添加复选框时出错
Error when adding checkbox
我的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');
我的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');