带有Vue.js的sprite.events.onInputDown.add()问题

时间:2018-06-08 11:12:27

标签: javascript vue.js phaser-framework

我是一个新的Web开发人员,目前正在使用Vue.js框架。 决定尝试用Phaser 2制作游戏,我现在很喜欢它! 虽然我遇到了鼠标事件的一些问题,但我对按键事件没有任何问题;)

目前我正在尝试点击图片,只是为了控制台将其注销。 (稍后会想要拖动。) 但首先,我不能让我的控制台注销。 这是我的代码,我在vue.js中使用它! 任何帮助都会很棒!谢谢!

以下是我认为重要的代码片段

mounted () {
  let self = this
  if (this.game == null) {
    this.game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, this.$el, {
      preload: function preload () {
        self.preload(this)
      },
      create: function create () {
        self.create(this)
      },
      update: function update () {
        self.update(this)
      },
      render: function redner () {
        self.render(this)
      }
    })
  }
}
preload () {
  this.game.load.image('pink', require(`@/assets/images/packing/pink-bg.png`))
  this.game.load.image('cat', require(`@/assets/images/packing/cat-head.png`))
  this.game.load.image('table', require(`@/assets/images/packing/table.png`))
  this.game.load.image('plate', require(`@/assets/images/packing/plate.png`))
  this.game.load.spritesheet('container', require(`@/assets/images/packing/container-set.png`), 310, 270)
  this.game.load.spritesheet('scorePlate', require(`@/assets/images/packing/kueh-set.png`), 313, 270)
}
let cat = this.game.add.sprite(0, 0, 'cat')
cat.height = this.game.world.height * 0.25
cat.width = this.game.world.width * 0.15

let table = this.game.add.sprite(0, 0, 'table')
table.height = this.game.height
table.width = this.game.width

this.game.physics.startSystem(Phaser.Physics.ARCADE)

let containerBullu = this.game.add.sprite(this.game.world.width - (this.game.world.centerX + this.game.world.centerX), this.game.world.height / 7, 'container')
containerBullu.height = this.game.world.height * 0.55
containerBullu.width = this.game.world.width * 0.35
containerBullu.frame = 4
containerBullu.inputEnabled = true
containerBullu.events.onInputDown.add(this.listener, containerBullu)

let containerCornflake = this.game.add.sprite(this.game.world.width - (this.game.world.centerX + this.game.world.centerX / 1.8), -50, 'container')
containerCornflake.height = this.game.world.height * 0.6
containerCornflake.width = this.game.world.width * 0.35
containerCornflake.frame = 9
render (phaser) {
  this.game.debug.spriteInfo(this.containerBullu, 100, 100)
}
listener (containerBullu) {
  console.log(containerBullu)
},
destroyed () {
  this.game.destroy()
}

我希望很快能听到任何人的意见! 谢谢!

此致 绝望和哭泣的新前端Web开发人员。 (我已经上了4个小时了。到现在为止。还在......)

0 个答案:

没有答案
相关问题