Time for action – coding the Block object
Once again a static method, create
, will use blank.png
to create our Block
sprite. Only this time, we don't actually change the texture rectangle for Block
inside create
:
The
Block
object is properly textured inside thesetupBlock
method:void Block::setupBlock (int width, int height, int type) { _type = type; _width = width * _tileWidth; _height = height * _tileHeight; this->setAnchorPoint(Vec2(0,0)); this->setTextureRect(Rect(0, 0, _width, _height));
A
Block
object's appearance will be based on its type, width, and height.The
Block
sprite's registration point is set to top left. And we finally change theBlock
object's texture rectangle size here.Then we set the
Block
object's color based on type:switch (type) { case kBlockGap: this->setVisible(false); return; case kBlock1: this->setColor(Color3B(200,200,200));...