Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocos2d android CCTouchesBegind在cocos2d android中不起作用_Cocos2d Android - Fatal编程技术网

Cocos2d android CCTouchesBegind在cocos2d android中不起作用

Cocos2d android CCTouchesBegind在cocos2d android中不起作用,cocos2d-android,Cocos2d Android,I已启用setIsTouchEnabled(真)但我无法在cocos2d android中检测到触摸开始和触摸结束 我的游戏玩家是 public class GameLayer extends CCColorLayer { protected CCLabel _label; public static CCScene scene() { CCScene scene = CCScene.node(); GameLayer layer = new GameLa

I已启用
setIsTouchEnabled(真)但我无法在cocos2d android中检测到触摸开始和触摸结束

我的游戏玩家是

 public class GameLayer extends CCColorLayer
 {
   protected CCLabel _label;

   public static CCScene scene()
   {
    CCScene scene = CCScene.node();
    GameLayer layer = new GameLayer(ccColor4B.ccc4(90, 90, 255, 255));
    layer.getLabel();

    scene.addChild(layer);
    return scene;

}

public CCLabel getLabel()
{
    return _label;

}

protected GameLayer(ccColor4B color)
{
    super(color);
    this.setIsTouchEnabled(true);
    CGSize winSize = CCDirector.sharedDirector().displaySize();
    Context context = CCDirector.sharedDirector().getActivity();
    _label = CCLabel.makeLabel("Tap On Me to START the game", "DroidSans", 32);
    _label.setColor(ccColor3B.ccBLACK);
    _label.setPosition(winSize.width/2, winSize.height/2);

    addChild(_label);

}

@Override
public boolean ccTouchesBegan(MotionEvent event)
{

    CGRect projectileRect = CGRect.make(_label.getPosition().x,_label.getPosition().y, _label.getContentSize().width,_label.getContentSize().height);
    CGPoint touchLocation = CGPoint.ccp(event.getX(), event.getY());
    CGRect targetRect = CGRect.make(event.getX(), event.getY(), 20, 20);
    System.out.print(":touch Points are - :"+projectileRect+" _  -  _ "+touchLocation+" _  -  _ "+targetRect);
    if (CGRect.intersects(projectileRect, targetRect))
    {
        System.err.print(": This is intersect function from App :");
    }
    return true;

}

@Override
public boolean ccTouchesEnded(MotionEvent event)
{
    // Choose one of the touches to work with
    CGPoint location = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(50, 200));
    System.out.printf("Got touch ", location);
    CGSize winSize = CCDirector.sharedDirector().displaySize();

    return true;

}
 }

有人能告诉我哪里出了问题吗?我没有收到任何错误,也没有在logcat中跟踪日志。您的代码很好,只需使用
System.out.println()
函数将文本输出到控制台,而不是
System.out.printf(),System.err.print()
。当我替换它们时,文本已经出现在控制台中

这:

System.out.print(":touch Points are - :"+projectileRect+" _  -  _ "+touchLocation+" _  -  _ "+targetRect);

改为:

System.out.println(":touch Points are - :"+projectileRect+" _  -  _ "+touchLocation+" _  -  _ "+targetRect);
System.out.println(": This is intersect function from App :");
System.out.println("Got touch " + location);
这是:

System.err.print(": This is intersect function from App :"); 
改为:

System.out.println(":touch Points are - :"+projectileRect+" _  -  _ "+touchLocation+" _  -  _ "+targetRect);
System.out.println(": This is intersect function from App :");
System.out.println("Got touch " + location);
这也是:

System.out.printf("Got touch ", location);
改为:

System.out.println(":touch Points are - :"+projectileRect+" _  -  _ "+touchLocation+" _  -  _ "+targetRect);
System.out.println(": This is intersect function from App :");
System.out.println("Got touch " + location);

您需要在构造函数中添加以下内容:

this.setIsTouchEnabled(true);
Log.e(“AM”和“+touchLocation”);将此代码放在CGPoint之后,检查您是否获得触摸的值?