我正在开发一款游戏,遇到了一点问题。现在,我有一个文本框,上面显示run into me以继续到下一个级别。当我遇到它时,下一层加载得很完美,这部分工作得很好。现在我试着改变一下文本框显示的位置,并且有两个指向两个不同级别的链接。游戏中有物品,我想做的是让玩家在有物品的情况下进入一个等级,如果没有物品则进入不同的等级。为此,我会给一个项目一个值,然后在与文本框冲突时,检查该值是否在库存中。所以主要的问题是,是否可以将两个节点链接到一个文本框?如果是这样的话,我该怎么做呢?下面是我的一些代码:
从我的.js文件中:
function Choice(scene, text, image, width, height, z) {
// Static textbox object that holds the text of a choice
tChoice = new TextBox(scene, image, width, height);
tChoice.text = text;
tChoice.choiceNumber = 0;
tChoice.z = z;
return tChoice;
} // end choice从我的.html文件中:
function checkChoiceCollisions() {
// If a player collides with a choice, that choice's level will be displayed.
for (var i = 0; i < choices.length; i ++) {
if(player.collidesWith(choices[i])) {
player.visible = false;
switchNode(i);
} // end if
} // end for
} // end checkChoiceCollisionsJSON:
"options":[{"text":"Run into me to continue\nto the next level","link":"nodes/nextLevel.txt","width":"150", "height":"75", "x":"800", "y":"250"}]谢谢你的帮助!!
编辑:我忘记添加这部分代码了..
function makeChoices() {
// Makes the choice textboxes defined by the level.
for (var i = 0; i < choices.length; i ++) {
// Destroy the previous level's choice boxes.
var index = spriteList.list.indexOf(choices[i]);
spriteList.list.splice(index, 1);
} // end for
choices = [];
for (var i = 0; i < curNode.options.length; i ++) {
// Create each choice box defined by the level.
var width = parseInt(curNode.options[i].width);
var height = parseInt(curNode.options[i].height);
var x = parseInt(curNode.options[i].x);
var y = parseInt(curNode.options[i].y);
var choice = new Choice(scene, curNode.options[i].text, null, width, height, 2);
choice.setPosition(x, y);
choice.fitText();
choices.push(choice);
if (!checkChoiceRequirements(i)) {
// Only display a choice if its requirements are met.
choices[i].visible = false;
} // end if
} // end for
} // end makeChoices发布于 2014-06-03 08:40:09
这是一个问题,因为我缺少评论…的要点
因为您的函数"Choice“是大写的,所以我希望它是一个伪经典构造函数,然后它将默认返回其隐式的”this“对象。但是你返回的却是'tChoice',这可能会产生意想不到的后果。
您还定义了一个'tChoice‘对象的值,而没有通过'var’关键字声明它。您是否打算访问名为“tChoice”的全局变量?
否则,我不确定您究竟在问什么“可以将两个节点链接到一个文本框吗?”访问对象似乎是一种很好的方式。你收到错误了吗?你能把你的代码发布到一个Fiddle/Plunkr/JS_Bin吗?
https://stackoverflow.com/questions/24005290
复制相似问题