2010-07-12 24 views
0

所以這裏就是我想要做的:(工作正常)可能從CCSpriteFrameCache(Cocos2d)獲取CCTexture?

創建從我讀入CCSpriteFrameCache地圖集精靈

添加動畫精靈 - 我也能得到這個工作正常,但...

動畫是通過加載一些CCSpriteFrames創建的,這些CCSpriteFrames依次從共享CCTextureCache中讀取CCTextures作爲其資產。它有效,但我不相信這是最好的方式。好像我應該用CCSpriteFrameCache中已經加載的atlassprite的元素加載那些CCSpriteFrames。

問題是:有沒有一種方法或方法加載CCSpriteFrames與CCSprites在CCSpriteFrameCache框架中命名?

開放的想法,我正在討論這個錯誤。感謝您的任何提示。

代碼在這裏:

CCAnimation *thingAnimation = [CCAnimation animationWithName:@"wiggle" delay:0.1f]; 

//this works but I want to get the CCTexture from CCSpriteFrameCache.... 
aTexture = [[CCTextureCache sharedTextureCache] addImage:@"moon.png"]; 

//because CCSpriteFrame will only accept a CCTexture 
frame1 = [CCSpriteFrame frameWithTexture:aTexture rect:CGRectMake(0, 0, aTexture.pixelsWide, aTexture.pixelsHigh) offset:ccp(0,-40)]; 
[thingAnimation addFrame:frame1]; 

回答

0

我想,如果你知道這已經,你認爲這是一個非常愚蠢的問題。我找到了答案在這裏: http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:animation

基本上從地圖集和plist中做動畫,你需要能夠與CCSpriteSheet,CCSprite,CCSpriteFrame,CCSpriteFrameCache和CCAnimation工作。

您首先創建CCSpriteSheet。然後你從plist創建CCSpriteFrameCache。然後你可以隨意創建CCSprites和CCSpriteFrames; CCSpriteFrames饋入CCAnimation。無論如何,這就是我的要求。讓我知道更好的方法。