Objective c CCtouchesBegind-CCTouchesEnded需要两个坐标
首先,我对Cocos2D和Obj-C还不熟悉,所以我确实遇到了类似这样的简单问题。 我的问题是这样的: 屏幕上有一个精灵,用户必须触摸它的顶部,在按下的同时向上移动一点,然后释放触摸。 想象一个戴着帽子的玩家精灵,你必须触摸帽子并将手指向上移动一点,使他的帽子朝那个方向飞。 实现这一点的最佳方式是什么 到目前为止,我得到的是:Objective c CCtouchesBegind-CCTouchesEnded需要两个坐标,objective-c,cocos2d-iphone,uitouch,uievent,Objective C,Cocos2d Iphone,Uitouch,Uievent,首先,我对Cocos2D和Obj-C还不熟悉,所以我确实遇到了类似这样的简单问题。 我的问题是这样的: 屏幕上有一个精灵,用户必须触摸它的顶部,在按下的同时向上移动一点,然后释放触摸。 想象一个戴着帽子的玩家精灵,你必须触摸帽子并将手指向上移动一点,使他的帽子朝那个方向飞。 实现这一点的最佳方式是什么 到目前为止,我得到的是: - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *to
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
//other stuff
}
我是否需要创建另一种方法来确定CCtouchesBegind位置,然后将该值提供给CCTouchesEnded方法,然后计算角度并使帽子飞走?
或者我可以确定在上述方法中触摸开始的位置吗
非常感谢您的回答:)您发布的方法仅适用于触摸结束时。这意味着它只会在用户将手指从屏幕上取下时触发。如果那是你想要的,那就好了。CGPoint变量“location”是您想要的点 一个点是两个浮点值。你将有:
location.x
location.y
这不会告诉你触摸是从哪里开始的。正如我所说,它只在用户将手指从屏幕上取下时触发。如果您需要知道用户触摸屏幕的位置,还有另一种方法。以下是标准触摸方法:
// Touch first detected
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
// Touches moved
-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
// User took finger off screen
- (void)ccTouchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
// Touch was somehow interrupted
- (void)ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
// Touch first detected
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
// Touches moved
-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
// User took finger off screen
- (void)ccTouchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
// Touch was somehow interrupted
- (void)ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event