Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *** This comment is now using the Adam's ES:
- Ok, let's one fast example...
- Keep in mind that I'm using the Button and ToggleButton as example for UI. But you can put in a game if you want as a emergency button or a swith that is on/off, if you want
- I have two scenes:
- P.S.: I'm represting the entity-id with "quotes" followed by { Components }
- SCENE_A:
- "play_button" { CButton.action = "play" }
- "sound_toggle" { CToggleable.action = "sound" }
- "music_toggle" { CToggleable.action = "music" }
- "exit_button" { CButton.action = "exit" }
- SCENE_B:
- "another_button" { CButton.action = "anotherb" }
- "another_toggle" { CToggleable.action = "anothert" }
- These are my Componentes data:
- CToggleable
- + toggled : boolean
- + action : String
- CButton
- + action : String
- ----
- Then I have:
- SceneAController (<-- maybe this is not the appropriated name)
- - will do something when "play", "sound", "music" or "exit" action is perfomed.
- SceneBController
- - will do something when "anotherb", "anothert" action is perfomed.
- ---
- Adam's advice is have one system by component. So:
- SceneAController (controls the SCENE_A actions and creates the entities, components and subsystems for SCENE_A contents)
- SceneBController (controls the SCENE_B actions and creates the entities, components and subsystems for SCENE_B contents)
- ToggleButtonSubsystem (how any entity with CToggleable behave)
- ButtonSubsystem (how any entity with CButton behave)
- ---
- ToggleButtonSubsystem
- {
- // when the bounds of entity (by CPosition) is collided with touch (x, y)), then:
- // --> CToggleable.toggled = !CToggleable.toggled
- // --> Create an ActionEvent with ActionEvent.action = CToggleable.action
- // --> Send the ActionEvent to current controller parent (or SceneAController or SceneBController)
- // else do nothing.
- }
- ButtonSubsystem
- {
- // when the bounds of entity (by CPosition) is collided with touch (x, y)), then:
- // --> Create an ActionEvent with ActionEvent.action = CButton.action
- // --> Send the ActionEvent to current controller parent (or SceneAController or SceneBController)
- // else do nothing.
- }
- ---
- If I have a SCENE_C with:
- P.S.: "entity-id" { Components ... }
- SCENE_C (game scene)
- "alarm_button" { CButton.action = "start the alarm" }
- "switch_toggle" { CToggleable.action = "toggle the elevator up-down" }
- I can still use the ButtonSubsystem and ToggleButtonSubsystem.
- They are going to be created (together with entities and components) in the SceneCController.
- So the parent of ButtonSubsystem and ToggleButtonSubsystem is now the SceneCController that has the ActionEventListener and will know what do do in the action.
- And I will not to have everytime make the CTogglable.toggle != CToggable.toggle (in every susbsystem or controller)
- I'm sending messages to the parent controller, but has any other way to maintain the Toggle and Button "generic" like this without using messages?
- What do you guys think? :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement