getProperty() property parameter value (undefined) is not a string.ERROR:
getProperty() property parameter value (undefined) is not a string.ERROR:
请帮我解决游戏中的碰撞问题,这里有一个问题。它一直告诉我对象未定义。还说 Cannot get 属性 "undefined" on element "cdoor1" and for "char" too.
CollisionDetector("cdoor1" , true);
CollisionDetector("char" , true);
function CollisionDetector(object, isDoor){
var playerX = getXPosition("char");
var playerY = getYPosition("char");
var objectX = getProperty(object);
var objectY = getProperty(object);
var playerWidth = getProperty("char" , "width");
var playerHeight = getProperty("char" , "width");
var objectWidth = getProperty(object , "width");
var objectHeight = getProperty(object , "height");
if(playerX + playerWidth >= objectX && playerX <= objectX + objectWidth){
if(playerY + playerHeight >= objectY && playerY <= objectY + objectHeight){
if(isDoor && !gameOver){
gameOver = true;
setScreen("screen_lose");
}
else if(isDoor && !gameOver && !getProperty(object,"hidden")){
hideElement("cdoor1");
showElement("odoor1");
}
}
}
}
使用构造函数时,您需要使用 "new" 将它们添加为变量,如下所示:
var cdoor1 = new CollisionDetector("cdoor1" , true);
var char = new CollisionDetector("char" , true);
如果您愿意,可以在这里进一步阅读:https://www.w3schools.com/JS/js_object_constructors.asp
我只需要更改对象的 put getX 和 getY 位置而不是 getProperty();
抱歉我的错误,谢谢大家的帮助!
请帮我解决游戏中的碰撞问题,这里有一个问题。它一直告诉我对象未定义。还说 Cannot get 属性 "undefined" on element "cdoor1" and for "char" too.
CollisionDetector("cdoor1" , true);
CollisionDetector("char" , true);
function CollisionDetector(object, isDoor){
var playerX = getXPosition("char");
var playerY = getYPosition("char");
var objectX = getProperty(object);
var objectY = getProperty(object);
var playerWidth = getProperty("char" , "width");
var playerHeight = getProperty("char" , "width");
var objectWidth = getProperty(object , "width");
var objectHeight = getProperty(object , "height");
if(playerX + playerWidth >= objectX && playerX <= objectX + objectWidth){
if(playerY + playerHeight >= objectY && playerY <= objectY + objectHeight){
if(isDoor && !gameOver){
gameOver = true;
setScreen("screen_lose");
}
else if(isDoor && !gameOver && !getProperty(object,"hidden")){
hideElement("cdoor1");
showElement("odoor1");
}
}
}
}
使用构造函数时,您需要使用 "new" 将它们添加为变量,如下所示:
var cdoor1 = new CollisionDetector("cdoor1" , true);
var char = new CollisionDetector("char" , true);
如果您愿意,可以在这里进一步阅读:https://www.w3schools.com/JS/js_object_constructors.asp
我只需要更改对象的 put getX 和 getY 位置而不是 getProperty(); 抱歉我的错误,谢谢大家的帮助!