Hadik Posted December 3, 2015 Share Posted December 3, 2015 Hello I am trying make animations (top down 2D) where I have 4x4 images in one file (spritesheet) like this: http://prntscr.com/99yt7s But I don't know how I can easy use for left,up,down, right movement. I must create this format: http://prntscr.com/99ytid And use like this: game.load.spritesheet('player', 'assets/jedi.png', 32, 45); // Preload// createvar player = game.add.sprite(300, 300, 'player');player.animations.add('up', [12, 13, 14, 15], 10, true); player.animations.add('left', [4, 5, 6, 7], 10, true);player.animations.add('down', [0, 1, 2, 3], 10, true);player.animations.add('right', [8, 9, 10, 11], 10, true);Is there any way How to use one file with multiple animations not in one line, but at more lines ? (But for animations, not simple frames) Thank you for any help Link to comment Share on other sites More sharing options...
pog Posted December 4, 2015 Share Posted December 4, 2015 You want to use a texture atlas and use the game.load.atlas method. Hadik 1 Link to comment Share on other sites More sharing options...
Kobaltic Posted December 4, 2015 Share Posted December 4, 2015 Texture atlas are for a sheet with sprites of different sizes. @Hadik What you have is correct for the 4X4. You just need to call the animation to play. Look up cursor keys and when you press up call player.animations.play('up'). Here is my real working code: In the create:cursors = game.input.keyboard.createCursorKeys();game.physics.enable(player, Phaser.Physics.ARCADE);In the update ( call movePlayer in the update):function movePlayer(){ /* start velocity at 0 * get movement from key pressed * move player with velocity * play correct movement animation */ player.body.velocity.x = 0; player.body.velocity.y = 0; if (cursors.right.isDown) { player.body.velocity.x = playerSpeed; player.animations.play('east'); }else if (cursors.left.isDown) { player.body.velocity.x = -playerSpeed; player.animations.play('west'); }else if (cursors.up.isDown) { player.body.velocity.y = -playerSpeed; player.animations.play('north'); }else if (cursors.down.isDown) { player.body.velocity.y = playerSpeed; player.animations.play('south'); }else { //stop the animation but keep player facing same direction player.animations.stop(); }} Link to comment Share on other sites More sharing options...
Hadik Posted December 4, 2015 Author Share Posted December 4, 2015 Thank you And also thanks for example Link to comment Share on other sites More sharing options...
Recommended Posts