# \[SOLVED\]Sprite sizing problem: Cannot read property 'setSize' of null

**URL:** <https://phaser.discourse.group/t/solved-sprite-sizing-problem-cannot-read-property-setsize-of-null/3381>\
**Category:** Phaser 3\
**Created:** [August 7, 2019, 3:48pm UTC](https://phaser.discourse.group/t/solved-sprite-sizing-problem-cannot-read-property-setsize-of-null/3381 "2019-08-07T15:48:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThePandaJam](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/thepandajam/32/1814_2.png) [@ThePandaJam](https://phaser.discourse.group/u/ThePandaJam)\
**Post date:** [August 7, 2019, 3:48pm UTC](https://phaser.discourse.group/t/solved-sprite-sizing-problem-cannot-read-property-setsize-of-null/3381/1 "2019-08-07T15:48:47Z")

</div>

I’m trying to set sprite hitboxes to match the size of the graphics. I currently have this:  
 ![image](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/7/72a03ca07caaba0f37d68d356571de39abb85a21.png)  
As you can see, the hitbox size doesn’t match.  
I know that you have to set the hitbox size separately using `setSize()` and `setOffset()`, so I’m using this here in my code:

```
create(){
  this.coordinates = {
    //key: [x,y,scale]
    0:[20, 20, 0.5],
    1:[60, 60, 0.8],
    2:[100, 100, 1],
    3:[140, 140, 1.2],
    4:[180, 180, 0.3],
    5:[220, 220, 2],
    6:[260, 260, 0.7],
    7:[300, 300, 1.7],
  }
  this.astros = this.physics.add.group();
  this.scatterObjects(this.coordinates);
}

scatterObjects(coords){
    let allFrames = this.anims.generateFrameNumbers('junk');
    allFrames.forEach(element => {
      console.log(element.frame);
      console.log(coords[element.frame][0]);
      let thing = new Astro(this,coords[element.frame][0],coords[element.frame][1],'junk',element.frame)
      thing.setScale(coords[element.frame][2]);
      console.log(thing);
      //This line causes issues:
      // thing.setSize(45*coords[element.frame][2], 60*coords[element.frame][2]);
      this.astros.add(thing);
    });

```

I get the following error:  
 ![image](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/7/74a60be8280063cbd01cfe952e46155050c83644.png)  
I don’t really understand how that can happen, since the object I’m calling this `setSize()`function on is printed right above and it is certainly not null…

Any help would be apperciated 🙂

---

<div class="post-metadata">

**Author:** ![ThePandaJam](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/thepandajam/32/1814_2.png) [@ThePandaJam](https://phaser.discourse.group/u/ThePandaJam)\
**Post date:** [August 7, 2019, 3:52pm UTC](https://phaser.discourse.group/t/solved-sprite-sizing-problem-cannot-read-property-setsize-of-null/3381/2 "2019-08-07T15:52:41Z")

</div>

Ah! I realised that no physics were assigned to the sprite objects, so I moved this line

```
this.astros.add(thing);

```

before

```
thing.setSize(45*coords[element.frame][2], 60*coords[element.frame][2]);

```

and that seems to have done the trick, though the sizing needs some tweaking

---

<div class="post-metadata">

**Author:** ![ThePandaJam](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/thepandajam/32/1814_2.png) [@ThePandaJam](https://phaser.discourse.group/u/ThePandaJam)\
**Post date:** [August 7, 2019, 3:54pm UTC](https://phaser.discourse.group/t/solved-sprite-sizing-problem-cannot-read-property-setsize-of-null/3381/3 "2019-08-07T15:54:47Z")

</div>

This line was sufficient to set the hitboxes to the right size.

```
thing.setSize(45, 60);

```

![image](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/a/a63cdd0f4b90585b89029f58ae3ff5fe8480cf52.png)
