I'm importing an image from a json spritesheet, which works okay, however I want to get the sprite to scale once it is in the game. Using the code below I get the error in console "Uncaught TypeError: plane.scale is not a function".
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
scene: {
preload: preload,
create: create
}
};
const game = new Phaser.Game(config);
function preload () {
this.load.image('background', 'assets/1.jpg');
this.load.multiatlas('aircraft', 'assets/texture.json', 'assets');
}
function create () {
const background = this.add.image(800, 600, 'background');
const plane = this.add.sprite(200, 200, 'aircraft', 'Glider2.png');
plane.scale(0.1, 0.1);
}
The problem / error is caused, because the function you should use is setScale not scale (link to the documentation).
The code should look like this:
...
const plane = this.add.sprite(200, 200, 'aircraft', 'Glider2.png');
plane.setScale(0.1);
...
btw: if the scale is the same value on the x and the y axis you can omit the second parameter.