icetimux

Members
  • Content count

    7
  • Joined

  • Last visited

  1. Hi everyone. I have experience with phaser making small arcade like games. But I now want to make a larger platformer with worlds. I cant figure out how to organise my code for each world and how to switch between worlds. Can anyone provide me with some guidance on how I can do this?
  2. plugin

    I remember I tried this plugin a few days ago. Does it works now if I use a tilemap with 16px x 16px little tiles? I remember it used to only work with the 32px phaser sample.
  3. Works beautifully! thanks for answering. Can you elaborate a little on what it does?
  4. Hi, Im making a platformer in Phaser and have successfully loaded a tilemap but my player doesn't collide with the tilemap layer. Here's my code. var game = new Phaser.Game(304, 208, Phaser.AUTO, 'game', { preload: preload, create: create, update: update, render: render}); function preload() { this.game.load.atlas('player', 'assets/player/player_full.png', 'assets/player/player_full.json'); game.load.image('bg', 'assets/bg-LONG.jpg'); // TILEMAP game.load.tilemap('world', 'assets/tilemaps/world.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('world_tiles', 'assets/tilemaps/world.png'); } var player; var facing = 'right'; var map; var tileset; var layer; function create() { // START PHYSICS game.physics.startSystem(Phaser.Physics.ARCADE); // ADD SPRITES game.add.tileSprite(0, 0, 900, 200, 'bg'); game.world.setBounds(0, 0, 900, 200); // PLAYER player = game.add.sprite(10, 176, 'player'); player.animations.add('idle_right', ['idle_1_right.png', 'idle_1_right.png', 'idle_2_right.png', 'idle_3_right.png'], 4, true); player.animations.add('running_right', ['running_1_right.png', 'running_2_right.png', 'running_3_right.png', 'running_4_right.png', 'running_5_right.png', 'running_6_right.png'], 9.5, true); player.animations.add('idle_left', ['idle_1_left.png', 'idle_1_left.png', 'idle_2_left.png', 'idle_3_left.png'], 4, true); player.animations.add('running_left', ['running_1_left.png', 'running_2_left.png', 'running_3_left.png', 'running_4_left.png', 'running_5_left.png', 'running_6_left.png'], 9.5, true); player.animations.add('jump_right', ['jump_1_right.png', 'jump_2_right.png', 'jump_3_right.png', 'jump_4_right.png', 'jump_5_right.png', 'jump_6_right.png'], 7, true); player.animations.add('jump_left', ['jump_1_left.png', 'jump_2_left.png', 'jump_3_left.png', 'jump_4_left.png', 'jump_5_left.png'], 7, true); // WORLD game.physics.arcade.gravity.y = 600; game.physics.enable(player, Phaser.Physics.ARCADE); player.body.collideWorldBounds = true; player.body.height = 24; // OTHER game.camera.follow(player); // TILEMAP map = game.add.tilemap('world'); map.addTilesetImage('world', 'world_tiles'); layer = map.createLayer('Tile Layer 1'); layer.resizeWorld(); } function update() { player.body.velocity.x = 0; game.physics.arcade.collide(player, layer); if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { facing = 'right'; player.body.velocity.x = 90; player.animations.play('running_right'); }else if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { facing = 'left'; player.body.velocity.x = -90; player.animations.play('running_left'); } if (game.input.keyboard.isDown(Phaser.Keyboard.UP) && player.body.onFloor() && game.input.keyboard.addKey(Phaser.Keyboard.UP).downDuration(1)) { if (facing == 'right') { player.animations.play('jump_right'); player.body.velocity.y = -230; }else{ player.animations.play('jump_left'); player.body.velocity.y = -230; } } if (player.body.velocity.x == 0 && player.body.onFloor() && player.body.velocity.y == 0) { if (facing == 'right') { player.animations.play('idle_right'); }else{ player.animations.play('idle_left'); } } } function render(){ game.debug.spriteInfo(player, 10, 20); }
  5. UPDATE: setting the sprite body.height allows me to collide correctly. Is there a way to automatically get the sprite height?
  6. Hello, I am trying to make a platformer and have loaded my sprite with atlas, it works perfectly until I add collision. to keep the example simple I am using collideWorldBounds and the problem is that the sprite is colliding in the center and not the bottom where the little feet are. here are some screenshots and code snippets. var game = new Phaser.Game(300, 200, Phaser.AUTO, 'game', { preload: preload, create: create, update: update, render: render}); function preload() { this.game.load.atlas('player', 'assets/player/player_full.png', 'assets/player/player_full.json'); game.load.image('bg', 'assets/bg.jpg'); game.load.image('ground', 'assets/world/ground.png'); } var player; var facing = 'right'; function create() { // START game.physics.startSystem(Phaser.Physics.ARCADE); // ADD SPRITES game.add.image(0, 0, 'bg'); game.stage.backgroundColor = "#4488AA"; // PLAYER player = game.add.sprite(10, 176, 'player'); game.physics.enable(player, Phaser.Physics.ARCADE); player.animations.add('idle_right', ['idle_1_right.png', 'idle_1_right.png', 'idle_2_right.png', 'idle_3_right.png'], 4, true); player.animations.add('running_right', ['running_1_right.png', 'running_2_right.png', 'running_3_right.png', 'running_4_right.png', 'running_5_right.png', 'running_6_right.png'], 9.5, true); player.animations.add('idle_left', ['idle_1_left.png', 'idle_1_left.png', 'idle_2_left.png', 'idle_3_left.png'], 4, true); player.animations.add('running_left', ['running_1_left.png', 'running_2_left.png', 'running_3_left.png', 'running_4_left.png', 'running_5_left.png', 'running_6_left.png'], 9.5, true); player.animations.add('jump_right', ['jump_1_right.png', 'jump_2_right.png', 'jump_3_right.png', 'jump_3_right.png', 'jump_4_right.png', 'jump_5_right.png', 'jump_6_right.png'], 11, true); player.animations.add('jump_left', ['jump_1_left.png', 'jump_2_left.png', 'jump_3_left.png', 'jump_3_left.png', 'jump_4_left.png', 'jump_5_left.png', 'jump_6_left.png'], 11, true); player.animations.play('idle'); // WORLD game.physics.arcade.gravity.y = 250; game.physics.enable(player, Phaser.Physics.ARCADE); player.body.collideWorldBounds = true; } function update() { player.body.velocity.x = 0; if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { facing = 'right'; player.body.velocity.x = 90; player.animations.play('running_right'); }else if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { facing = 'left'; player.body.velocity.x = -90; player.animations.play('running_left'); }else if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { if (facing == 'right') { player.animations.play('jump_right'); }else{ player.animations.play('jump_left'); } }else{ if (facing == 'right') { player.animations.play('idle_right'); }else{ player.animations.play('idle_left'); } } }