问题描述
- 子视图从(x,y)到(-x,y)
-
开发的游戏中,需要子视图从位置(x, y)沿着抛物线滑到位置(width-x, y),应该怎么实现?下面是代码的摘录:
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event { CGSize screenSize = [[CCDirector sharedDirector] winSize]; if(!self.anim.flipY){ self.anim.position = ccp(screenSize.width - self.anim.position.x, self.anim.position.y); self.anim.flipY = true; } else{ self.anim.position = ccp(screenSize.width - self.anim.position.x, self.anim.position.y); self.anim.flipY = false; } }
解决方案
不确定这样是不是你需要的,不过这样可以实现跳转:
// Create a CCJumpTo action.
CCJumpTo *jumpAction = [CCJumpTo actionWithDuration:2.0 position:ccp(100,100) height:50 jumps:1];
// Tell your sprite to run our action.
[mySprite runAction:jumpAction];
还可以用CCJumpBy。
这些都是以抛物线轨迹执行的,再设置一下height参数。
时间: 2025-01-20 10:05:59