Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between an Image and a Sprite in Phaser 3?

In the Phaser 3 docs I can see that the biggest difference between Sprite and Image is that you cannot animate or add a physics body to an Image, but in Image properties you can see an animationManager. I'm a little confused about this. Can anyone clarify this?

like image 519
winter Avatar asked Jan 31 '19 08:01

winter


People also ask

What is a sprite in phaser?

A Sprite Game Object is used for the display of both static and animated images in your game. Sprites can have input events and physics bodies. They can also be tweened, tinted, scrolled and animated. The main difference between a Sprite and an Image Game Object is that you cannot animate Images.

How do you add a background image in phaser?

Give this a try: var config = { type: Phaser. AUTO, width: 600, height: 800, physics: { default: 'arcade', arcade: { gravity: {y: 500}, debug: false } }, scene: { preload: preload, create: create, update: update } }; That should load your first scene with the functions you have created.


1 Answers

Actually, according to the official docs Phaser.GameObjects.Image does not have a AnimationManager property.

Phaser.GameObjects.Sprite on the other hand does have an anims that can access animations, but doesn't include a direct property of type AnimationManager. Both can be confirmed by using the TypeScript defintions.

This is because AnimationManager is global, and handles all animations. In Phaser 2 all objects would handle their own animations. See for example Phaser 2 CE's Phaser.Image docs.

So just as the documentation says, Image is effectively a static, lighter-weight, Sprite.

like image 63
James Skemp Avatar answered Nov 12 '22 07:11

James Skemp