Hey everybody!
I’m building my endless run game in Corona Sdk. I’m using Composer and Widget libraries to create scenes and buttons.
The problem:
I have my player walking and two buttons for jumping and crouching. I can’t understand why when the buttons are pressed, the scrolling speed of background and ground increases and my enemies start “scrolling” the other way. This leads to a Corona Simulator Runtime error when player and enemy collide, instead of game over scene.
Actually I need speed to increase but haven’t write the code yet
This is the scrolling function:
local function scroller (self, event)
local speed = speedIncrement
if self.x < -(display.contentWidth-speed2) then
self.x = 2display.contentWidth-speed*2
else
self.x = self.x-speed
end
end
This is the buttons code
local function ButtonPressed(event)
local target = event.target
local targetId = target.id
if event.phase ==“ended” then
if targetId =="1" then
if not player.isJumping then
print ("Salta")
player.isJumping=true
player:applyLinearImpulse(0,-15,player.x,player.y)
player:setSequence("jump")
player:play()
player:addEventListener( "sprite", walkAgain )
end
elseif targetId =="2" then
if not player.isCrouching then
print ("Abbassati")
player.isCrouching=true
player:setSequence("crouch")
player:play()
player:addEventListener( "sprite", walkAgain )
end
end
player.isNotWalking = true
end
end