Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

phaser tilemap layer and sprite collision


Recommended Posts

HI ,

i am trying to make a simple rpg stye game. i have created a map in tiled editor and exporting it to json. i can load and display the map in game but the colisons between my sprite and collision layer is not working. i have followed example from  here . i also do not see any error in console. it just dosent work.  here is my code. i am alsso attaching my level fileslevel2

<!doctype html> 
<html lang="en"> 

    canvas {cursor: url('/assets/sprites/cursors/Black.png'), default;}

    <meta charset="UTF-8" />
    <title>Phaser - Making your first game, part 1</title>
    <script type="text/javascript" src="js/phaser.js"></script>
    <style type="text/css">
        body {
            margin: 0;

<script type="text/javascript">

function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;

var __Player;
var map;
var xx;
var mainState = {

    preload: function(){

    game.load.tilemap('level', 'auxassets/level2', null, Phaser.Tilemap.TILED_JSON);
    game.load.image('forest_tiles_image', 'forest_tiles.png');
    game.load.image('tiles', 'terrain_atlas.png');
    game.load.image('player', '/auxassets/cahracter.png');
    game.load.spritesheet('character', 'rpg_sprite_walk.png', 24, 32, 32);


    create: function(){

        map = game.add.tilemap('level');

        map.addTilesetImage('grass', 'tiles');

        layer = map.createLayer('grass');
        xx = map.createLayer('obstacles');

        game.physics.p2.convertTilemap(map, xx);

        __Player = game.add.sprite(100,1700,'character');


        cursors = this.input.keyboard.createCursorKeys();


    update: function(){

            __Player.body.y -= 5;
            __Player.animations.play('walk_up', 20);
         if (cursors.down.isDown){
           __Player.body.y += 5;
           __Player.animations.play('walk_down', 20);

        if (cursors.left.isDown){
           __Player.animations.play('walk_left', 20);

         __Player.body.x -= 5;
        if (cursors.right.isDown){
            __Player.animations.play('walk_right', 20);
             __Player.body.x += 5;

render: function() {

        // game.debug.cameraInfo(game.camera, 32, 32);


var game = new Phaser.Game(800,600);
game.state.add('main', mainState);






Link to comment
Share on other sites

  • 1 month later...

  • Recently Browsing   0 members

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