Phaser 3 场景 input.on() 未触发触摸事件
Phaser 3 scene input.on() touch events not trigerred
我在 angular 组件(离子项目)的构造函数中有以下设置。
let config = {
type: Phaser.AUTO,
width: '100vw',
height: '100vh',
transparent:true,
disableContextMenu: true,
parent: 'phaser-example',
physics: {
default: 'arcade',
arcade: {
gravity: { y: 200 }
}
},
scene: {
preload: function() {
that.preload(this);
},
create: function() {
that.create(this);
},
update: function() {
that.update(this);
}
}
};
this.game = new Phaser.Game(config);
我在创建方法中为 click/touch 事件设置了一个侦听器,如下所示:
create(scene){
scene.input.on('pointerup', this.moveSourceSprite, scene);
}
但是,从未调用过 moveSourceSprite。但是,当我监听 pointerupoutside 并单击游戏时,会调用 moveSourceSprite。
我想,由于某种原因,场景没有听到整个游戏区域。
我是 Phaser 的新手,一直停留在这一点上。如果你能帮助我,我将不胜感激。
谢谢,
道格
var myScene1 = {
key:'scene1',
preload: function(){
this.load.image('alien1', 'sprites/phaser-alien.png');;
},
create: function(){
this.add.image(100, 100, 'alien1');
this.input.on('pointerup', ()=>{game.scene.start('scene2'); game.scene.stop('scene1')}, myScene1);
},
}
var myScene2 = {
key:'scene2',
preload: function(){
this.load.image('alien2', 'sprites/alien2.png');;
},
create: function(){
this.add.image(100, 100, 'alien2');
this.input.on('pointerup', ()=>{game.scene.start('scene1'); game.scene.stop('scene2')}, myScene2);
},
}
var config = {
type: Phaser.AUTO,
width: 600,
height: 600,
loader: {
baseURL: 'https://raw.githubusercontent.com/nazimboudeffa/assets/master/',
crossOrigin: 'anonymous'
},
parent: 'phaser-example',
scene: [myScene1, myScene2]
};
var game = new Phaser.Game(config);
game.scene.start('scene1');
<script src="//cdn.jsdelivr.net/npm/phaser@3.19.0/dist/phaser.js"></script>
我在 angular 组件(离子项目)的构造函数中有以下设置。
let config = {
type: Phaser.AUTO,
width: '100vw',
height: '100vh',
transparent:true,
disableContextMenu: true,
parent: 'phaser-example',
physics: {
default: 'arcade',
arcade: {
gravity: { y: 200 }
}
},
scene: {
preload: function() {
that.preload(this);
},
create: function() {
that.create(this);
},
update: function() {
that.update(this);
}
}
};
this.game = new Phaser.Game(config);
我在创建方法中为 click/touch 事件设置了一个侦听器,如下所示:
create(scene){
scene.input.on('pointerup', this.moveSourceSprite, scene);
}
但是,从未调用过 moveSourceSprite。但是,当我监听 pointerupoutside 并单击游戏时,会调用 moveSourceSprite。
我想,由于某种原因,场景没有听到整个游戏区域。
我是 Phaser 的新手,一直停留在这一点上。如果你能帮助我,我将不胜感激。
谢谢,
道格
var myScene1 = {
key:'scene1',
preload: function(){
this.load.image('alien1', 'sprites/phaser-alien.png');;
},
create: function(){
this.add.image(100, 100, 'alien1');
this.input.on('pointerup', ()=>{game.scene.start('scene2'); game.scene.stop('scene1')}, myScene1);
},
}
var myScene2 = {
key:'scene2',
preload: function(){
this.load.image('alien2', 'sprites/alien2.png');;
},
create: function(){
this.add.image(100, 100, 'alien2');
this.input.on('pointerup', ()=>{game.scene.start('scene1'); game.scene.stop('scene2')}, myScene2);
},
}
var config = {
type: Phaser.AUTO,
width: 600,
height: 600,
loader: {
baseURL: 'https://raw.githubusercontent.com/nazimboudeffa/assets/master/',
crossOrigin: 'anonymous'
},
parent: 'phaser-example',
scene: [myScene1, myScene2]
};
var game = new Phaser.Game(config);
game.scene.start('scene1');
<script src="//cdn.jsdelivr.net/npm/phaser@3.19.0/dist/phaser.js"></script>