如何在Game Maker中制作跳跃动画?

时间:2016-10-16 05:14:57

标签: game-maker

由于某些原因,当我运行游戏时,精灵在其跳跃动画中而不是在开始时空闲,即使向左和向右移动精灵仍然是跳跃动画。我按照youtube上的教程我知道左右动画可以提供任何帮助,我们将不胜感激。

///platform "physics"

var rkey = keyboard_check(vk_right);
var lkey = keyboard_check(vk_left);
var jkey = keyboard_check_pressed(vk_up);

//Check for ground
if (place_meeting(x, y+1, obj_solid))
{
airjump = 1;
vspd = 0;
//Jumping
if (jkey)
  {
    vspd = -jspd;
  }
}
else
{
//Gravity
if (vspd < 10 )
{
 vspd += grav;
}    
//Check For airjump
if(airjump > 0)
{
    if(jkey)
    {
    vspd = -jspd;
    airjump -= 1;        
    }
}
}

//Moving Right
if(rkey)
{
hspd = spd;
//Left Wall-Jump
if(place_meeting(x-1, y, obj_solid) && !place_meeting(x, y+1, obj_solid)
&&              !lkey)
{
    vspd = -jspd;
}
}
//Moving Left
if(lkey)
{
hspd = -spd;
//Right Wall-Jump
if(place_meeting(x+1, y, obj_solid) && !place_meeting(x, y+1, obj_solid) 
&&       !rkey)
{
    vspd = -jspd;
}
}
//Check for not moving
if((!rkey && !lkey) || (rkey & lkey))
{
hspd = 0 ;
}
//Horizontal Collisions
if(place_meeting(x + hspd, y, obj_solid))
{
while(!place_meeting(x+sign(hspd), y,obj_solid))
{
    x += sign(hspd);
}
hspd = 0;
}

//Move Horizontally
x += hspd;

//Vertical Collisions
if(place_meeting(x, y+vspd, obj_solid))
{
while(!place_meeting(x, y+sign(vspd),obj_solid))
{
    y += sign(vspd);
}
vspd = 0;
}

//Move Vertically
y += vspd;

//Control The Sprites
if(vspd != 0)
{
sprite_index = spr_player_jump;
image_speed = 1;
//use the next line if you have a falling animation as well but the 
falling         animation should be the second one
//image_index = y>yprevious;
}

else
{

if(hspd != 0)
{
    sprite_index = spr_player_walk;
    image_speed = .15;
}
else if(hspd = 0)
{
    sprite_index = spr_player_stand;
}
}
if (!place_meeting(x,y+1, obj_solid))
{
sprite_index=spr_player_jump;
}

//Control the direction that the player is facing
if(hspd > 0)
{
image_xscale = 1;    
}
else if (hspd < 0)
{
image_xscale = -1;
} 

1 个答案:

答案 0 :(得分:0)

首先,在创建事件中,设置image_speed = 0;然后你必须播放一次动画。

然后,当您进入步骤事件时,当玩家跳跃时:

`while (image_index != image_number)
{
    image_index++;
}
//Or you can replace image_number with the end
//value of your jump animation, if you also have other animations like
//walking then set image index to the start value before running the loop`

另外,检查以确保玩家也在地面上(所以按空中的空格键不会让动画播放。除非你想要它。)