[Solved] Collision problem
-
I try to port some simple code from flixel and got problem, my Player start jumping on platform without reason(?) and i cant understand why this happens. Looks like he bounced back, but only in the exact place. Please help, and excuse my english.
here is the code
package; import flixel.FlxG; import flixel.FlxSprite; import flixel.FlxState; import flixel.tile.FlxTilemap; import flixel.text.FlxText; import flixel.ui.FlxButton; import flixel.math.FlxMath; class MenuState extends FlxState { private var thePlayer:FlxSprite; private var simpleTilemap:FlxTilemap; override public function create():Void { super.create(); FlxG.worldBounds.set(0, 0, 800, 600); FlxG.worldDivisions = 8; FlxG.camera.bgColor = 0xff646A7D; FlxG.camera.zoom = 3; //Tilemap settings simpleTilemap = new FlxTilemap(); simpleTilemap.loadMapFromCSV ("assets/simpleMap.csv", "assets/images/tiles.png", 16, 16, AUTO); thePlayer = new FlxSprite(36, 150); thePlayer.makeGraphic(20, 20, 0xFFFF0000); thePlayer.drag.x = thePlayer.maxVelocity.x * 4; thePlayer.acceleration.y = 300; thePlayer.maxVelocity.set(120, 300); add(thePlayer); add(simpleTilemap); } override public function update(elapsed:Float):Void { super.update(elapsed); FlxG.camera.follow(thePlayer, PLATFORMER); thePlayer.acceleration.x = 0; if(FlxG.keys.anyPressed([LEFT, A])) { thePlayer.flipX = true; thePlayer.acceleration.x -= thePlayer.drag.x; } else if(FlxG.keys.anyPressed([RIGHT, D])) { thePlayer.flipX = false; thePlayer.acceleration.x += thePlayer.drag.x; } if (FlxG.keys.anyPressed([UP, W]) && thePlayer.velocity.y == 5) { thePlayer.y -= 1; thePlayer.velocity.y = -200; } FlxG.collide(thePlayer, simpleTilemap); FlxG.log.advanced(thePlayer.velocity.y); } }
-
You can fix the double jump by replacing
FlxG.keys.anyPressed([UP, W])
toFlxG.keys.anyJustPressed([UP, W])
. That was the only bug that I seen.
-
@galoyo said in Collision problem:
FlxG.keys.anyJustPressed([UP, W])
Thank you, but double jump is not realy problem. My sprite shaking on 1 pixel up and down. I made gif to show
-
I see nothing unusual produced from the code you given. Maybe this thread would help.
-
@DleanJeans Thank you, i actually find the solution 2 minutes ago, and it also has in thread. I swap the variables for collide()
FlxG.collide(thePlayer, simpleTilemap);
to
FlxG.collide(simpleTilemap, thePlayer);
-
What is your window size and resolution?