Serious trouble when it comes to menus


(John Andersson) #1

Okay, so I add a menu from the players entity… if check is pressed blaba add new menu to the world. However, I can’t seem to remove the menu with the same button without creating a new one

I tried

	//Upgrade
if (Input.pressed(Key.D) && Upgrades_Menu.activated == false) FP.world.add(new    Upgrades_Menu(FP.camera.x, FP.camera.y));

and in the upgrades menu entity, I have this code in the update function

    if (Input.pressed(Key.D))
    {
        FP.world.recycle(this);
        activated = false;
    }

The problem is that immediately after it removes itself and sets activated to false, then the hero class adds a new one since it seems to be checking for the variable “activated” immediately after it is set to false in the menu entity. Any ideas on how to fix this? =P Such a simple task, yet so confusing!

(PS, Upgrades_Menu.activated is a static variable)


(Martí Angelats i Ribera) #2

Different thing here. To start with, try to avoid using FP.world directly this is not the way to go the 99% of the times (this is not the exception).

Then the main error. The problem is that you check if the D is pressed but it will always be becouse you open the menu with it. The solution is use a boolean set to false adn when D is unpressed set it to true (and and an and to that if).

Also, what you are suppose to do here do here is to create and entity which have the following properties:

  1. x = 0
  2. y = 0
  3. graphic.relative = false

You can add the entity to the world or have the property visible set to false and then just do entity.visible = true to show it.


(John Andersson) #3

I’ll try your solution asap :slight_smile: Why is FP.world not a proper way? What should I do instead?


(Martí Angelats i Ribera) #4

FP.world may be modified before you get it. Instead you should have the world in a variable (if is an entity it already have it. It’s called world [tecnically is a parameter that you can only read]).