Thanks
also I add this line for stand on the ladder and don't move down.
if LadderCollide = 0
SetphysicsGravity (0,100)
else
SetphysicsGravity (0,0)
Endif
But somtomes SetphysicsGravity (0,0)the problem will occur. mean before climp the ladder if I push a box sprite then climb the ladder, the box sprite Glide.
This is my full code and Sprites. Please Help me to fix some Problem.
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")
// Ladder Sprite
ladder = CreateSprite ( LoadImage ("ladder.png") )
SetSpriteSize ( ladder, 5, 40 )
SetSpritePosition ( ladder, 50, 60 )
// Sprite Box
Box = CreateSprite ( LoadImage ("box.png") )
SetSpriteSize ( Box, 8, 10 )
SetSpriteOffset ( Box, 4, 4 )
SetSpritePositionByOffset ( Box, 40, 96 )
SetSpritePhysicsOn ( Box, 2 )
SetSpritePhysicsCanRotate(Box, 0)
SetSpritePhysicsFriction(Box, 100)
do
// Move VirtualJoystick to Left and Right
Rem Start **********************************************************************
select state
case 0:
SetSpriteImage ( Player, img1, 1 )
if GetVirtualJoystickX ( 1 ) > 0
SetSpriteFlip ( Player, 0, 0 )
SetSpriteImage ( Player, img2, 1 )
SetSpriteAnimation ( Player, 72 , 97 , 11 )
PlaySprite ( Player, 8, 1, 1, 11 )
state = 2
elseif GetVirtualJoystickX ( 1 ) < 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:
setSpritePhysicsVelocity(Player,GetVirtualJoystickX(1)*20.0,getSpritePhysicsVelocityY(Player))
if GetVirtualJoystickX ( 1 ) < 0
SetSpriteFlip ( Player, 1, 0 )
SetSpriteImage ( Player, img2, 1 )
SetSpriteAnimation ( Player, 72 , 97 , 11 )
PlaySprite ( Player, 8, 1, 1, 11 )
state = 3
elseif GetVirtualJoystickX ( 1 ) = 0
state = 0
SetSpriteImage ( Player, img1, 1 )
Endif
endcase
case 3:
setSpritePhysicsVelocity(Player,GetVirtualJoystickX(1)*20.0,getSpritePhysicsVelocityY(Player))
if GetVirtualJoystickX ( 1 ) > 0
SetSpriteFlip ( Player, 0, 0 )
SetSpriteImage ( Player, img2, 1 )
SetSpriteAnimation ( Player, 72 , 97 , 11 )
PlaySprite ( Player, 8, 1, 1, 11 )
state = 2
elseif GetVirtualJoystickX ( 1 ) = 0
state = 0
SetSpriteImage ( Player, img1, 1 )
Endif
endcase
endselect
Rem End **********************************************************************
LadderCollide = GetSpriteCollision ( Player, ladder )
if LadderCollide = 1
Print ("Collision")
if GetVirtualJoystickY ( 1 ) < 0
SetSpritePhysicsVelocity(Player, getSpritePhysicsVelocityX(Player), GetVirtualJoystickY (1)*20.0)
//SetphysicsGravity (0,0)
else
SetSpritePhysicsVelocity(Player, getSpritePhysicsVelocityX(Player), 0)
endif
endif
if LadderCollide = 0
SetphysicsGravity (0,100)
else
SetphysicsGravity (0,0)
Endif
Print (GetVirtualJoystickY(1))
Print (BoxCollide)
sync()
Loop