好吧,我的精灵面临着方向的问题,我有这样的: 如果我按下D键,精灵将播放行走的精灵,当我释放它时,它面向我正在行走的方向, HOWEVER 当我向左走时(A键),它会播放精灵走向左边的动画,但是当我停下来的时候,它会立即看到另一个方向,所以继承我的代码( PS我有一个不会走路且面向另一个方向的精灵(player_other_direction)):
///Platformer Physics
var rkey = keyboard_check(ord("D"));
var lkey = keyboard_check(ord("A"));
var jkey = keyboard_check(ord("W"));
//Check for the ground
if(place_meeting(x, y+1, obj_platform))
{
vspd = 0;
//Jumping
if(jkey)
{
vspd = -jspd;
}
}
else
{
//Move down with gravity
if (vspd < 10)
{
vspd += grav;
}
if(keyboard_check_released(ord("W")) && vspd <-4){
vspd = -4;
}
}
//Moving to the right
if(rkey)
{
sprite_index = player_walking_right;
if(hspd < spd){
hspd += fric;
} else{
hspd = spd;
}
}
//Moving to the left
if(lkey)
{
sprite_index = player_walking_left;
if(hspd > -spd){
hspd -= fric;
} else {
hspd = -spd;
}
}
//Check for not moving
if((!rkey and !lkey) || (rkey && lkey))
{
sprite_index = player;
if(hspd != 0){
if(hspd<0){
hspd += fric;
} else {
hspd -= fric;
}
}
}
//Horizontal Collisions
if(place_meeting(x+hspd, y, obj_platform))
{
while(!place_meeting(x+sign(hspd), y, obj_platform)){
x+= sign(hspd);
}
hspd = 0;
}
//Move Horizontally
x += hspd;
//Vertical Collisions
if(place_meeting(x, y+vspd, obj_platform))
{
while(!place_meeting(x, y+sign(vspd), obj_platform)){
y+= sign(vspd);
}
vspd = 0;
}
//Move Vertically
y += vspd;
PS。我已经定义了变量,但是它们在另一个脚本中
答案 0 :(得分:3)
//Check for not moving
if((!rkey and !lkey) || (rkey && lkey))
{
sprite_index = player;
if(hspd != 0){
if(hspd<0){
hspd += fric;
} else {
hspd -= fric;
}
}
}
在这里,你检查玩家是否在移动;如果没有,你将它的sprite_index设置为&#34; player&#34;。我的猜测是&#34;播放器&#34;面向右边,所以当你停止移动时,无论你走哪条路,都会面向右边。
您需要设置一种方法来检查您上次移动的方向,如果它在左侧,请将sprite_index设置为&#34; player_other_direction&#34;而不是&#34;播放器&#34; (因为你提到你已经有了这个&#34; player_other_direction&#34; sprite准备好使用了。)