Jump to content

Sprite colliding with the Game Phaser


Demtoo
 Share

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

Link to comment
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...
 Share

  • Recently Browsing   0 members

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