Game Development Reference
In-Depth Information
Sprite::createWithSpriteFrameName("city_light.png");
sprite->setAnchorPoint(Vec2(0.5,0));
sprite->setPosition(Vec2(_screenSize.width * (0.25f
+ i * 0.5f),
_screenSize.height * 0.1f));
_gameBatchNode->addChild(sprite, kBackground);
}
2. Then the trees:
//add trees
for (int i = 0; i < 3; i++) {
auto sprite =
Sprite::createWithSpriteFrameName("trees.png");
sprite->setAnchorPoint(Vec2(0.5f, 0.0f));
sprite->setPosition(Vec2(_screenSize.width * (0.2f
+ i * 0.3f),0));
_gameBatchNode->addChild(sprite, kForeground);
}
Notice that here we create sprites by passing it a sprite frame name. The IDs for
these frame names were loaded into SpriteFrameCache through our
sprite_sheet.plist file.
3. The screen so far is made up of two instances of city_dark.png tiling at the
bottom of the screen, and two instances of city_light.png also tiling. One
needs to appear on top of the other and for that we use the enumerated values de-
clared in GameLayer.h :
enum {
kBackground,
kMiddleground,
kForeground
};
4. We use the addChild( Node, zOrder) method to layer our sprites on top
of each other, using different values for their z order.
Search WWH ::




Custom Search