Jump to content

Sprite not adding using spritesheet animation


pdiddles03
 Share

Recommended Posts

I'm using a spritesheet to output my player.  It's generated with texturepacker.  But when i specify the frames in it, it won't put it on to the game.  Is there anything wrong with my code?

 

var map, floor, player;
    var game = new Phaser.Game(320,240, Phaser.AUTO, null, {
      preload:preload,
      create:create,
      update:update
    });

    function preload(){
      game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
      game.scale.pageAlignHorizontally = true;
      game.scale.pageAlignVertically = true;
      game.load.spritesheet('sprites','images/images.png','images/images.json');
      game.load.spritesheet('player','images/player.png','images/player.json',8,8);
      game.load.tilemap('map','images/tilemap.json',null,Phaser.Tilemap.TILED_JSON);


    }
    function create(){
      map = game.add.tilemap('map');
      map.addTilesetImage('tileset', 'sprites');
      layer = map.createLayer('World 1');
      player = game.add.sprite(32,32,'player');
      console.log(player)
      player.frame = 0;
      player.animations.add('walk', [0,1,2], 30, true)
      player.animations.play('walk');

    }
    function update(){

    }

 

Link to comment
Share on other sites

52 minutes ago, pdiddles03 said:

I'm using a spritesheet to output my player.  It's generated with texturepacker.  But when i specify the frames in it, it won't put it on to the game.  Is there anything wrong with my code?

 


var map, floor, player;
    var game = new Phaser.Game(320,240, Phaser.AUTO, null, {
      preload:preload,
      create:create,
      update:update
    });

    function preload(){
      game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
      game.scale.pageAlignHorizontally = true;
      game.scale.pageAlignVertically = true;
      game.load.spritesheet('sprites','images/images.png','images/images.json');
      game.load.spritesheet('player','images/player.png','images/player.json',8,8);
      game.load.tilemap('map','images/tilemap.json',null,Phaser.Tilemap.TILED_JSON);


    }
    function create(){
      map = game.add.tilemap('map');
      map.addTilesetImage('tileset', 'sprites');
      layer = map.createLayer('World 1');
      player = game.add.sprite(32,32,'player');
      console.log(player)
      player.frame = 0;
      player.animations.add('walk', [0,1,2], 30, true)
      player.animations.play('walk');

    }
    function update(){

    }

 

I'm assuming your using trying to get to display animation with texture altas since your using json instead of just a spritrsheet. So it would be like  

player.animations.add('walk', Phaser.Animation.generateFrameNames('walk', 1, 2),true);

Hope this works for you.

Link to comment
Share on other sites

11 hours ago, mrxj88 said:

I'm assuming your using trying to get to display animation with texture altas since your using json instead of just a spritrsheet. So it would be like  


player.animations.add('walk', Phaser.Animation.generateFrameNames('walk', 1, 2),true);

Hope this works for you.

According to this page: https://phaser.io/examples/v2/animation/sprite-sheet  , I am doing it correctly

Link to comment
Share on other sites

8 hours ago, pdiddles03 said:

I'm confused why you say "you are using json instead of a spritesheet". the json is what describes the spritesheet.

You say you want to add your spritesheet by using the example above that you gave me from the link. But 'Im telling you that's the wrong example your trying to use. Because you are using a json file which means you are trying to use a texture atlas. As spritesheet don't need a json file to describe where the sprite begins and ends because they dont vary in size. Here i found 2 links that may be able to help clear up what i'm saying. the first link is for a texture atlas: https://www.joshmorony.com/how-to-create-animations-in-phaser-with-a-texture-atlas/ And this link is for spritesheet: https://www.joshmorony.com/how-to-create-an-animated-character-using-sprites-in-phaser/

Link to comment
Share on other sites

1 hour ago, mrxj88 said:

You say you want to add your spritesheet by using the example above that you gave me from the link. But 'Im telling you that's the wrong example your trying to use. Because you are using a json file which means you are trying to use a texture atlas. As spritesheet don't need a json file to describe where the sprite begins and ends because they dont vary in size. Here i found 2 links that may be able to help clear up what i'm saying. the first link is for a texture atlas: https://www.joshmorony.com/how-to-create-animations-in-phaser-with-a-texture-atlas/ And this link is for spritesheet: https://www.joshmorony.com/how-to-create-an-animated-character-using-sprites-in-phaser/

Very interesting. so i don't even need a spritesheet. I like that a lot better. Phaser is a new thing to me.  It's naming for different things doesn't make a lot of sense to me but I am sure it will all make sense as time goes on. Thanks for your help!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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