Game Development Reference
In-Depth Information
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 :
1. The Block object is properly textured inside the setupBlock 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 the
Block object's texture rectangle size here.
2. 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));
break;
case kBlock2:
this->setColor(Color3B(150,150,150));
break;
Search WWH ::




Custom Search