# How to Create Rectangle Object

**URL:** <https://phaser.discourse.group/t/how-to-create-rectangle-object/5308>\
**Category:** Phaser 3\
**Created:** [February 23, 2020, 10:17pm UTC](https://phaser.discourse.group/t/how-to-create-rectangle-object/5308 "2020-02-23T22:17:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![eric](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@eric](https://phaser.discourse.group/u/eric)\
**Post date:** [February 23, 2020, 10:17pm UTC](https://phaser.discourse.group/t/how-to-create-rectangle-object/5308/1 "2020-02-23T22:17:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rexrainbow](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/rexrainbow/32/51_2.png) [@rexrainbow](https://phaser.discourse.group/u/rexrainbow)\
**Post date:** [February 24, 2020, 3:49am UTC](https://phaser.discourse.group/t/how-to-create-rectangle-object/5308/2 "2020-02-24T03:49:28Z")

</div>

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

```

or

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

```

See [this](https://rexrainbow.github.io/phaser3-rex-notes/docs/site/shape-rectangle/#create-shape-object)

---

<div class="post-metadata">

**Author:** ![eric](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@eric](https://phaser.discourse.group/u/eric)\
**Post date:** [February 24, 2020, 4:20am UTC](https://phaser.discourse.group/t/how-to-create-rectangle-object/5308/3 "2020-02-24T04:20:15Z")

</div>

Thank you!

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

---

<div class="post-metadata">

**Author:** ![eric](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@eric](https://phaser.discourse.group/u/eric)\
**Post date:** [February 24, 2020, 5:09am UTC](https://phaser.discourse.group/t/how-to-create-rectangle-object/5308/4 "2020-02-24T05:09:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rexrainbow](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/rexrainbow/32/51_2.png) [@rexrainbow](https://phaser.discourse.group/u/rexrainbow)\
**Post date:** [February 24, 2020, 10:24am UTC](https://phaser.discourse.group/t/how-to-create-rectangle-object/5308/5 "2020-02-24T10:24:42Z")

</div>

See [this demo](https://codepen.io/rexrainbow/pen/OweyWd), line 4.
