W
W
WannaCreative2017-01-23 18:47:20
JavaScript
WannaCreative, 2017-01-23 18:47:20

[Phaser.js] Why is only one object "solid" and the rest are not?

!!! You can pass through the wall, but if you stand on the top of the wall, then the character does not fall through !!!
Hello!
I created a small scene in Phaser.js and made a collision so that mario is on the platform and can't go through the side ones.
0W79gYZkdXo.jpg
But, unfortunately, it stands only on the main platform, which is from below, below it. And it calmly passes through the side walls, although all these walls are in the same group. What's the problem, I can't figure it out :{
xAkXMOh4v50.jpgCODE

preload: function()
    {
        game.load.image('mario', 'images/mario.png');
        game.load.image('WallH', 'images/wallH.png');
        game.load.image('WallW', 'images/wallW.png');
    },
    
    create: function()
    {
        game.physics.startSystem(Phaser.Physics.ARCADE);
        game.stage.backgroundColor = "3984db";
        game.physics.arcade.gravity.y = 1200;
        this.cursor = game.input.keyboard.createCursorKeys();

        this.mario = game.add.sprite(game.width / 2, game.height / 2, 'mario');
        this.mario.anchor.setTo(0.5,0.5);
        this.mario.scale.setTo(0.15,0.15);
        
        this.walls = game.add.group();
        this.walls.enableBody = true;
        this.walls.enableBody = true;
        
        this.downWallH = game.add.sprite(0, 540, 'WallH', 0, this.walls);
        this.leftWallW = game.add.sprite(0,0, 'WallW', 0, this.walls);
        this.rightWallW = game.add.sprite(822,0, 'WallW', 0, this.walls);
        
        game.physics.arcade.enable(this.mario);
        this.walls.setAll('body.allowGravity', false);
        this.walls.setAll('body.immovable', true);
        
        
    },
...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tooyz, 2017-01-23
@Tooyz

game.physics.arcade.enable(this.walls) if I'm not mistaken.

G
GreatRash, 2017-01-24
@GreatRash

Is it possible to include body after adding the walls to the group, and not before?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question