Containers within containers
Before we move to the parallax effect logic, there is something I wanted to talk about related to the layering of our _gameBatchNode
object, which you'll recall is a SpriteBatchNode
object.
If you go to the static create
method inside Terrain.cpp
, you will notice that the object is still created with a reference to a blank.png
texture:
terrain->initWithSpriteFrameName("blank.png")
In fact, the same 1 x 1 pixel image used in the test version is now in our sprite sheet, only this time the image is transparent.
This is a bit of a hack, but necessary, because a sprite can only be placed inside a batch node if its texture source is the same used to create the batch node. But Terrain
is just a container, it has no texture. However, by setting its blank
texture to something contained in our sprite sheet, we can place _terrain
inside _gameBatchNode
.
The same thing is done with the Block
class, which now, in the final version of the game, behaves like another...