Sign in to follow this  
Demtoo

Sprite colliding with the Game Phaser

Recommended Posts

Hi,

I'm currently in the middle of setting up the base of my game with the use of Phaser game engine but I'm having issue with the sprite colliding with the world bounds. 

I've used Tiling to create the backdrop and the ground etc. But I need help understanding how to define what the sprite should be colliding with. How do I collide with the ground, which is part of the whole tile.

Please see the attached 2 images, the sprite falls through the game as expected.

 

 this.world.setBounds(0,0, 400,300);


        
        console.log("in Game screen");
        
        //sprite width - 180px, height 247.5px
        map = this.add.tilemap('level');
        map.addTilesetImage('MyTile', 'tiles');
        layer = map.createLayer('Tile Layer 1');
        console.log("Json and sprite loaded");
        


        sprite = this.add.sprite(this.world.centerX, this.world.centerY, 'character');
        sprite.anchor.setTo(0.5,0.5);
        sprite.scale.setTo(0.2, 0.2);
        console.log("Character Loaded");
        
           this.physics.startSystem(Phaser.Physics.ARCADE);
       this.physics.enable(sprite, Phaser.Physics.ARCADE);
       sprite.body.gravity.y  = 500;
       console.log("Physics added to sprite"); 

The above code is in the create function, I am using state management, as you can see I've added set world bounds, when adding this the sprite dissapears, I've tried numerous different dimension but I've still not come to a solution.

Image1.png.538490075df3412d2bccc35b2a017b0a.pngImage2.png.6660cf064c41006f74b96619c82cd703.png

Any help would be much appreciated.

 

Thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.