【发布时间】: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