OnAreaTouched堆叠Andengine

时间:2013-11-22 07:38:43

标签: touch andengine sprite

首先,我将向您展示图像以解释我的问题

  

Small unScaled Image

图片说明:

我有2个精灵 RED 白色。我附上

  1. 带场景的红色精灵和
  2. 带红色精灵的白色精灵
  3. 我已移动并缩放红色精灵白色精灵,如第二张图片

    Scaled Moved Image

    我的问题

    我已经注册了触控器。但是我想在缩放完整图像时注册白色精灵的触摸(在第二个图像的情况下)

    但是当我在完全刻度上注册触摸时,它不会触发触摸。

    要触发触摸,我必须在图像1

    之前注册两个精灵触摸

    我也遇到了类似的问题 here

    我的代码

    > `titleScene = new Scene();
            titleScene.setBackground(new Background(0, 1, 0));
            A_Background_Sprite = new Sprite(0, 0, A_Background_TextureRegion, activity.getVertexBufferObjectManager());
            titleScene.attachChild(A_Background_Sprite);
            RED_Sprite = new Sprite(50, 50, RED_TextureRegion, activity.getVertexBufferObjectManager()){
    
    
                public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
    
                    if(!RED_Sprite.isScaled())
    
                    {
                    Log.i("Apple_Background_Sprite", "setOnClickListener");
                    AppleX=(int) RED_Sprite.getX();
    
                    AppleY= (int) RED_Sprite.getY();
    
    
    
                    RED_Sprite.registerEntityModifier(new SequenceEntityModifier(new MoveModifier(1f, RED_Sprite.getX(), camera.getCenterX(), RED_Sprite.getY(),camera.getCenterY()),new ScaleModifier(1f, 1f, 2f, new IEntityModifierListener() {
    
                        public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {
                            // TODO Auto-generated method stub
    
                            white_Sprite.setVisible(true);
            titleScene.registerTouchArea(white_Sprite);
                        }
    
                        public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
                            // TODO Auto-generated method stub
    
    
                        }
                    },EaseLinear.getInstance())));
    
    
    
    
                    }
                    else
                    {        
    
                    //  Spelling_Background_Sprite.registerEntityModifier(new MoveModifier(4f,  camera.getWidth(), 20, 400, 400));
    
                    }
    
                    return true;
                                  // here you can use the code
                                }
            };
    
    
    
            RED_Sprite.setSize(150f, 150f);
    
    
            titleScene.setTouchAreaBindingOnActionDownEnabled(true);
    
            white_Sprite.setVisible(false);
    
            titleScene.attachChild(RED_Sprite);
            RED_Sprite.attachChild(white_Sprite);
    
    
            titleScene.registerTouchArea(RED_Sprite);
    

    请看看

    RED_Sprite.registerEntityModifier(new SequenceEntityModifier(new MoveModifier(1f,RED_Sprite.getX(),camera.getCenterX(),RED_Sprite.getY(),camera.getCenterY()),new ScaleModifier(1f,1f,2f,new IEntityModifierListener(){

                public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {
                    // TODO Auto-generated method stub
    
                    white_Sprite.setVisible(true);
    titleScene.registerTouchArea(white_Sprite);
                }
    

1 个答案:

答案 0 :(得分:0)

当你有覆盖的对象,并且想要触发所有对象上的触摸事件时,请确保在onTouch回调函数结束时不返回true,否则触摸侦听器会停止处理剩余的触摸事件。有关详细信息,请参阅本教程http://andengineguides.wordpress.com/2011/09/14/getting-started-touch-events/