Javascript 在phaser游戏中添加弹出窗口
我想在游戏中添加弹出窗口。我正在使用phaser并找到modal.js在phaser中添加弹出窗口,它似乎很有用,但当我尝试添加它时,我得到一个错误“Uncaught TypeError:无法设置undefined的属性'modal1'。我想我得到这个错误仅仅是因为我的编码结构。这是我的密码Javascript 在phaser游戏中添加弹出窗口,javascript,jquery,phaser-framework,Javascript,Jquery,Phaser Framework,我想在游戏中添加弹出窗口。我正在使用phaser并找到modal.js在phaser中添加弹出窗口,它似乎很有用,但当我尝试添加它时,我得到一个错误“Uncaught TypeError:无法设置undefined的属性'modal1'。我想我得到这个错误仅仅是因为我的编码结构。这是我的密码 var reg={}; createModals: function(){ reg.modal.createModal({ type: "modal1", inclu
var reg={};
createModals: function(){
reg.modal.createModal({
type: "modal1",
includeBackground: true,
modalCloseOnInput: true,
itemsArr: [{
type: "graphics",
graphicColor: "0xffffff",
graphicWidth: 300,
graphicHeight: 300,
graphicRadius: 40
}, {
type: "text",
content: "The white behind me\nis a [Phaser.Graphic]",
fontFamily: "Luckiest Guy",
fontSize: 22,
color: "0x1e1e1e",
offsetY: -50
}, ]
});
},
showModal1: function(){
reg.modal.showModal("modal1");
}
这方面有什么帮助吗…这是一个完整的例子
var reg={};
函数createModals(){
reg.modal.createModal({
类型:“modal1”,
includeBackground:没错,
modalCloseOnInput:正确,
项目SARR:[
{
键入:“图形”,
graphicColor:“0xffffff”,
宽度:300,
高度:300,
图形半径:40
}, {
键入:“文本”,
内容:“我身后的白色\n是[Phaser.Graphic]”,
fontFamily:“最幸运的家伙”,
尺寸:22,
颜色:“0x1E”,
副职:-50
}
]
});
}
函数showModal1(){
注册模态显示模态(“模态1”);
}
var GameState=函数(游戏){
};
GameState.prototype.create=函数(){
reg.modal=新游戏模式(游戏);
createModals();
VARM1=this.game.add.button(30,50,“m1”,showModal1);
};
var game=new Phaser.game(750380,Phaser.CANVAS,'game');
game.state.add('game',GameState,true)代码>
我是这个库的创建者,看起来你没有在构造函数上传递正确的游戏对象
reg.modal = new gameModal(game);
如果您的游戏对象未被调用game
,则需要传递正确的游戏对象
通常这是从这一行来的
var game = new Phaser.Game(1024, 768, Phaser.AUTO, 'game', null, true);
因此,game
是一个全局变量
@Jatin patil的回答是正确的。我得到了一个错误“未捕获类型错误:无法在patternsRatio.game1.create(game1.js:97)的Phaser.StateManager.loadComplete(Phaser.js:30083)的Phaser.Loader.finishedload(Phaser.js:74233)的patternsRatio.game1.create(game1.js:97)中设置未定义的属性'modals'。”在Phaser.Loader.processLoadQueue(Phaser.js:74190)在Phaser.Loader.asyncComplete(Phaser.js:74263)在Phaser.Loader.fileComplete(Phaser.js:75120)在HTMLImageElement.file.data.onload(Phaser.js:74522)上