728x90
반응형
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using Spritesheets with Cocos2d-X | |
// http://paralaxer.com/animation-spritesheets/ | |
//------------------------------------------------------------------ | |
// So how does one use a spritesheet with Cocos2d-X? | |
// The first thing you've got to do is load the texture file | |
// and cache the sprite frames: | |
// set the appropriate resource directory for this device. HD/HDR/SD, etc... | |
CCFileUtils::sharedFileUtils()->setResourceDirectory( "HD" ); | |
// load and cache the texture and sprite frames | |
auto cacher = CCSpriteFrameCache::sharedSpriteFrameCache(); | |
cacher->addSpriteFramesWithFile( "Ninja.plist" ); | |
//------------------------------------------------------------------ | |
// Here's how to create a sprite using one of the sprite frames: | |
CCSprite* someSprite = new CCSprite; | |
someSprite->initWithSpriteFrameName( "ninja-stopped0000.png" ); | |
//------------------------------------------------------------------ | |
// To individually get one of the sprite frames: | |
// get the sprite frame | |
CCSpriteFrame* frame = cacher->spriteFrameByName( "ninja-sidekick-e0007.png" ); | |
// set someSprite's display frame | |
someSprite->setDisplayFrame( frame ); | |
//------------------------------------------------------------------ | |
//To play an animation: | |
// load all the animation frames into an array | |
const int kNumberOfFrames = 13; | |
CCArray* frames = new CCArray; | |
frames->initWithCapacity(kNumberOfFrames); | |
for( int i = 0; i < kNumberOfFrames; i++ ) | |
{ | |
CCString* filename = | |
CCString::createWithFormat("ninja-sidekick-e%04d.png", i); | |
frames->addObject(cacher->spriteFrameByName(filename->getCString())); | |
} | |
// play the animation | |
CCAnimation* anim = new CCAnimation; | |
anim->initWithSpriteFrames(frames); | |
someSprite->runAction(CCAnimate::create(anim)); |
728x90
반응형
'C C++' 카테고리의 다른 글
C/C++ 오류 발생 전처리기 #error (0) | 2013.03.06 |
---|---|
Creating and using Sprite Sheets in Cocos2D-X with Texture Packer (0) | 2012.12.07 |
간단한 C++ 오버라이딩(overriding) 예제 (0) | 2012.11.09 |
Qt Polymorphism (0) | 2012.03.06 |
CStdString : 윈도우즈 문자열 클래스 (0) | 2012.02.27 |