How To Add Sprite To Another Sprite?

I’m sure there is a simple way to do this, but I feel like I have tried every combination of

mySprite.add.sprite(...)

mySprite.pysics.add.sprite(...)

etc, and I’m just getting errors…

At a high level, I have one sprite that is an image, but the collision detection is based on the rectangular bounding box. I would like the collision to be based on a smaller oval shape that is closer to the shape of the actual drawing in my image.

My plan is to have the overall mySprite that was created with the png. Then I would like to add a sprite to this called mySpriteHitbox to which I will then add an “invisible” graphic of the oval.

I will then move around the sprite my changing the x and y position of mySprite while using mySpriteHitbox for checking collisions.

Does this strategy make sense? Is there a better way to do what I’m trying to do here, or is this more or less the best way to go?

Thanks!

Did you preload the sprite?
preload() {
this.load.spritesheet(‘spriteName’, ‘spriteFile.png’, { frameWidth: 300, frameHeight: 300 });
}

then in your create:
create() {
this.add.sprite(xPos, yPos, ‘spriteName’);
}

Thanks @BryantFriend,

“this.add.sprite” just adds the sprite to the current scene though.

I’m trying to add the sprite to another sprite

Game Objects can’t have children in Phaser 3. Use Containers.

1 Like