So let’s say I have a UI module that deals with the on screen D-pad and a jump button interfacing.
Let’s also say I have a Player Character module that deals with moving the player character around the screen and holds it’s physics variables/constants.
And lastly I have Game Play Scene module that handles “onEnterFrameEvent” Which is the best “lua / Corona” way to deal with this event?
Below is the code, but Method 1 essentially uses “public” tables that anything can modify
Method 2 uses function calls to return a bool. Same functionality. The tutorials I’ve watched seem to lean toward the tables, but my experience is abstraction is the best policy. Your input please.
EDIT: This example is simplified a bit so I don’t have to post every function, you can imply what it does by its name I think.
Method 1:
local function onEnterFrameEvent(event) local dt = dtk:getDeltaTime() if ui.dPadActive == true then player:move(ui.isPressing\_Up, ui.isPressing\_Right, ui.isPressing\_Down, ui.isPressing\_Left, dt) end if ui.isJumping == true then player:jump(dt) ui.isJumping = false end map.updateView() -- Updates a map's camera system and culling. Should be called each frame and directly after you manually move the map. end
or Method 2:
local function onEnterFrameEvent(event) local dt = dtk:getDeltaTime() if ui:get\_dPadActive() == true then -- functions returns bool player:move(ui:get\_isPressing\_Up(), ui:get\_isPressing\_Right(), ui:get\_isPressing\_Down(), ui:get\_isPressing\_Left(), dt) end if ui:get\_isJumping() == true then -- function returns bool player:jump(dt) -- setting the "isJumping" value is reset in the function call if its value was true end map.updateView() -- Updates a map's camera system and culling. Should be called each frame and directly after you manually move the map. end