我的create
函数如下:
create: function() {
var checkbox1 = game.add.checkbox( 10, 10, { text: 'labeltext', style: { fill: '#ffffff' } }, 'texture' );
checkbox1.events.onInputUp.add( function( elm, pointer ){
alert( checkbox1.state );
}, this );
}
但是,这会返回以下错误:
Phaser.Cache.getImage: Key "texture" not found in Cache
我该如何解决这个问题?
最佳答案
我假设您正在使用 Checkbox addon for Phaser .
根据文档,game.add.checkbox
函数中的第四个参数是一个字符串,它应该是与 Phaser Cache 中存储的纹理相对应的键。
您已指定字符串'texture'
作为此参数的值。
您看到的错误消息意味着您没有加载以 texture
作为键的资源,或者您加载了它但随后以某种方式从缓存中清除了它。
如果是前者(最有可能),那么您需要确保在尝试将其用作此复选框的纹理之前加载它:
game.load.image('texture', 'path to texture');
关于javascript - 添加复选框时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47546099/