|Published (Last):||3 January 2004|
|PDF File Size:||20.7 Mb|
|ePub File Size:||6.98 Mb|
|Price:||Free* [*Free Regsitration Required]|
With Transferable Objects, data is transferred from one context to another. Assuming your main app is running from http: For example, in the next example the ‘msg’ property of the JSON message is accessible in both locations. However, when passing these types of data using postMessagea copy is still made. The Web Workers specification defines an API for spawning background scripts in your web application.
Below is a example of using a string to pass ‘Hello World’ to a worker in doWork. Welcome to our first tutorial on Making a Game with Phaser 3.
Although this particular example isn’t very exciting, it demonstrates that postMessage is also your means for passing data back to the main thread. You can explicitly release a Blob URLs by passing it to window. The config object is how you configure your Phaser Game.
This is great for further breaking up large tasks at runtime. Instead, they fail silently! There are two ways to stop a worker: Web Workers run in an isolated thread. But in this tutorial we’re just going to set the renderer, dimensions and a default Scene.
CodeBerry Blog|Stories about learning programming
Blob URLs are unique and last for the lifetime of your application e. While going through this process we’ll explain some of the core features of the framework. If an error occurs while a worker is executing, the an ErrorEvent is fired.
Game object is assigned to a local variable called game and the configuration object is passed to it. alapol
To combat the perf hit, you can use Transferable Objects. One reason for this javascrippt that messages passed between main pages and workers are copied, not shared. Messages passed between the main page and workers are copied, not shared. Script execution happens within a single thread.
Making your first Phaser 3 game
Workers utilize thread-like message passing to achieve parallelism. Keep in mind most browsers spawn separate processes for each worker. The magic comes with the call to window. For example, when transferring an ArrayBuffer from your main app to Worker, the original ArrayBuffer is cleared and no longer usable.
For an sample of how to spawn a subworker, see the example in the specification. The javasdript element that Phaser creates will be simply be appended to the document at the point the script was called, but you can also specify a parent container in the game config should you wish.
To run your app from the file: In the context of a worker, both self and this reference the global scope for the worker. The worker case, the first argument is the data javascrupt the second is the list of items that should be transferred.