Jump to content



Recommended Posts

Hey guys,


i'm a newbie to phaser and i have had troubles creating obstacles. i am using arcade physics to show a group of bricks that are immovable to which the character can collide with. The following code is creating a brick that is falling along with the character and not staying in place. 

function create() {
    game.time.desiredFps = 30;
    bg = game.add.tileSprite(0, 0, 600, 800, 'background');
    game.physics.arcade.gravity.y = 250;
    player = game.add.sprite(32, 32, 'dude');
    game.physics.enable(player, Phaser.Physics.ARCADE);
    player.body.bounce.y = 0.7;
    player.body.collideWorldBounds = true;
    player.body.setSize(20, 32, 5, 16);
    player.animations.add('left', [0, 1, 2, 3], 10, true);
    player.animations.add('turn', [4], 20, true);
    player.animations.add('right', [5, 6, 7, 8], 10, true);
    bricks = game.add.group();
    bricks.enableBody = true;
    bricks.physicsBodyType = Phaser.Physics.ARCADE;
    var brick;
    brick= bricks.create(400,200,'atari');
    cursors = game.input.keyboard.createCursorKeys();
    jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);

How can you draw a fixed obstacle on the map.

Link to comment
Share on other sites



You can see a good example here of what you are trying to achieve (if I've understood what you want ^^) : http://www.photonstorm.com/phaser/tutorial-making-your-first-phaser-game


Few things are done differently ; for example, the tutorial initializes the gravity on the player whereas you did it on the physics system directly, you specified the physicsBodyType of bricks whereas the tutorial never does it, ...


But honestly, I'm not a Phaser expert and I'm not sure if that even matters :unsure:


Good luck ^^

Link to comment
Share on other sites


  • Recently Browsing   0 members

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