我应该为学校做一个JS游戏,但我需要帮助:
var player1 = {
char: kitana,
x: 150,
y: 50,
life: 100,
facing: 1,
currentAnimation: "move",
currentFrame: 0,
frameSlow :0,
currentImage: new Image(),
};
var player2 = {
char: kitana,
x: 150,
y: 50,
life: 100,
facing: 1,
currentAnimation: "move",
currentFrame: 0,
frameSlow :0,
currentImage: new Image(),
};
var kitana = {
hitbox :{
left : 5,
right : 100,
},
images : {
move:[],
punch: [],
},
};
我想把" kitana"通过"播放器"中的引用对象,我该如何轻松地做到这一点?
我的目标是使用player1.char.images.move[0] = "exemple";
之类的内容,然后将其用于player2.char.images.move[0]
感谢您的帮助,抱歉我的英文不好
答案 0 :(得分:0)
在播放器之前放置kitana
对象定义,您将获得正确的引用:
var kitana = {
hitbox: {
left: 5,
right: 100,
},
images: {
move: [],
punch: [],
},
};
var player1 = {
char: kitana,
x: 150,
y: 50,
life: 100,
facing: 1,
currentAnimation: "move",
currentFrame: 0,
frameSlow: 0,
currentImage: new Image(),
};
var player2 = {
char: kitana,
x: 150,
y: 50,
life: 100,
facing: 1,
currentAnimation: "move",
currentFrame: 0,
frameSlow: 0,
currentImage: new Image(),
};