|Country:||Republic of Macedonia|
|Published (Last):||24 October 2010|
|PDF File Size:||20.76 Mb|
|ePub File Size:||7.45 Mb|
|Price:||Free* [*Free Regsitration Required]|
Instead, they fail silently! But before we do that, the first thing to do is create a new Worker object in your main page. This is your list of transferrable items. The only browser requirement is the support of the canvas tag. While going through this process we’ll explain some of the core features of the framework. To run your app from the file: This article will only cover dedicated workers and I’ll refer to them as ‘web workers’ or ‘workers’ throughout.
What if you want to create your worker script on the fly, or create a self-contained page without having to create separate worker files?
Table of Contents
The constructor takes the name of the worker script:. Download the resources for this tutorial and unzip them into your web root.
The first argument doesn’t have to be an ArrayBuffer by the way. This will insure the external script is imported from the same origin. The width and height properties set the size of the canvas element that Phaser will create.
Web Workers run in an isolated thread. For an sample of how to spawn a subworker, see the example in the specification.
This is great for further breaking up large tasks at runtime. However, subworkers come with a few caveats:. Below is a example of using a string to pass ‘Hello World’ to a worker in doWork.
Making your first Phaser 3 game
Download this zip file which contains each step of this tutorial in code and the assets that go with it. Hence, the failure will be due to cross origin restrictions. However, when passing these types of data using postMessagea copy is still made. For example, when transferring an ArrayBuffer from your main app to Worker, the original ArrayBuffer is cleared and no longer usable. They’re going to help put and end to that nasty ‘unresponsive script’ dialog that we’ve all come to love:.
There are two ways to stop a worker: With Transferable Objects, data is transferred from one context to another. Web Workers allow you to do things like fire up long-running scripts to handle computationally intensive tasks, but without blocking the UI or other scripts to handle user interactions. Therefore, if you’re passing a large 50MB file for examplethere’s a noticeable overhead in getting that file between the worker and the main thread.
If an error occurs while a worker is executing, the an ErrorEvent is fired.
There are lots of options that can be placed in this object and as you expand on your Phaser knowledge you’ll encounter more of them. July 26th, Comments: However, unlike pass-by-reference, the ‘version’ from the calling context is no longer available once transferred to the new context.