在 cocos2d 上为 CCSprite 制作动画?
大家好,我是 cocos2d 和 iPhone 开发的新手,我目前正在尝试创建一个像“PapiJump”这样的游戏, 我目前遇到的问题是在我的游戏中为角色 CCSprite 制作动画, 我创建了我的角色的 3 个图像,角色指向右、左和中(http://i53.tinypic.com/ngzoyh.png),
因此当角色改变方向(左或右)时,它不会直接“跳跃”到另一个方向,但会动画。
在我的代码中,我使用 TouchesEnded 方法,在此方法中,我设置一个名为“touchState”的变量, 因此,如果用户触摸屏幕的右侧,它会将“touchState”设置为 1,否则将其设置为 2(表示左侧)。
然后在“init”方法中,我创建了一个“时间表”,每 0.5 秒运行另一个方法,名为:“updateGame”, “updateGame”方法更新玩家的位置,其工作原理如下: 玩家位置 = ccp(玩家位置.x, 玩家位置.y - 玩家重力.y);
我已阅读 Ray 的教程关于动画CCSprites,但我不知道如何实现我需要的结果.. 预先感谢并抱歉我的英语不好!
Hey guys, I'm new to cocos2d and iPhone development, im currently trying to create a game like "PapiJump",
What I'm currently having problems with, is animating the character CCSprite in my game,
I have created 3 images of my character, character pointing right, left and middle (http://i53.tinypic.com/ngzoyh.png)
so when the character changes its direction (left or right), it wont "jump" directly to the other direction but will animate..
In my code im using the TouchesEnded method, in this method im setting a variable named "touchState",
so if the user touched the right side of the screen it will set "touchState" to 1, otherwise it sets it to 2 (means left).
then in the "init" method i created a "schedule" that runs another method every 0.5 sec that is named: "updateGame",
the "updateGame" method updates the player's position, it works like that:
player.position = ccp(player.position.x , player.position.y - playerGravity.y);
I've read Ray's tutorial on animating CCSprites but i have no idea how to achieve the result that i need..
Thanks in advance and sorry for my bad english!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑:看起来你正在谈论只是翻转图像。 重新获取精灵
您可以使用(或缓存它们并切换)
Edit: Looks like you're talking about just flipping the image around. You can just refetch a sprite with
(Or cache them and switch)
你能澄清你的问题吗?如果你想设置不同的精灵框架,你可以使用
setDisplayFrame
:或者如果你有动画:
但我觉得这个问题有点模糊。
Can you clarify your question? If you want to set a different sprite frame, you can use
setDisplayFrame
:or if you have an animation:
But I feel like the question is a little vague.
如果我正确地回答了您的问题,我可以建议两种方法来解决您的问题:
首先你可以旋转你的对象直到它颠倒,然后使用 FlipX(或 FlipY)标志标记为 true 继续之前的动画,或者你可以添加一个动画,仅对角色旋转进行动画处理,当它完成时更改 FLipX(或FlipY)状态。
if i got your question properly i can suggest two ways to solve your problem:
first you could rotate your object to till it is upside down, and the continue your previous animations using FlipX(or FlipY) flag marks as true or you can add an animation wich animates only characters rotation and when ever it's finnished change the FLipX(or FlipY) status.