简体   繁体   中英

AndEngine: Make sprite move and jump at the same time?

I'm having a bit of difficulty with this program and I'm not quite sure how to resolve it.

Currently in my game, the character can jump, move left and move right; however not at the same time (entirely). If my character is in the air and I move left or right, he WILL go that direction, but if he is moving left or right BEFORE jumping, nothing will happen. This is the current code I have for the situation:

    final Rectangle jump = new Rectangle(100, 300, 60, 60, vbom)
    {
        public boolean onAreaTouched(TouchEvent touchEvent, float X, float Y)
        {
            if (touchEvent.isActionDown())
            {
                player.jump();
            }
            return true;
        };
    };

    final Rectangle left = new Rectangle(20, 200, 60, 60, vbom)
    {
        public boolean onAreaTouched(TouchEvent touchEvent, float X, float Y)
        {
            if (touchEvent.isActionUp())
            {

                player.stopRunning();

            }
            else
            {

                player.setRunningLeft();
            }
            return true;
        };
    };

    final Rectangle right = new Rectangle(100, 200, 60, 60, vbom)
    {
        public boolean onAreaTouched(TouchEvent touchEvent, float X, float Y)
        {
            if (touchEvent.isActionUp())
            {

                player.stopRunning();

            }
            else
            {
                player.setRunningRight();

            }
            return true;
        };
    };

The rectangle objects are placeholders for the on screen buttons. This code is also largely based on the http://www.matim-dev.com/ Full-Game tutorial with several modifications and add-ins.

This bug may be because of one of your logic, but first, check your multi-touch settings. It happened to one of my game, because it will ignore the other touch events.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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