【问题标题】:Cocos2d, how to do a certain touch methodCocos2d,如何做某一种触摸方法
【发布时间】:2012-10-30 11:36:37
【问题描述】:

我有一个我想触摸的精灵,一旦我不再触摸它,我想调用一个方法 nslog“不触摸”。现在我设置代码的方式只在我点击其他东西时调用方法 nslog“不触摸”。我想在触摸对象时调用方法 nslog“触摸”,但只要我触摸其他东西或抬起我的手指,它会调用 nslog“不接触”。有什么建议么? 感谢您的宝贵时间。

-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
UITouch* touch = [touches anyObject];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
 int arraysize = [brain count];
for (int i = 0; i < arraysize; i++) {
if (CGRectContainsPoint( [[brain objectAtIndex:0]  boundingBox], location)) {
        NSLog(@"touched");
        }else {

NSLog(@"not touched");
   }}}

【问题讨论】:

    标签: iphone objective-c ios xcode cocos2d-iphone


    【解决方案1】:

    我建议您将触摸处理程序注册为目标触摸委托。它会让你吞下这种触摸。

    您应该处理所有委托方法。我的意思是,touchBegan:withEvent:touchMoved:withEvent:touchEnded:withEVent:。因此,如果它的位置在精灵的矩形内,则只需在开始时存储触摸。然后就在touchMoved:withEvent:touchEnded:withEvent: 处理存储的触摸位置以确定触摸是否离开了精灵的矩形。

    【讨论】:

      【解决方案2】:

      您可能想要定义ccTouchesEnded

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-27
        • 1970-01-01
        相关资源
        最近更新 更多