Multiple Entities In One


(Zouhair Elamrani Abou Elassad) #1

I was wondering if there is a way to create an entity that contains other entities, i’m trying to create o Sliding Menu that appears when the user pause the game, the sliding menu have some buttons in it, so i was thinking to make every button an entity ans set Hitboxes, or is there a better way ?


(Darrin) #2

You may want to check out PunkUI. It has a few features but not sure how updated. I typically just create an Entity manager that displays or hides the entities.

  • mobtype 1 entity
  • mobtype 1 entity manager

etc


(rostok) #3

…or just add switch to the new world with all the necessary menu entities. Good trick here is to take screenshot before switching. Also if you modify main engine update and render loop you could have two worlds being updated and rendered simultaneously.


(B6ka) #4

If you follow the latter approach (suggested by rostok),you can save your current game world in a variable in the menu world, and it can easily be restored once the game is unpaused.

Something like this.

(1) Pause game:

if (Input.pressed(Key.P)) FP.world = new MenuWorld(this);

(2) Unpause the game:

if (Input.pressed(Key.P)) FP.world = _gameWorld;

Where _gameWorld is the variable that we passed to the MenuWorld.

The game world will be restored in exactly the same state it was before you paused the game.


(Zouhair Elamrani Abou Elassad) #5

… That’s a good idea, but how can i take a screenshot of the current world ?


(Zouhair Elamrani Abou Elassad) #6

… Thank you, i will take a look a that ^^


(Zouhair Elamrani Abou Elassad) #7

… Why do we need to pass the current world reference to the main world ?


(rostok) #8

FP.screen.capture() should return appropriate Image object.

As of passing the reference to menu you need to know what world to switch you when exiting from menu.

@B6ka I think that making new Menu is not needed, It can be stored as separate world as well.


(B6ka) #9

@AbouElassad, you need to pass the current game world to the menu world (not the main world), so that when you unpause the the game, you can restore the current world to exactly the same state.

@rostok, sure you can the menu state world as well.


(B6ka) #10

You can look at the example here. Ignore other stuff look at GameWorld and MenuWorld. It is a really rough cut, but I think it illustrates the idea. Press P to pause. endless_runner.zip (263.4 KB) .


(Zouhair Elamrani Abou Elassad) #11

… I see what you mean, thank You so much ^^


(Zouhair Elamrani Abou Elassad) #12

… Got it, no i understand , thank you ^^


(Zouhair Elamrani Abou Elassad) #13

… I’ll check it out, thank you for the link :smile: