I want to change the scene, say to level2.lua when the “player” is in a certain range of y value. code problem is in bold below. It only works if I set the y value to where the starting y value is. Please help if this is possible. I know the code in bold isn’t right at all it’s just to tell you what I’m aiming for.
–
– main.lua
–
display.setStatusBar( display.HiddenStatusBar )
local physics = require “physics”
physics.start()
local background = display.newImage( “background.jpg” )
background.x, background.y = 160, 240
local ground = display.newImage( “ground.png” )
ground.x, ground.y = 160, 700
physics.addBody( ground, “static”, { friction=1.0, density=1.0, bounce=0 } )
local player = display.newImage( “player.png” )
player.x = 160
player.y = 230
player.myName = “player”
physics.addBody( player, { friction=1.0, density=1.0, bounce=0.3, radius=35 } )
player.isFixedRotation = true
local function onScreenTouch( event )
if event.phase == “began” then
– make player jump forward
player:applyForce( 0, -500, player.x, player.y )
end
end
if (player.y is in the range of 200, 250) then I want it to
change scene for example to test2.lua
end
Runtime:addEventListener( “touch”, onScreenTouch )