How do I create a Static sprite?

Hey forum :slight_smile:

I’ve got a sprite sheet for this switch that I want to add to my game. When the player touches the switch it’ll play a different animation, etc…

Since i need this object to be animated, I knew I had to preload it as a sprite, however I want it to be a static object. Just sit where I set the coordinates for and loop the animation. I checked the API documents and saw that Sprites can be static or dynamic, but I kind of got confused when I started exploring the StaticBody class and would greatly appreciate some help as to how I can set my sprite as a static object. Below is a small snippet of my code for help. Thank you!

Code Snippet:
// preload spritesheet
var switch1;
this.load.spritesheet(‘switch’, ‘…/assets/level3/switch.png’, {
frameWidth: 70,
frameHeight: 130
});

// create switch
switch1 = this.physics.add.sprite(707, 420, ‘switch’);
switch1.body.immovable = true;
// switch1.body.StaticGroup??

switch1 = this.physics.add.staticSprite(707, 420, 'switch');
2 Likes

thank you!