我正在与Gamemaker:Studio进行游戏,并且玩家的精灵没有改变,他遇到了一个恼人的问题。我想尽快反馈。 "玩家"的精灵不改变的是spr_playerboom。这个想法是,当玩家击中Z时,精灵会改变。
image_speed = 0.2;
var zpress = keyboard_check(ord('Z'));
var rkey = keyboard_check(vk_right);
var lkey = keyboard_check(vk_left);
var jkey = keyboard_check(vk_space);
if(zpress){
sprite_index = spr_playerboom;
}
//Check for ground
if(place_meeting(x, y+1, obj_floor)){
vspd = 0;
//Jumping
if(jkey){
vspd = -jspd;
}
} else {
//Gravity
if(vspd < 10){
vspd += grav;
}
}
//Moving right
if(rkey){
hspd = spd;
sprite_index = spr_playerwalkright;
}
//Moving left
if(lkey){
hspd = -spd;
sprite_index = spr_playerwalkleft;
}
//Check for not moving
if((!rkey && !lkey) || (rkey && lkey) || (!zpress)){
hspd = 0;
sprite_index = spr_playerstand;
}
//Horizontal Collision
if(place_meeting(x+hspd, y, obj_floor)){
while(!place_meeting(x+sign(hspd), y, obj_floor)){
x+=sign(hspd);
}
hspd = 0;
}
//Moving Horizontally
x += hspd;
//Vertical Collision
if(place_meeting(x, y+vspd, obj_floor)){
while(!place_meeting(x, y+sign(vspd), obj_floor)){
y+=sign(vspd);
}
vspd = 0;
}
//Moving Vertically
y += vspd;
答案 0 :(得分:0)
让我们删除不能用于sprite的代码。结果将是:
var zpress = keyboard_check(ord('Z'));
var rkey = keyboard_check(vk_right);
var lkey = keyboard_check(vk_left);
if (zpress)
sprite_index = spr_playerboom;
if (rkey)
sprite_index = spr_playerwalkright;
if (lkey)
sprite_index = spr_playerwalkleft;
if ((!rkey && !lkey) || (rkey && lkey) || (!zpress))
{
sprite_index = spr_playerstand;
}
所以这是一个错误。哪里?前三个条件很简单,不能发生冲突。所以你需要看看最后一个条件。
(!rkey && !lkey) || (rkey && lkey) || (!zpress)
它的意思
如果(both left and rigth keys is not pressed)
或(both left and right keys is pressed)
或(z key is not pressed)
。因此,如果您按下Z,但未按下rkey + lkey,精灵将更改为spr_playerstand
等。
(((!rkey and !lkey) or (rkey and lkey)) and (!zpress))
在这种情况下,当按下Z时,精灵不会变为spr_playerstand