Jump to content

four direction sprite not working


Parser.Error
 Share

Recommended Posts

/*
when i move sprite with keyboard, phaser not remember the last frame of direction. and frame are broken.  
*/
 
import store from './core/utilitises/store.js';
 
const GAME = new Phaser.Game(
800,
600,
Phaser.AUTO,
'',
{
preload: preload,
create: create,
update: update,
render: render
});
 
function preload(){
GAME.load.image('background','asset/images/background/grid-1920x1920.png');
 
// name sprite - image source sprite - width sprite - height sprite - number image
GAME.load.spritesheet('player', 'asset/images/heroes/@skytrue.png', 48, 66, 32);
}
 
function create(){
GAME.add.tileSprite(0, 0, 1920, 1920, 'background');
GAME.world.setBounds(0, 0, 1920, 1920);
GAME.physics.startSystem(Phaser.Physics.P2JS);
 
store.player = GAME.add.sprite(GAME.world.centerX, GAME.world.centerY, 'player');
 
GAME.physics.p2.enable(store.player);
store.player.animations.add('down', [0,1,2,3,4,5,6,7], 8, true, true);
store.player.animations.add('left', [8,9,10,11,12,13,14,15], 8, true, true);
store.player.animations.add('right', [16,17,18,19,20,21,22,23], 8, true, true);
store.player.animations.add('up', [24,25,26,27,28,29,30,31], 8, true, true);
 
store.cursors = GAME.input.keyboard.createCursorKeys();
GAME.camera.follow(store.player);
 
}
 
function update(){
 
store.player.body.setZeroVelocity();
 
if (store.cursors.up.isDown) {
store.player.body.moveUp(100)
store.player.animations.play('up');
} else if (store.cursors.down.isDown) {
store.player.body.moveDown(100);
store.player.animations.play('down');
} else if (store.cursors.left.isDown) {
store.player.body.moveLeft(100)
store.player.animations.play('left');
} else if (store.cursors.right.isDown) {
store.player.body.moveRight(100);
store.player.animations.play('right');
} else {
store.player.animations.stop();
store.player.frame = 0
}
 
}
 
function render(){
 
}
 
console.log(GAME, "test")
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...