Ashish

Phaser is not loading the same map created in Tiled software

Recommended Posts

 

I have created a sample map using tiled software. Then tried to load the same u on webpage using phaser.js. But I am not getting the proper result. Is there any mistake in my code or something wrong with library.

<!DOCTYPE html>
<html>
   <head>
      <title>Basic Platformer game</title>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width">
      <script src="js/phaser.min.js"></script>
      <script src="js/phaser.js"></script>
      
   </head>
   <body>
      <div id="phaser-game"></div>
      <script type="text/javascript">
         (function() {

            var game = new Phaser.Game(
            800, 600, Phaser.CANVAS, 'phaser-example', 
            { preload: preload, create: create, update: update, render: render });

            function preload() {
    game.load.tilemap('map', 'background.json', null, Phaser.Tilemap.TILED_JSON);
    game.load.image('tile2', 'floor2.png');
    game.load.image('player','bot2.png');

}

var map;
var layer;
var marker;
var player;
var currentTile;
var cursors;
var curser;


function create() {
    game.stage.backgroundColor = '#787878';    
    game.physics.startSystem(Phaser.Physics.P2JS);

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

    map.addTilesetImage('floor2','tile2');
    currentTile = map.getTile(0, 0);
    layer = map.createLayer('Tile Layer 1');
    

    player = game.add.sprite(20, 20, 'player');
    game.physics.p2.enable(player);
    player.body.fixedRotation = true;

    layer.resizeWorld();
    
    marker = game.add.graphics();
    marker.lineStyle(2, 0x000000, 1);
    marker.drawRect(0, 0, 20, 20);

    cursors = game.input.keyboard.createCursorKeys();    
    game.camera.follow(player, Phaser.Camera.FOLLOW_LOCKON, 0.1, 0.1);
    game.physics.arcade.enable(player);
    

      </script>
   </body>
</html>

 

issue2.PNG

issue1.PNG

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.