Monday, August 4, 2014

Cocos2D-X Creating Solid Color Rectangular Sprite

There are times where instead of overriding the "draw" method, you need to create a sprite that is a solid rectangle. There are a few ways to do it, but the easiest for me is to create a 1x1px PNG file. The color can be changed during runtime as needed.

Reference: http://stackoverflow.com/questions/3339955/cocos2d-solid-color-rectangular-sprite

1 comment:

  1. create a blank Sprite, then set TextureRect and Color.
    (no need any png file).

    auto *sprite = Sprite::create();
    sprite->setTextureRect(Rect(0, 0, width, height));
    sprite->setColor(color);

    ReplyDelete