Unsquashed Sprite Squashed Sprite
未碾碎的雪碧碾碎的雪碧
My brother has issues with his sprite squashing whilst moving horizontally. The squashing is permanent after moving. I have found the line that causes the problem but cannot figure out what is causing this issue. When I remove this line the squashing stops however the sprite does not turn. He is following Shaun Spalding's Complete Platformer Tutorial and though I've watched it over I cannot find any issues with the actual code.
我哥哥对他在水平移动时的精灵挤压有问题。搬家后的挤压是永久性的。我已经找到了导致问题的线路,但找不到导致此问题的原因。当我移除这条线时,挤压停止,但是精灵不会转动。他正在遵循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
更多回答
优秀答案推荐
A possible cause of this is that you've set the image_xscale
to a different value before using the line:
出现这种情况的一个可能原因是,在使用行之前,您已经将IMAGE_XScale设置为不同的值:
if (hsp != 0) image_xscale = sign(hsp);
For example, you may have set this in the Create Event to enlarge the sprite:
例如,您可能在创建事件中设置了此选项以放大精灵:
image_xscale = 2;
But that value is reset after setting image_xscale
again, as that line will only return -1
or 1
because of the Sign().
但在再次设置IMAGE_XScale之后,该值将被重置,因为该行将只返回-1或1,因为符号()。
One quick solution is to apply the scale change to that line of code, like this:
一种快速解决方案是将比例更改应用于该行代码,如下所示:
if (hsp != 0) image_xscale = 2 * sign(hsp);
(Once again, presuming you've changed it's scale value somewhere else)
(再次假设您已经在其他地方更改了它的比例值)
Though another solution is to enlarge the sprite itself in the sprite editor, so the scale doesn't have to be kept in mind everytime.
虽然另一种解决方案是在精灵编辑器中放大精灵本身,这样就不必每次都记住比例。
I have had the same issue,(I used similar to Shaun Spaldings code too) but if you go into the resize sprite editor you can scale the image down and that solves the problem. Its the button that looks like full screen (4 arrows facing outwards to each corner) when looking at the sprite in the workspace. There must be some bug with Gamemaker when you scale an object down so much it cant handle it, so the solution is to change the sprite scale out of the room. Goodluck,
-DuckMan-
我也遇到过同样的问题(我也使用了类似于Shaun Spalding的代码),但如果你进入调整大小的精灵编辑器,你可以缩小图像,这就解决了问题。它是在工作区中查看精灵时看起来像全屏的按钮(每个角都有4个向外的箭头)。当你把一个物体缩小到无法处理的程度时,一定是Gamemaker有一些错误,所以解决方案是改变房间外的精灵比例。祝你好运,-达克曼
更多回答
我是一名优秀的程序员,十分优秀!