简体   繁体   中英

Android programming (cocos2d), whites rectangle instead image

I am trying to make animation in cocos2d, but instead of images it print only whites rectangles. All images becomes whites rectangles right after addChild(player); in code.

When I give it to comments other images are shown good. Animation seems to be good, because I see the white rectangle of animated images is little changing. All images are in assets.

There is a code:

   CGSize winSize = CCDirector.sharedDirector().displaySize();
   CCSprite p = CCSprite.sprite("Player.png");
   p.setPosition(CGPoint.ccp(p.getContentSize().width / 2.0f, winSize.height / 2.0f));
   addChild(p, 1);

   CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFrames("player.plist");
   CCSprite player = CCSprite.sprite(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("Player.png"));
   player.setPosition(CGPoint.make(60, winSize.height / 3));
   addChild(player);
   CCAnimation anim = CCAnimation.animation("", 0.3f);
   for (int i = 2; i <9; i++) {
   anim.addFrame(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("PlayerWalk_0" + i + ".png"));
   }

   CCAction animaction = CCAnimate.action(2, anim, true);
   player.runAction(animaction);

Thanks for replies.

EDIT:

I changed addChild(player); to addChild(player, 2); and first image is now shown correctly but animated image and fps are still white rectangles.

Texture and plist had diffrent names. I renamed them, so they was the same, just one ending with .plist and other with .png. Now it works. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM