Skip to content

Instantly share code, notes, and snippets.

@SONIC3D
Created January 22, 2014 07:39
Show Gist options
  • Save SONIC3D/8554863 to your computer and use it in GitHub Desktop.
Save SONIC3D/8554863 to your computer and use it in GitHub Desktop.
SpriteSheet和SpriteBatchNode
void GameLayer::useSpriteSheet()
{
// 建立SpriteBatchNode
// 方法1:
CCSpriteFrameCache::sharedSpriteFrameCache()->
addSpriteFramesWithFile("sprite_sheet.plist");
_gameBatchNode = CCSpriteBatchNode::create("sprite_sheet.png");
this->addChild(_gameBatchNode);
// 方法2:
CCSpriteFrameCache::sharedSpriteFrameCache()->
addSpriteFramesWithFile("sprite_sheet.plist","sprite_sheet.png");
CCTexture2D *fullTexture=CCTextureCache::sharedTextureCache()->
textureForKey("sprite_sheet.png");
_gameBatchNode = CCSpriteBatchNode::createWithTexture(fullTexture);
this->addChild(_gameBatchNode);
// -----------------------------------------------------------------------------
// 加载在sprite_sheet.plist中描述的sprite
CCSprite * sprite;
sprite = CCSprite::createWithSpriteFrameName("city_dark.png");
sprite->setPosition(ccp(0, 0));
_gameBatchNode->addChild(sprite);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment