Game Development Reference
In-Depth Information
tile =
Sprite::createWithSpriteFrameName("building_1.png");
tile->setAnchorPoint(Vec2(0, 1));
tile->setPosition(Vec2(i * _tileWidth, -1 *
(_tileHeight * 0.47f + j * _tileHeight)));
tile->setVisible(false);
this->addChild(tile, kBackground, kWallTile);
_wallTiles.pushBack(tile);
}
}
A block comprises 20 sprites stored inside a _wallTiles vector and five
sprites stored in a _roofTiles vector. So, when we initialize a Block object,
we in effect create a building that is five tiles wide and four tiles tall. I made the
decision that no building in the game would exceed this size. If you decide to
change this, then here is where you would need to do it.
4. The initBlock method also creates five chimney sprites and places them at the
top of the building. These will be spread out later according to the building type
and could be very easily turned into obstacles for our _player sprite. We also
create the animation actions for the puffs of smoke, here inside initBlock .
5. Moving on to our new setupBlock method, this is where the unnecessary tiles
and chimneys are turned invisible and where we spread out the visible chimneys.
We begin the method as follows:
void Block::setupBlock (int width, int height, int
type) {
this->setPuffing(false);
_type = type;
_width = width * _tileWidth;
//add the roof height to the final height of the
block
_height = height * _tileHeight + _tileHeight *
0.49f;
this->setPositionY(_height);
SpriteFrame * wallFrame;
Search WWH ::




Custom Search