The autocull component in phaser ce
The auto cull component in Phaser ce is a fairly simple component that just adds two boolean values. One of which can be used to enable auto culling of sprites in a project keeping sprites that are outside of the camera from rendering, and the other is just an inCamera boolean that can be used to find out if a sprite is outside of the camera or not. In this post I will be outlining a simple example that makes use of what is added to sprites in phaser ce thanks to the auto cull component.
1 - What to know
This is a post where I am writing about just the auto cull component of phaser ce,the javaScript powered game framework. As such this post just covers a very narrow topic of interest whet it comes to making games with phaser ce as a framework. If you are new to phaser you might want to start with my getting started post on phaser ce. The auto cull component is one of many components that add features to display objects in phaser such as sprites, text, and graphics. I have found that studying each of these components one at a time is helping me understand everything that there is to work with out of the box with phaser, ultimately helping me save time by writing less code. Culling is similar to clipping) when it comes to 3d games, only the whole object is not rendered because it is out of view of the camera.
1.1 - This is a phaser ce 2.x post
In this post I was using phaser community edition 2.11.1 of phaser
2 - Example of the sprite.inCamera property
For an example of the inCamera property I made a demo that involves two sprites one represents a ship, and the other represents a pointer sprite that points to the location of the ship when it it outside the view of the camera.
2.1 - The update pointer method
So then here is a helpe that will be used to set the properties of the pointer, and ship sprites depending on the inCamera value of the ship sprite.
|
|
2.2 - Make a sprite sheet
This helper just makes a sprite sheet for the ship, and the pointer sprites using canvas.
|
|
2.3 - The Phaser.Game instance and state object
So now that I have my helpers I now just need to get everything working with a Phaser.Game instance and a state object.
|
|