简体   繁体   English

Andengine onAreaTouched TouchEvent不起作用-ACTION_OUTSIDE和ACTION_CANCEL

[英]Andengine onAreaTouched TouchEvent not working - ACTION_OUTSIDE & ACTION_CANCEL

I have a simple problem. 我有一个简单的问题。 I have a button on the screen. 我在屏幕上有一个按钮。 I want isActionDown to push the button down, and isActionUp to push the button back up again and make my character jump. 我想要isActionDown按下按钮,而isActionUp再次按下按钮,使我的角色跳起来。 But the problem is if I push the button down and drag away from it, the button stays pushed down. 但是问题是,如果我按下按钮并向其拖动,按钮将保持按下状态。 I would like the button to push back up again if the user drags away from it. 如果用户从按钮上拖动,我希望按钮再次向上推。

How can I create the desired affect? 如何创建所需的效果? isActionCancel doesn't seem to do the trick. isActionCancel似乎无法解决问题。

    private void addButton(){
    goB = new AnimatedSprite(240, 364, ResourceManager.getInstance().go_region, vbom){
        @Override
        public boolean onAreaTouched(final TouchEvent event, final float x, final float y){


            if (event.isActionDown()){
                goB.animate(new long[]{ 250 }, new int[] { 1 }, true);
                /*if(event.isActionCancel()){
                    goB.animate(new long[]{ 250 }, new int[] { 0 }, true);
                }*/
            }
            if (event.isActionUp()){
                goB.animate(new long[]{ 250 }, new int[] { 0 }, true);
                fresh = true;
                playerBody.applyLinearImpulse(new Vector2(0, 45), playerBody.getPosition());
            }


            if (event.isActionCancel() || event.isActionOutside()){
                goB.animate(new long[]{ 250 }, new int[] { 0 }, true);
            }
            return true;
        }
    };
    goB.setScale(3);

    registerTouchArea(goB);
    attachChild(goB);

    goB.animate(250);
}

I'm having the hardest time with this, and I've tried all sorts of variations of the code above. 我在这方面经历了最艰难的时光,并且我尝试了上面代码的各种变体。 Please let me know if you have the solution. 如果您有解决方案,请告诉我。

Thanks for your help! 谢谢你的帮助!

Use the 使用

setTouchAreaBindingOnActionDownEnabled(true);
setTouchAreaBindingOnActionMoveEnabled(true);

functions 职能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM