在android中点击ccsprite的事件

时间:2013-02-11 12:52:34

标签: android cocos2d-android

我是cocos2d的新手。

我正在开发一款游戏。

我想在图层的spites上做一些点击事件。

当我们点击图层的某个精灵时,我不知道调用哪个方法。

我在ccTouchesBegan(MotionEvent event)中获取控件但我无法找到点击的精灵。

以下是代码:

CCSprite bridge = RetrivingImagesFromSDcard.getImage(Constants.scrooll_Sprites[tileDetailsList
                                                                                                           .get(tileID).tileSpriteID3]);
                            addChild(
                                    bridge,
                                    tileDetailsList.get(tileID).tileSpriteID3Zorder,tileDetailsList.get(tileID).tileSpriteID3Tag);
                            bridge.setPosition(tilesBG.getPosition().x,tilesBG.getPosition().y);
                            bridge.setRotation(tileDetailsList.get(tileID).tileAngle);
                            bridge_Sprite_ArrayList.add(bridge);

这是触摸事件

@Override
    public boolean ccTouchesBegan(MotionEvent event) {
        if (flagTap == false)
        {
            tapCount = tapCount+1;
            tapCountStr = Integer.toString(tapCount);
            Log.e("TapCount", "@@@@@@@@@@@@@@@@@"+tapCountStr);

            map.put(GameLayer.timVal,tapCountStr);
            System.out.println(map);
            //CHANGES DONE 8 FEB

            try
            { 

                GameLog gameLogObj = new GameLog();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
                String currentDateandTime = sdf.format(new Date());
                GameLayer.logLevelArgument = "INFO";
                GameLayer.logMsgArgument = "TAPBEFORELAUNCH";
                GameLayer.roundStr = Integer.toString(Constants.level);
                TrainMapLayer.flagLogType = true;  
                String MAPSIZE = ""+Constants.numberOfColumns+"x"+Constants.numberOfRows;

                gameLogObj.OpenAndAppendData(currentDateandTime, "UserId value", "sessionID Value",
                        " gameID Value", GameLayer.roundStr, "RoundDiscriptor", GameLayer.logMsgArgument,GameLayer.logLevelArgument,TrainMapLayer.flagLogType,MAPSIZE,"");


            }



            catch (Exception e) {
                Log.e("Exception in TAPBEFORELAUNCH",">>>>>>>>>>>>"+e);
                GameLog gameLogObj = new GameLog();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
                String currentDateandTime = sdf.format(new Date());
                GameLayer.logLevelArgument = "ERROR";
                GameLayer.logMsgArgument = e.toString();
                GameLayer.roundStr = Integer.toString(Constants.level);
                TrainMapLayer.flagLogType = false; 
                String MAPSIZE = ""+Constants.numberOfColumns+"x"+Constants.numberOfRows;

                gameLogObj.OpenAndAppendData(currentDateandTime, "UserId value", "sessionID Value",
                        " gameID Value", GameLayer.roundStr, "RoundDiscriptor", GameLayer.logMsgArgument,GameLayer.logLevelArgument,TrainMapLayer.flagLogType,MAPSIZE,"" );

            }  

            //CHANGES DONE 7 FEB

        }
        else
        {
            Log.v("In else condition ccTouchesBegan", "))))))))))))))))");

        }
        return true;
    }

请帮助我

1 个答案:

答案 0 :(得分:2)

您可以使用CCMenuItemImage进行触摸。喜欢:

CCMenuItemImage xyz= CCMenuItemImage.item("start.png", "start.png",this, "to_Where_You_Want_To_Replace_Your_Scene");