Ed you nailed it.
I created several Runtime events in my “player” module.
I passed the event.target (“player” module), and event.names to my “ui” module.
Anywhere there was a table property for “M.isMovingLeft = true” or “M.isJumping = true” has been replaced by a dispatchEvent and adding a unamed property to the event table.
It looks something like this in the UI module:
local function onButtonTap( event ) local taps = event.numTaps -- eventual use for double jump or some nifty mechanic local targetID = event.target.id if "jump" == targetID then Runtime:dispatchEvent({name = M.jumpEvent, target=uiTarget, true}) debugString = "Jump" end end
It looks something like this in the “player” module:
local function onUserInput(event) local name = event.name local val = event[1] if(name == "playerIsJumping") then player.isJumping = val elseif(name == "playerIsMovingRight") then player.isMovingRight = val elseif(name == "playerIsMovingLeft") then player.isMovingLeft = val elseif(name == "playerIsMovingUp") then player.isMovingUp = val elseif(name == "playerIsMovingDown") then player.isMovingDown = val end end
and the “GamePlayScene” moldule, where the onEnterFrameEvent is stored. Which is nice because the dispatched events in the UI module effect the player module. No middle-man. The onEnterFrameEvent just gets to call appropriate methods without a sea of parameters as they are internal to the “player” module now instead of the “ui” module.
player:setDeltaTime(dtk:getDeltaTime()) player:move() player:jump() map.updateView() -- Updates a map's camera system and culling. Should be called each frame and directly after you manually move the map.
Thumbs up or down Ed?