我想从画廊中选择播放器图像,或者我可以从凸轮拍摄照片,并且需要在播放器移动时为这些图像制作动画。我对cocos2d很陌生,身体能帮助我吗?我们可以在cocos2d游戏中动态更改玩家图片吗?
0
A
回答
0
要更改播放器动画,您需要对其执行CCAnimate
操作。
// Add sprite frames to sprite frame cache (if you are using a spritesheet)
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"NinjaPreto.plist"];
// Create animation
CCAnimation* animation = [CCAnimation animation];
// Create sprite frames
CCSpriteFrame *spriteFrame1 = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"animation1.png"];
CCSpriteFrame *spriteFrame2 = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"animation2.png"];
CCSpriteFrame *spriteFrame3 = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"animation3.png"];
// Add sprite frames to animation
[animation addSpriteFrame:spriteFrame1];
[animation addSpriteFrame:spriteFrame2];
[animation addSpriteFrame:spriteFrame3];
animation.delayPerUnit = 0.1;
animation.restoreOriginalFrame = NO;
// Run action
[player runAction:[CCRepeatForever actionWithAction:animation]];
所以,如果你想改变播放器的形象,只是创建所需的新图像的新动画动作。
PS:如果你只是想改变玩家图像,而无需动画,使用:
[player setTexture:[[CCTextureCache sharedTextureCache] addImage:@"image.png"]];
0
在cocos2d-X,您可以通过以下方式
CCTexture2D *tex = CCTextureCache::sharedTextureCache()->addImage("xyz.png");
sprit_name->setTexture(tex);
做到这一点,如果你想CHANGE THE SPRITE SIZE然后还要在此线
sprit_name->setTextureRect(CCRectMake(0,0, tex->getContentSize().width, tex->getContentSize().height));
相关问题
- 1. 我们可以动态更改Google文档中的图片吗?
- 2. 游戏中的玩家停止游戏
- 3. 我可以在GameCenter游戏中拥有超过4名玩家吗?
- 4. 我可以在我的Cocos2D-iPhone游戏中支持VoiceOver吗?
- 5. iPhone Cocos2d游戏更改为iPad游戏
- 6. 多人游戏玩家2人游戏
- 7. iPhone - 可以Cocos2d创建非游戏吗?
- 8. 我们可以在游戏中使用cocos2D演示应用程序吗?
- 9. iOS游戏玩家ID
- 10. CPU玩家骰子游戏
- 11. 玩家死亡/ c游戏#
- 12. 3玩家卡牌游戏
- 13. 在Java游戏中切换玩家
- 14. 在游戏中设置两个玩家
- 15. 玩家移动时Java游戏变慢
- 16. 游戏敌人向玩家移动
- 17. Twitch API让玩家玩X游戏
- 18. iOS游戏中心可以在游戏中的玩家之间传递字符串/对象吗?
- 19. 游戏中心让玩家为了他们加入到游戏中
- 20. 玩家游戏对象在游戏中消失
- 21. 在cocos2d中同时在多个图层中玩游戏
- 22. OO Javascript游戏,如何添加玩家游戏的玩家数组?
- 23. Python将玩家添加到游戏中
- 24. 跟踪游戏中的玩家(Java)
- 25. Tic-Tac-Toe游戏不会切换玩家,更新分数或更换玩家
- 26. 我们可以在css3动画中移动背景图片吗?
- 27. 有多少玩家使用游戏中心或等待游戏
- 28. 如何实现实时多玩家谷歌玩游戏服务C++到cocos2d-x
- 29. 在Android游戏中更新玩家得分
- 30. 游戏中心无法加载照片几个玩家ID
[playerSprite的SetTexture:[[CCTextureCache sharedTextureCache] addImage:@“playerWithS hield.png“]]; – Anjaneyulu
我需要动态地拍照,并且应该应用于玩家图片 – Raj
[playerSprite setTexture:[[CCTextureCache sharedTextureCache] addImage:[UIImage imageNamed:[NSString stringwithformat @“%@”,yourimage]]]]; – Anjaneyulu