How to Create Rectangle Object

I’m new to Phaser, and fairly new to JavaScript in general. I’m trying to create a rectangle object, but it’s throwing the error “Object doesn’t support this action.”

Here’s my code:

var rectangle = new Phaser.Rectangle(0, 0, 1000, 500);

Any thoughts on what I am doing wrong?

var rect = scene.add.rectangle(x, y, width, height, fillColor, fillAlpha);

or

var rect = new Phaser.GameObjects.Rectangle(scene, x, y, width, height, fillColor, fillAlpha);
scene.add.existing(rect);

See this

1 Like

Thank you!

I think I also had issues with my Wampserver so that’s why it might not have been working.

Actually it is still saying “Object doesn’t support property or method 'rectangle”. When I comment out the ‘…this.add.rectangle…’ line, the background appears on the screen correctly (in the background color I set in ‘config’), but when I have that line uncommented, it just turns the background color black. Could there be something else going wrong here besides the code?

See this demo, line 4.

1 Like