Hi all,
I encountered strange problem on iOS devices.
I made up a single spritesheet file for sprite animation. There are sprite frame images in this spritesheet like this sequence.
ani_house_bread_lv1_xx.png
When I run the animation from this spritesheet, the building seems shaking left<>right, which is completely fine on iOS simulator and Android devices.>animationByName( animation_name );
The codes I tested for this sprite animation is like following 2.
Code 1
<pre>
void createAnimationFromPlistToSprite
{
CCAnimationCache* animCache = CCAnimationCache::sharedAnimationCache;
CCAnimation* animation = animCache
if( animation==NULL )
{
CCSpriteFrameCache* frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
frameCache~~>addSpriteFramesWithFile;
animation = CCAnimation::create;
CCFileUtils* fileUtils = CCFileUtils::sharedFileUtils;
const char* fullPath = fileUtils~~>fullPathForFilename( animation_plist_path ).c_str();
CCDictionary* dictionary = CCDictionary::createWithContentsOfFileThreadSafe( fullPath );
CCDictionary* framesDict = static_cast<CCDictionary*>( dictionary~~>objectForKey );
CCArray* keys = framesDict~~>allKeys();
for( int i = 0 ; i < keys~~>count; ++i )
{
CCString* spriteFileName = static_cast<CCString*> );
CCSpriteFrame* sprite = CCSpriteFrameCache::sharedSpriteFrameCache~~>spriteFrameByName );
animation~~>addSpriteFrame;
}
animation~~>setDelayPerUnit( delayPerUnit );
animation~~>setRestoreOriginalFrame;
animCache~~>addAnimation( animation, animation_name );
}
else
{
CCLog( “## Animation(%s) is already in Cache”, animation_name );
}
if( animation )
{
if( pSprite!=NULL )
{
CCArray* aniframes = animation~~>getFrames;
if>0 )
{
CCAnimationFrame* aniframe = static_cast<CCAnimationFrame*> );
pSprite~~>initWithSpriteFrame( aniframe~~>getSpriteFrame );
}
}
}
}
void startAnimationInSprite
{
CCAnimationCache* animCache = CCAnimationCache::sharedAnimationCache;
CCAnimation* animation = animCache~~>animationByName( animation_name );
if( animation )
{
CCAction* action = NULL;
if(loop)
{
animation~~>setLoops;
//action = CCRepeatForever::create);
action = CCAnimate::create;
}
else
{
animation~~>setLoops(1);
action = CCAnimate::create( animation );
}
// CCMoveBy* moveby = CCMoveBy::create(0, ccp(0,120));
// pSprite~~>runAction;
// CCSequence* seq = CCSequence::create;
pSprite~~>runAction( action );
}
}
void startAnimationInSprite(const char* plistfile,
const char* animation_name,
CCSprite* pSprite,
bool loop)
{
CCAnimationCache* animCache = CCAnimationCache::sharedAnimationCache();
CCAnimation* animation = animCache->animationByName( animation_name );
if( !animation )
{
createAnimationFromPlistToSprite( plistfile, animation_name );
}
startAnimationInSprite(animation_name, pSprite, loop);
}
And I tried AdvanceSprite class from
http://www.cocos2d-x.org/forums/6/topics/1792
[[http://www.cocos2d-x.org/forums/6/topics/1792]]
Have anyone encountered this before?
cocos2d-x library I am using is “cocos2d-x-2.2.0”
Thanks in advance.
house_bread.plist.zip (1.1 KB)
house_bread.png (2384.6 KB)