Jump to content

Can't add rectangle ?


Kaoff
 Share

Recommended Posts

Hello there !

I'm just starting with Phaser 3, and I was hoping to make myself a simple pong game as an exercise to test out the framework.

Thus, I wish I could only use the this.add.rectangle method in my scene to display my players and my ball, but this method only work when I already invoked the this.add.image method BEFORE.

To be more explicit:

export default class PlayScene extends Scene {
  constructor () {
    super({ key: 'PlayScene' })
  }

  create () {
    const logo = this.add.image(400, 150, 'logo')
    const rect = this.add.rectangle(400, 300, 100, 100, 0xff0000, 1)

    this.tweens.add({
      targets: logo,
      y: 450,
      duration: 2000,
      ease: 'Power2',
      yoyo: true,
      loop: -1
    })
  }
}

This will display both logo and rectangle

But

export default class PlayScene extends Scene {
  constructor () {
    super({ key: 'PlayScene' })
  }

  create () {
    const rect = this.add.rectangle(400, 300, 100, 100, 0xff0000, 1)
  }
}

This will display nothing.

 

Is it normal ? Might the fact I am using PhaserCLI be the problem ?

 

Thanks for your answers :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...