I have just started using the Cocos2D library for Android. I am trying to make a walking bear animation.
For that I am using a CCSpriteFrameCache, but I'm getting a "frame not found" error in the log.
I have added an AnimBear.plist file and an AnimBear.png file (combined image of the various movements of the bear) to the assets folder.
My Java code is as per below :
CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFrames("AnimBear.plist");
CCSpriteSheet spriteSheet = CCSpriteSheet.spriteSheet("AnimBear.png");
scene.addChild(spriteSheet);
ArrayList<CCSpriteFrame> walkSprites = new ArrayList<CCSpriteFrame>();
for (int i = 1; i <= 8; ++i)
{
walkSprites.add(CCSpriteFrameCache.sharedSpriteFrameCache().getSpriteFrame("bear" + i + ".png"));
System.out.println("bear image is added");
}
CCAnimation walkAnimation = CCAnimation.animation("bear", 0.1f, walkSprites);
bear = CCSprite.sprite(walkSprites.get(0));
this.walkAction = CCRepeatForever.action(CCAnimate.action(walkAnimation, false));
bear.runAction(walkAction);
Now here are the errors I get:
- walkSprites.get(0) line throws a Null Pointer Exception.
- CCSpriteFrameCache.sharedSpriteFrameCache().getSpriteFrame("bear" + i + ".png") line prints "CCSpriteFrameCache: Frame '%s' not found" in the logcat
Can anybody help me please, what am I doing wrong?
Thanks in advance.