简体   繁体   English

Android编程(cocos2d),用白色矩形代替图像

[英]Android programming (cocos2d), whites rectangle instead image

I am trying to make animation in cocos2d, but instead of images it print only whites rectangles. 我正在尝试在cocos2d中制作动画,但是它只打印白色矩形而不是图像。 All images becomes whites rectangles right after addChild(player); addChild(player);之后,所有图像都变成白色矩形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); 我改变了addChild(player); to addChild(player, 2); addChild(player, 2); and first image is now shown correctly but animated image and fps are still white rectangles. 现在可以正确显示第一个图像,但是动画图像和fps仍然是白色矩形。

Texture and plist had diffrent names. Texture和plist具有不同的名称。 I renamed them, so they was the same, just one ending with .plist and other with .png. 我重命名了它们,所以它们是相同的,只是一个以.plist结尾,另一个以.png结尾。 Now it works. 现在可以了。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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