Quote: "3- how can disable Miles down and Miles up? because when joystick is Miles down or Miles up the speed decrease. I want Joystick work only in 4 direction."
I downloaded your sprites and had a look at your code (from the 10th of jan) and if I understand the issue correctly then I think what you need to do is convert the joystickx into a simple move left, move right or don't move parameter. Below is a modified version of your code.
SetDisplayASpect ( 4.0/3.0 )
// Add Virtual Joystick Buttons
AddVirtualJoystick( 1, 10, 88, 12)
state = 0
// Create Player Sprite
Player = CreateSprite ( 0 )
SetSpriteSize ( Player, GetSpriteWidth (Player), GetSpriteHeight (Player) )
SetSpriteOffset ( Player, GetSpriteWidth( Player )/2, GetSPriteHeight( Player )/2 )
SetSpritePositionByOffset ( Player, 30, 97 )
SetSpritePhysicsOn ( Player, 2 )
SetSpritePhysicsCanRotate( Player, 0 )
SetSpriteDepth ( Player, 0 )
img1 = LoadImage ("p1_stand.png")
img2 = LoadImage ("p1_walk.png")
do
// Move VirtualJoystick to Left and Right
Rem Start **********************************************************************
`save the joystickX value
joystick_x# = getVirtualJoystickX(1)
`determine the x direction_x the sprite moves
if joystick_x# = 0
`not moving
direction_x = 0
else
`direction_x either -1 (move to the left) or 1 (move to the right)
direction_x = joystick_x#/abs(joystick_x#)
endif
select state
case 0:
SetSpriteImage ( Player, img1, 1 )
if direction_x > 0
SetSpriteFlip ( Player, 0, 0 )
SetSpriteImage ( Player, img2, 1 )
SetSpriteAnimation ( Player, 72 , 97 , 11 )
PlaySprite ( Player, 8, 1, 1, 11 )
state = 2
elseif direction_x < 0
SetSpriteFlip ( Player, 1, 0 )
SetSpriteImage ( Player, img2, 1 )
SetSpriteAnimation ( Player, 72 , 97 , 11 )
PlaySprite ( Player, 8, 1, 1, 11 )
state = 3
Endif
endcase
case 2:
`apply the "direction_x" variable to calculate the sprite's velocity
setSpritePhysicsVelocity(Player,direction_x*20.0,getSpritePhysicsVelocityY(Player))
if direction_x = 0
state = 0
SetSpriteImage ( Player, img1, 1 )
elseif direction_x < 0
SetSpriteFlip ( Player, 1, 0 )
SetSpriteImage ( Player, img2, 1 )
SetSpriteAnimation ( Player, 72 , 97 , 11 )
PlaySprite ( Player, 8, 1, 1, 11 )
state = 3
Endif
endcase
case 3:
setSpritePhysicsVelocity(Player,direction_x*20.0,getSpritePhysicsVelocityY(Player))
if direction_x = 0
state = 0;
SetSpriteImage ( Player, img1, 1 )
elseif direction_x > 0
SetSpriteFlip ( Player, 0, 0 )
SetSpriteImage ( Player, img2, 1 )
SetSpriteAnimation ( Player, 72 , 97 , 11 )
PlaySprite ( Player, 8, 1, 1, 11 )
state = 2
Endif
endcase
endselect
Rem End **********************************************************************
print("joystick_x# : " + str(joystick_x#))
print("direction_x : " + str(direction_x))
sync()
Loop
What I've done is to save the getVirtualJoystickX(1) value to a variable and then used this to calculate another variable "direction_x" that has values -1 (move left) 0 (don't move) and 1 (move right) then applied this throughout the code. You can use the same I hope this is what you wanted or if not I hope it gives some ideas.
I've not looked at the sprite size issue but, as Marl said, you need to load the images first and then create the sprites. What you can then do is change the size of the sprites using the setSpriteSize or setSpriteScale commands.