Quote: "Can you show me the whole code to see if I gave you a bad example?"
The problem might be that in this snippet:
x# = GetDirectionX()
y# = GetDirectionY()
if x# > 0.5 then x# = x# + 1.0
else if x# < -0.5 then x# = x# - 1.0
if y# > 0.5 then y# = y# + 1.0
else if y# < -0.5 then y# = y# - 1.0
setspriteposition(1,x#,y#) // update sprite position
that x# and y# get reset (to GetDirectionX/Y respectively) each time an arrow key is released and since you're positioning the sprite to x# and y#, ....well.
But AL had the right idea, try:
rem
rem AGK Application
rem
rem MrSovr youtube
rem tutorial #1
rem MY Version 2.0
rem Landscape App
SetDisplayAspect( 4.0/3.0 )
setVirtualResolution(640,480)
rem create and set sprite
loadimage(1,"posionshroom.png")
createsprite(1,1)
SetSpriteSize(1,42,40) // used to control sprite size
SetSpritePositionByOffset(1,50,50) // sets sprites X&Y to center
rem set sprite start position X&Y
x#=320.0
y#=240.0
rem A Wizard Did It!
do
Print("use the arrow keys to move the Shroom")
rem show statistics for X and Y
print("X position = " + str ( GetSpriteX(1)))
print("Y position = " + str ( getspritey(1)))
rem get input and move sprite
DirX# = GetDirectionX()
DirY# = GetDirectionY()
if DirX# > 0.5 then x# = x# + 1.0
else if DirX# < -0.5 then x# = x# - 1.0
if DirY# > 0.5 then y# = y# + 1.0
else if DirY# < -0.5 then y# = y# - 1.0
setSpritePositionByOffset(1,x#,y#) // update sprite position
sync()
loop
Note: I'm on a mac right now so haven't tested the code.