Jump to content

Sprite and Group of Ground Sprites Collision


srikarg
 Share

Recommended Posts

Hello everyone!

 

After I updated my game to the latest release (1.1.4), I noticed a few issues with the collisions between the player and the ground.

 

My game is set up where there are several ground sprites that are created by parsing a level text file (a ground sprite is added to a group and created on screen whenever a 'g' appears in the text file). My player is just a regular atlas sprite. After I started my game, I found these two bugs:

 

First, my player falls through the ground occasionally (even though the ground is set to immovable) as seen below (it's a GIF):

 

z4PwIck.gif

 

Secondly, my player fails to collide with the side of the ground sprites (even though it can easily walk on top of them) as seen in another GIF below:

 

XtGsAyI.gif

 

Can someone please help me resolve this issue? It has been annoying me for the past few hours...Thanks in advance!

 

Here's my code (written in CoffeeScript):

console.clear()game = platforms = player = cursors = nullpreload = () ->    game.load.image 'sky', 'deploy/art/sky.jpg'    game.load.image 'ground', 'deploy/art/ground.png'    game.load.spritesheet 'coin', 'deploy/art/coin.png'    game.load.atlasXML 'player', 'deploy/art/player.png', 'deploy/art/player.xml', null    game.load.text 'level', 'deploy/level.txt', falsecreate = () ->    game.add.sprite 0, 0, 'sky'    player = game.add.sprite game.world.centerX, game.world.height - 75, 'player'    player.body.bounce.y = 0.1    player.body.gravity.y = 200    player.animations.add 'left', ['left_1.png', 'left_2.png', 'left_3.png', 'left_4.png'], 10, false, false    player.animations.add 'right', ['right_1.png', 'right_2.png', 'right_3.png', 'right_4.png'], 10, false, false    player.animations.add 'idle', ['still.png'], 10, false, false    cursors = game.input.keyboard.createCursorKeys()    platforms = game.add.group()    level = game.cache.getText('level').split '\n'    x = y = 0    for line in level        for character in line.split ''            if character is 'g'                platforms.create x * 32, y * 32, 'ground'            x++        y++        x = 0    platforms.setAll 'body.immovable', trueupdate = () ->    if player.x > game.world.width + player.width        player.x = -player.width    else if player.x < -player.width        player.x = game.world.width + player.width    game.physics.collide player, platforms    player.body.velocity.x = 0    if cursors.up.isDown and player.body.touching.down        player.body.velocity.y = -120    if cursors.left.isDown        player.body.velocity.x = -150        player.animations.play 'left'    else if cursors.right.isDown        player.body.velocity.x = 150        player.animations.play 'right'    else        player.animations.play 'idle'game = new Phaser.Game 800, 640, Phaser.AUTO, '', {    preload: preload    create: create    update: update}

Also, here's level.txt (the text file generator for the level) if it's needed:

..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ggg......ggggggggggggggggggggggggg

Thanks again!

Link to comment
Share on other sites

the 'sinking' issue sounds like a bug in the collision/separation code. i've been seeing some strange behaviours myself. if you have a solid sample of it, submit a bug to github with all the relevant info.

 

the second issue is probably the same as issue #363 - i'm seeing the exact same thing in a side-scroller with two sprites that are standing on the same 'ground' level 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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