hi,I made this little code based on a tutorial I found on the internet about 2d character jump and run, ive tried to implement it in agk, my character jump very well except for one thing, after the first jump my char gets overlaped in the scene. here is my code, if someone show me the error will be grateful. thanks
obs: no media required, if someone can compile to see,
// Landscape App
setvirtualresolution(1024,768)
SetSyncRate(30,1)
//create my char
jogador = createsprite(0)
setspritecolor(jogador,255,0,255,255)
setspritesize(jogador,50,100)
setspritepositionbyoffset(jogador,1024/2,768/2)
//... and the scene
cenario = createsprite(0)
setspritecolor(cenario,0,0,255,255)
setspritesize(cenario,500,50)
setspritepositionbyoffset(cenario,1024/2,768/1.5)
//initialize var
gravity# = 9.8
moving = 0
jumping = 0
//debugmode
setphysicsdebugon()
do
tecla = getrawlastkey()
jumpkeypressed = getrawkeystate(32)
jogadorx# = getspritex(jogador)
jogadory# = getspritey(jogador)
//groundy# = getspritey(cenario)
//intialize y velocity
//jumping boolean when jump key is pressed
if jumping = 0 and jumpKeyPressed = 1
velocity_y# = 80.0
//gravity# = 9.8
jumping = 1
endif
if jumping = 1
jogadory# = jogadory# - velocity_y#
velocity_y# = velocity_y# - gravity#
setspritey(jogador,jogadory#)
endif
//init moving boolean when walk key is pressed
//init velocity_x
// if moving = 0 and leftKeyPressed = 1
// moving = 1
// velocity_x# = -10
// elseif moving = 0 and rightKeyPressed = 1
// moving = 1
// velocity_x# = 10
// else
// moving = 0
// endif
//move object by x velocity
//if moving = 1 then jogadorx# = jogadorx# + velocity_x#
setspritey(jogador,jogadory#+gravity#)
if getspritecollision(jogador,cenario)=1
setspritey(jogador,jogadory#)
velocity_y# = 0
jumping = 0
endif
//setspritey(jogador,jogadory#+gravity#)
print("Timer: "+str(timer(),0))
print("FPS: "+str(screenfps(),0))
print("Tecla: "+str(tecla))
print("JumpkeyPressed?: "+str(JumpkeyPressed))
print("Jogador Y: "+str(jogadory#))
print("Cenario Y: "+str(groundy#))
sync()
loop
//end game loop