【问题标题】:Squashed Sprite when turning horizontally水平转动时压扁的雪碧
【发布时间】:2021-11-20 20:41:36
【问题描述】:

Unsquashed SpriteSquashed Sprite

我的兄弟在水平移动时遇到了他的精灵挤压的问题。移动后挤压是永久性的。我找到了导致问题的线路,但无法弄清楚导致此问题的原因。当我删除这条线时,挤压会停止,但精灵不会转动。他正在关注 Shaun Spalding 的完整平台游戏教程,虽然我已经看过它,但我找不到实际代码的任何问题。

/// @description Insert description here
// You can write your code in this editor

// get player input
key_left=keyboard_check(vk_left);
key_right=keyboard_check(vk_right);
key_jump=keyboard_check_pressed(vk_up);

// calculate movement
var move=key_right-key_left;

hsp=move*walksp;

vsp=vsp+grv;

if(place_meeting(x,y+1,o_wall)) and (key_jump)
{
    vsp=-7;
}

// horizontal collision
if (place_meeting(x+hsp,y,o_wall))
{
    while(!place_meeting(x+sign(hsp),y,o_wall))
    {
        x=x+sign(hsp);
    }
    hsp=0;
}
x=x+hsp;

// vertical collision
if (place_meeting(x,y+vsp,o_wall))
{
    while(!place_meeting(x,y+sign(vsp),o_wall))
    {
        y=y+sign(vsp);
    }
    vsp=0;
}
y=y+vsp;

// animation



if(!place_meeting(x,y+1,o_wall))
{
    sprite_index=splayerA;
    image_speed=0;
    if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{   
    image_speed=1;          
    if (hsp==0)
    {
        sprite_index=s_player;
    }
    else
    {
        sprite_index=splayerR;
    } 
}

if (hsp != 0) image_xscale = sign(hsp); //this line is wrong and causes the squishing

【问题讨论】:

    标签: animation gml game-maker-studio-2


    【解决方案1】:

    一个可能的原因是您在使用该行之前将image_xscale 设置为不同的值:

     if (hsp != 0) image_xscale = sign(hsp);
    

    例如,您可能在 Create Event 中设置了此项来放大精灵:

    image_xscale = 2;
    

    但是在再次设置image_xscale 后,该值会被重置,因为该行将只返回-11,因为Sign()。

    一种快速的解决方案是将比例更改应用于该代码行,如下所示:

    if (hsp != 0) image_xscale = 2 * sign(hsp);
    

    (再一次,假设您在其他地方更改了它的比例值)

    虽然另一种解决方案是在精灵编辑器中放大精灵本身,但不必每次都记住比例。

    【讨论】:

      猜你喜欢
      • 2023-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-13
      • 2021-03-31
      • 2011-05-14
      相关资源
      最近更新 更多