I’ve been at this for hours.
My TileSprites smooth when scaled. I don’t want that behaviour. I’ve tried pixelArt: true
, antialias: false
, roundPixels: true
, which all have no effect on TileSprites when they’re scaled.
It’s weird because I effectively use the same code as the TileSprite Pixel Art example.
Here’s my current code. I’m only including relevant bits.
/* globals Phaser */
const defaultConfig = {
type: Phaser.AUTO,
parent: "game",
width: 800,
height: 600,
physics: {
default: "arcade",
arcade: {
gravity: { y: 500 },
debug: true
}
},
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.NO_CENTER
},
pixelArt: true,
render: {
antialias: false,
pixelArt: true,
roundPixels: true
}
};
class Game
{
constructor(config = {})
{
this.game = new Phaser.Game(Object.assign({}, defaultConfig, config));
this.game.scene.add("main", MainScene, true);
}
}
class ParallaxManager
{
constructor() { }
preload(scene)
{
scene.load.image("background_01", "assets/parallax-mountain-bg.png");
scene.load.image("parallax_01_mountain_01", "assets/parallax-mountain-montain-far.png");
// ...
}
create(scene)
{
// THIS DOESN'T WORK WITH PIXELART WHEN SCALED
this.sky = scene.add.tileSprite(scene.scale.width / 2, scene.scale.height / 2, 272 * 4, 160 * 4, "background_01");
// this.sky.setTileScale(4);
this.sky.tileScaleX = 4;
this.sky.tileScaleY = 4;
this.furthest = scene.add.tileSprite(scene.scale.width / 2, scene.scale.height * .4, 272 * 3, 160 * 3, "parallax_01_mountain_01");
this.furthest.setTileScale(3);
// ...
Game.ground = scene.physics.add.staticGroup();
Game.ground.create(scene.scale.width / 2, scene.scale.height, "ground")
.setScale(2, 5)
.refreshBody();
}
update(scene)
{
// ...
}
}
class MainScene extends Phaser.Scene
{
_createProgressBar()
{
// ...
}
_initializePlayer()
{
// THIS WORKS WHEN SCALED WITH PIXELART
Game.player = this.physics.add.sprite(this.scale.width / 2, this.scale.height / 2, "player_idle");
Game.player.setScale(3);
// ...
}
_handlePlayerInput()
{
// ...
}
constructor(config)
{
Game.parallax = new ParallaxManager();
super({
roundPixels: true,
pixelArt: true
});
}
init(data) { }
preload()
{
this._createProgressBar();
Game.parallax.preload(this);
this.load.image("ground", "assets/platform.png");
// Load Player sprites
this.load.spritesheet("player_idle", "assets/Player/Idle/idle.png", {
frameWidth: 20, frameHeight: 190 / 5
});
this.load.spritesheet("player_move", "assets/Player/Run/run.png", {
frameWidth: 57 / 3, frameHeight: 112 / 3
});
}
create()
{
Game.parallax.create(this);
// ...
}
update()
{
Game.parallax.update(this);
// ...
}
}
export default Game;
Please let me know if there’s anything I can do to remedy this.
EDIT: Here’s a snapshot of what the game currently looks like:
And here’s a snapshot of what the scene should look like: