【问题标题】:GML sprite direction facing issue?GML精灵方向面临问题?
【发布时间】:2015-10-08 19:07:54
【问题描述】:

好的,我的精灵朝向方向时遇到问题,我有这样的问题: 如果我按下 D 键,精灵将播放行走精灵,当我松开它时,它面向我行走的方向,但是当我向左行走(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。我已经定义了变量,但是它们在另一个脚本中

【问题讨论】:

    标签: sprite game-maker gml


    【解决方案1】:
    //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 设置为“player”。我的猜测是“玩家”面向右侧,所以当你停止移动时,无论你走哪条路,你都会面向右侧。

    你需要设法检查你最后移动的方向,如果它是向左,将 sprite_index 设置为“player_other_direction”而不是“player”(因为你提到你已经有了这个“player_other_direction " 可以使用的精灵)。

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 1970-01-01
      • 2012-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-09
      • 2011-03-16
      • 1970-01-01
      相关资源
      最近更新 更多