본문 바로가기

Cocos2d-x v3.17/기본기능

[Cocos2d-x 기본기능]SpriteCache사용하기

반응형

SpriteCache사용하기 

 

SpriteCache는 Cocos2d-x가 Sprite액세스 속도를 높이기 위해 제공하는 Sprite의 캐싱 메카니즘입니다.

우리는 Sprite 하나를 생성하여 SpriteFrameCache에 넣을수 있습니다. 

C++ 

// Our .plist file has names for each of the sprites in it. We'll grab

// the sprite named, "mysprite" from the sprite sheet:

auto mysprite = Sprite::createWithSpriteFrameName("mysprite.png");

반대로 SpriteFrameCache에서 Sprite를 가져오는 방법도 있습니다.

먼저 cache에서 SpriteFrame을 얻어오고 그다음에 SpriteFrame을 생성하는것입니다. 

C++ 

// this is equivalent to the previous example,

// but it is created by retrieving the SpriteFrame from the cache.

auto newspriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("Blue_Front1.png");

auto newSprite = Sprite::createWithSpriteFrame(newspriteFrame);

 

   

출처: <http://cocos2d-x.org/docs/cocos2d-x/zh/sprites/spriteframe_cache.html


반응형