Use states to handle switching the texture on the sprite.
Also when posting code/projects please help us so that we can help you.
Your code was hard to read and had some pretty odd things going with syntax of if-then and then a next line with else. It was confusing me and likely confusing you. Clean code with good indents will help you a lot. That and reviewing a book on AGK. Hands On AppGameKit Basic will take you far.
I've fixed your code and added state handling of the sprite's texture to make him walk.
rem Landscape App
SetVirtualResolution (1280,720)
// Create VirtualJoystick
AddVirtualJoystick(1,100,620,150)
idleImage = LoadImage ("idle.png")
spr = CreateSprite(idleImage)
SetSpritePosition (spr,250,470)
setSpriteSize(spr,140,160)
SetSpriteShape (spr,3)
setSpritePhysicsOn(spr,2)
setSpritePhysicsCanRotate(spr,0)
SetSpriteDepth (spr, 0)
SetSpriteAnimation ( spr, 170, 170, 4 )
PlaySprite ( spr, 10 , 1, 1, 4 )
// Load ground Texture
img = LoadImage ("texture.png")
ground = CreateSprite(img)
setSpriteAnimation(ground,128,128,2)
SetSpriteVisible(ground,0)
SetphysicsGravity (0,700)
//SetPhysicsDebugOn ()
// Create Floor Sprite
//Don't put this in a do-loop unless you want to flood the engine with sprites!
cspr = 100
for n = 0 to 12
if getspriteexists(cspr)=0 then clonesprite(cspr,ground)
setspritephysicson(cspr,1)
setspriteframe(cspr,2)
setspritevisible(cspr,1)
SetSpritePosition (cspr, n*100, 620)
SetSpriteSize (cspr, 100,-1)
inc cspr
next n
walkImage = LoadImage("walk.png")
//state for switching the texture
walkState = 0
do
Print("walkState = " + str(walkState))
// Move the Player to left and right
if GetVirtualJoystickX(1) > 0.1
SetSpriteFlip (spr,0,0)
SetSpritePhysicsVelocity (spr, GetVirtualJoystickX(1)*200, GetSpritePhysicsVelocityY(spr))
if walkState = 0
walkState = 1
endif
elseif GetVirtualJoystickX(1) < -0.1
SetSpriteFlip (spr,1,0)
SetSpritePhysicsVelocity (spr, GetVirtualJoystickX(1)*200, GetSpritePhysicsVelocityY(spr))
if walkState = 0
walkState = 1
endif
else
if walkState = 2
//reset to idle
walkState = 0
SetSpritePhysicsVelocity (spr, 0, GetSpritePhysicsVelocityY(spr))
//reset the texture to idle image
SetSpriteImage(spr , idleImage)
SetSpriteAnimation ( spr, 170, 170, 4 )
PlaySprite ( spr, 10, 1)
endif
endif
if walkState = 1
walkState = 2 //prevent from doing this every loop
SetSpriteImage(spr , walkImage)
SetSpriteAnimation(spr , 170 , 170 , 11)
PlaySprite(spr , 10 , 1)
endif
Sync()
loop