Jump to content

Problem about player sprite and TileMap


aitim
 Share

Recommended Posts

sorry for my english.

 

here is my player sprite

FgfF8SD.png

 

and there are my code

var game = new Phaser.Game(1280, 720, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render});function preload() {	game.load.spritesheet('player', 'assets/boyz.png', 100, 144);	game.load.image('ground', 'assets/platform.png');	game.load.image('floor', 'assets/floorsprite.png');	game.load.image('tree', 'assets/tree.png');    game.load.tilemap('map', 'assets/map1.json', null, Phaser.Tilemap.TILED_JSON);}var platforms;var left = false;function create() {	map = this.add.tilemap('map');    map.addTilesetImage('floor');	map.addTilesetImage('tree');	blocked = map.createLayer('blocked');	blocked.debug = true;	layer = map.createLayer('tree');	layer = map.createLayer('ground');    map.setCollisionBetween(0, 100);	game.physics.startSystem(Phaser.Physics.ARCADE);	platforms = game.add.group();    platforms.enableBody = true;	var ground = platforms.create(0, game.world.height - 64, 'ground');    ground.scale.setTo(6, 2);    ground.body.immovable = true;    var ledge = platforms.create(400, 450, 'ground');    ledge.body.immovable = true;    ledge = platforms.create(-150, 250, 'ground');    ledge.body.immovable = true;			player = game.add.sprite(20, game.world.height - 144*3, 'player');    game.physics.arcade.enable(player);    player.body.gravity.y = 300;    player.body.collideWorldBounds = true;    player.animations.add('left', [1, 2, 3, 4], 10, true);    player.animations.add('right', [6, 7, 8, 9], 10, true);	player.body.gravity.y = 300;	game.camera.follow(player);		cursors = game.input.keyboard.createCursorKeys();	}function update() {	game.physics.arcade.collide(player, blocked);		player.body.velocity.x = 0;     if (cursors.left.isDown)    {        player.body.velocity.x = -200;        player.animations.play('left');		left = true;    }    else if (cursors.right.isDown)    {        player.body.velocity.x = 200;        player.animations.play('right');		left = false;    }    else    {        player.animations.stop();		if(left == true)        player.frame = 0;		else{		player.frame = 5;		}    }        if (cursors.up.isDown && player.body.touching.down)    {        player.body.velocity.y = -380;    }		if (!player.body.touching.down)	{		if(left == false)		player.frame = 10;		else{		player.frame = 11;		}	}}function render() {}

this is the result

1Cl5VHZ.jpg

 

my player touching tile map but it not display 5th sprite frame and cannot jump

how can I solve?

 

Thank you

Link to comment
Share on other sites

  • 2 months later...
 Share

  • Recently Browsing   0 members

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