0
A
回答
1
這樣做:
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
if (touchState != kSceneStateUngrabbed) return NO;
// Store the starting touch point
CGPoint touchPoint = [touch locationInView:[touch view]];
startTouchPoint = touchPoint;
touchPoint = [[CCDirector sharedDirector] convertToGL:touchPoint];
// Change touch state
touchState = kSceneStateGrabbed;
return YES;
}
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint touchPoint = [touch locationInView:[touch view]];
float rightleft = touchPoint.x-startTouchPoint.x ;
float updown = touchPoint.y-startTouchPoint.y;
if(abs(rightleft)>abs(updown)){
if(rightleft>0)
{
[ spaceShip runAction:[CCMoveTo actionWithDuration:1 position:ccp(winsize.width, spaceShip.position.y)]];
}
else
[ spaceShip runAction:[CCMoveTo actionWithDuration:1 position:ccp(0, spaceShip.position.y)]];
}
else{
if(updown<0){
[ spaceShip runAction:[CCMoveTo actionWithDuration:1 position:ccp(spaceShip.position.x, winsize.height)]];
}
else
[ spaceShip runAction:[CCMoveTo actionWithDuration:1 position:ccp(spaceShip.position.x, 0)]];
}
}
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
// Change touch state
touchState = kSceneStateUngrabbed;
}
相關問題
- 1. 在角度方向上移動精靈
- 2. 移動精靈的方向
- 3. 滑動精靈
- 4. AndEngine精靈正在移動
- 5. 如何讓精靈坐在移動的精靈上
- 6. 在cocos2d的路徑上移動精靈
- 7. 如何使用Andengine向其上滑動的方向拋出一個精靈?
- 8. PYGAME讓精靈在朝着它的方向移動
- 9. CCActionMoveTo精靈在錯誤的方向移動
- 10. AS3如何使它正在移動的精靈臉部方向
- 11. 製作精靈在矢量的相反方向移動
- 12. 如何檢測精靈在哪個方向移動?
- 13. 2D精靈面對它在Pygame中移動的方向
- 14. 在XNA中向上彎曲的弧形移動2D精靈?
- 15. 定時移動精靈
- 16. 瞭解SpriteKit:移動精靈
- 17. Swift如何移動精靈?
- 18. 沿路徑移動精靈
- 19. Xna碰撞移動精靈
- 20. 移動精靈直線
- 21. 使精靈不可移動
- 22. 自動移動一個精靈來捕捉另一個精靈
- 23. 向點動畫精靈
- 24. 移相器 - 用另一個精靈移動精靈
- 25. 如何使用鼠標在as3上創建精靈的向上/向下移動
- 26. 如何在cocos2d中平滑移動精靈
- 27. 獲取精靈套件對象向上移動
- 28. 無法移動的精靈動畫
- 29. 動畫一個移動的精靈
- 30. 圖片精靈動畫鼠標移動
什麼是touchState,kSceneStateUngrabbed?假設startTouchPoint是CGPoint。 – Doug