我正在努力制作这个游戏,现在,我有一个可以移动的角色,但是我想有效地改变角色的宽度和高度。因此,角色上下移动的大小与角色左、右的大小不同,所以我做了一个if语句,如果玩家正在上升,那么宽度是这个,如果玩家是向右的,那么with就是那个。但是,当我完成输入代码时,它会给出两个错误:
Syntax error on token ";", { expected after this token
Syntax error, insert "}" to complete Block谁能告诉我出什么事了吗?
下面是代码:
public class player extends creature {
// other code
private static int player_width;
private static int player_height = 70; // error 1 here
if(currentimage == assets.player_up) {
player_width = 50;
} else if(currentimage == assets.player_down) {
player_width = 50;
} else if(currentimage == assets.player_right) {
player_width = 60;
} else if(currentimage == assets.player_left) {
player_width = 60;
} // error 2 here
public player(game game, float x, float y) {
super(x, y,player_width,player_height);
this.game = game;
}以下是生物构造器:
public abstract class creature extends entity {
public static final int DEFAULT_HEALTH = 10;
public static final float DEFAULT_SPEED = 3.0f;
public static final int DEFAULT_CREATURE_WIDTH = 64,
DEFAULT_CREATURE_HEIGHT = 64;
protected int health;
protected float speed;
protected float xMove, yMove;
public creature(float x, float y, int width, int height) {
super(x, y, width, height);
health = DEFAULT_HEALTH;
speed = DEFAULT_SPEED;
xMove = 0;
yMove = 0;
}发布于 2017-06-23 00:49:58
嗯,你应该把那些if语句放在构造函数中。如果它们在类中,则不会运行,但是method.Just不会将它们放到您的
public player(game game, float x, float y)方法,你应该是金的。
注意:只是一个侧面,你应该大写类名,它使代码更容易阅读。
https://stackoverflow.com/questions/44711314
复制相似问题