Kaoff

Can't add rectangle ?

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 :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.