Hello everyone from Corona community, I’m making my first app in Corona and I’m stuck in one little bug that I can’t fix or debug alone.
As this is my first post in the forums and as I am a newbie in this environment, I choose this board to post, but if there is one that better suit my post, please let me know.
Well, my problem is the following:
I started making and Endless Runner app to learn the Corona SDK. Everything went fine and is working, but SOMETIMES the code to check if the player landed on the platform, and change his animation from “falling” to “running” doesn’t work, and he gets stuck on the “falling” animation while landed on the platform.
Normally, we would have this:
But sometimes, and I don’t know why, we have this:
I added some “prints” to the code, to make sure that the code that calls the “Player:setSequence” is being called, it is the case of the two “lets go” debug lines. They are printe before and after the setSequence command. Here are some code snippets:
function animatePlayer() --controla as animações de ação do jogador vx, vy = player:getLinearVelocity( ) local checkAgain --se o jogador está subindo no plano y, animação de pulo if vy \< 0 then player.gravityScale = 1 player:setSequence("jump1") checkAgain = true --se o jogador está descendo, animação de cair elseif vy \> 0 then if ( tapSwitch ) then --verifica se ele esta caindo ou planando player:setSequence("jump3") player.gravityScale = 0.05 else print("hey") player:setSequence("jump2") player.gravityScale = 1 end checkAgain = true --se jogador está parado no plano y, animação de corrida else if(checkAgain) then player:setSequence( "run" ) player:play() checkAgain = false end end end
This is the animation code, special atention to the “print(hey)”, that is the code to control when the player is “falling”
function onLocalCollision( event ) --controla toda as colisões do jogo (Jogador com o chão e jogador com os inimigos) local locPlayer local other if (event.phase == "began") then --o corona nao tem como saber qual object é qual numa colisão, aqui defino qual é qual através do nome do objeto if (event.object1.name=="player") then locPlayer = event.object1 other = event.object2 elseif (event.object2.name=="player") then locPlayer = event.object2 other = event.object1 else return end --colisão com o chão if (other.name=="p") then print("ho") audio.play( sfx.se2, { channel=2 } ) combo = 0 updateCombo() player.estado = 0 player:setLinearVelocity(0,0) player.gravityScale = 1 print("lets go") player:setSequence( "run" ) print("lets go") player:play()
Nos this is my collision function, the platform is called “p”. When is collides with the player, it prints “ho”, do some things, and I surrounded the setSequence with the prints “lets go”. And as you can see from the screenshots, they are all called, and it don’t print “hey” after, indicating that the code that make the player “fall” doesn’t get called again after the collision, so the case is that the setSequence(Run) is not working.
I don’t have a clue from where do I go from here. With these informations can somebody help me, or do you need some more code snippets to try a guess?
Thank you for you time!
Paulo, (a not english speaker)