Hi,
I am new at Phaser and has my first problem with the player sprite.
Here is my code:
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
pixelArt: true,
physics: {
default: 'arcade',
arcade: {
gravity: {
y: 0
}
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
let controls;
let player;
const game = new Phaser.Game(config);
function preload() {
// MAP
this.load.image('tiles', 'map/galletcity/galletcity.png');
this.load.tilemapTiledJSON('map', 'map/GameMap.json');
this.load.spritesheet('survivor', 'characters/player.png', {
frameWidth: 16,
frameHeight: 16
});
}
function create() {
// MAP
const map = this.make.tilemap({
key: 'map'
});
const tileset = map.addTilesetImage('galletcity', 'tiles');
const below = map.createStaticLayer('Below', tileset, 0, 0);
const world = map.createStaticLayer('World', tileset, 0, 0);
world.setCollisionByProperty({
collides: true
});
const above = map.createStaticLayer('Above', tileset, 0, 0);
// DEBUGGER COLLIDES
// const debugGraphics = this.add.graphics().setAlpha(0.75);
// world.renderDebug(debugGraphics, {
// tileColor: null, // Color of non-colliding tiles
// collidingTileColor: new Phaser.Display.Color(243, 134, 48, 255), // Color of colliding tiles
// faceColor: new Phaser.Display.Color(40, 39, 37, 255) // Color of colliding face edges
// });
// PLAYER
player = this.physics.add.sprite(400, 400, 'survivor');
this.physics.add.collider(player, world);
player.setCollideWorldBounds(true);
this.anims.create({
key: 'up',
frames: this.anims.generateFrameNumbers('survivor', {
start: 1,
end: 6
}),
frameRate: 10,
repeat: -1
});
this.anims.create({
key: 'right',
frames: this.anims.generateFrameNumbers('survivor', {
start: 1,
end: 6
}),
frameRate: 10,
repeat: -1
});
this.anims.create({
key: 'down',
frames: this.anims.generateFrameNumbers('survivor', {
start: 1,
end: 6
}),
frameRate: 10,
repeat: -1
});
this.anims.create({
key: 'left',
frames: this.anims.generateFrameNumbers('survivor', {
start: 1,
end: 6
}),
frameRate: 10,
repeat: -1
});
this.anims.create({
key: 'turn',
frames: [{
key: 'survivor',
frame: 3
}],
frameRate: 20
});
// CAMERA
this.cameras.main.setBounds(0, 0, map.widthInPixels, map.heightInPixels);
const cursors = this.input.keyboard.createCursorKeys();
const controlConfig = {
camera: this.cameras.main,
left: cursors.left,
right: cursors.right,
up: cursors.up,
down: cursors.down,
speed: 0.5
};
controls = new Phaser.Cameras.Controls.FixedKeyControl(controlConfig);
}
function update(time, delta) {
// CAMERA
controls.update(delta);
// PLAYER
player.body.setVelocity(0);
}
I read the tutorial and looked at the examples but don’t understand my problem.
Does it come from the sprite?
Thanks