LoginSignup
21
21

More than 5 years have passed since last update.

【Cocos2d-x 3.x】複数の画像を1枚のSpriteに合成する

Last updated at Posted at 2014-11-27

cocos2d-x 3.x系で、複数の画像をまとめる記事がなかったので書きました。
2.xだと、Spriteのcreateは最初に1つすればよかったんですが
3.xだと、1番最後にしたvisitしか表示されなかったので、for文の中でSpriteの生成を行いました。

たくさんの画像を1つのSpriteとしてて合成して表示すると、描画処理の軽減しパフォーマンスの向上が期待できます。

Size visibleSize = Director::getInstance()->getVisibleSize();

RenderTexture* tex = RenderTexture::create(visibleSize.width, visibleSize.height);
this->addChild(tex);
//texture焼き込み開始
tex->begin();

//たくさんSpriteを作る
for(int i = 0; i < 1000; i++) {
    Sprite* sprite = Sprite::create("image.png");
    //addChildしないnodeはretainすること
    sprite->retain();
    //visit前に、画面上の位置や大きさなど指定
    sprite->setPositionX(i);
    //visitすると、textureにSpriteが焼き込まれる
    sprite->visit();
}
//texture焼き込み完了
tex->end();
21
21
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
21