mercredi 17 février 2016

Buttons for levels

Hello People of stackoverflow. I'm trying to make a button which works like a "next Level" button. So far I can only link the button to a other Level 2 class. How can I implement it so that it will work for Level 3 class too?

package GUI 
{
    import net.flashpunk.Entity;
    import net.flashpunk.Graphic;
    import net.flashpunk.graphics.Image;
    import net.flashpunk.World;
    import net.flashpunk.utils.Input;
    import net.flashpunk.utils.Key;
    import net.flashpunk.FP;
    /**
     * ...
     * @author Steven Lai
     */
    public class continue_button extends Entity 
    {
        [Embed(source="../../Assets/continuebutton.png")]
        private const CONTINUE_BUTTON:Class;

        //private var Set_lv3:Boolean;


        public function continue_button()
        {
            graphic = new Image(CONTINUE_BUTTON);
            setHitbox(51, 25);
            width = 51;
            height = 25;
            x = 200;
            y = 100;
            //Set_lv3 = false;


        }

        override public function update():void
        {
            if (collidePoint(x, y, world.mouseX, world.mouseY))
            {
                if (Input.mousePressed)
                {
                    /*
                    if (Set_lv3 == true)
                    {
                        FP.world = null;
                        FP.world = new level_3;
                    }
                    else 
                    {
                        FP.world = null;
                        FP.world = new level_2;
                        Set_lv3 = true;
                    }
                does not work as intended*/ 
                FP.world = null; //used to migitate mem leak
                FP.world = new level_2; //switches to a other world/screen


                }
            }
        }
    }

}

Aucun commentaire:

Enregistrer un commentaire