Created
February 20, 2019 00:16
-
-
Save chrisdugne/1bfd2a0451ca6914865145b17bfdc27e to your computer and use it in GitHub Desktop.
corona-stutter.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local spaceship = display.newGroup() | |
App.hud:insert(spaceship) | |
spaceship.y = display.contentHeight - 100 | |
spaceship.x = display.contentWidth * 0.5 | |
local image = display.newImage( | |
spaceship, | |
'assets/images/game/spaceship.png', | |
0, 0 | |
) | |
---------------------------------------------------- | |
local getTimer = system.getTimer | |
local latestTime = getTimer() | |
local way = 1 | |
local speed = 250 | |
local function moveSpaceship() | |
local ms = getTimer() | |
local dt = ms - latestTime | |
latestTime = ms | |
local distance = speed * dt / 1000 * way | |
spaceship.y = spaceship.y - distance | |
if(spaceship.y < 100 or spaceship.y > display.contentHeight -100) then | |
way = way * -1 | |
-- Runtime:removeEventListener('enterFrame', moveSpaceship) | |
end | |
end | |
Runtime:addEventListener('enterFrame', moveSpaceship) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment