public function collide(player:Player):Bool { var collided = FlxG.pixelPerfectOverlap(player,this);
if (collided) { player.x = player.x - 5*(player.x-player.last.x); player.y = player.y - 5*(player.y-player.last.y); player.velocity.x = 0; player.velocity.y = 0; }
return collided; }
Previous two posters are right, but there's an easier way to do this. In the update method where you're moving the ball, you can add a conditional to check the position of the ball. What you want to do is check it against (I think) FlxG.width and FlxG.height. Those two values are gonna be your bottom and right sides of the screen, and 0, 0 are gonna be the top and left sides of the screen. So you can check the ball's position (minus or plus half the ball's width to check the edge of it instead of the center, if you're so inclined) against those values, depending on which direction it's traveling, and if it exceeds the value then set its velocity to zero.
It might be best to check what the next position of the ball is gonna be before you move it and, if it's less than 0 or greater than height/width, then set it to that value instead.
I have a feeling that this might be easier than I am thinking it is, but figured I'd ask and see if someone could help me. I am trying to stop a ball from moving when it hits a wall. However, I want the wall to be the sides of the screen. What would be the easiest way to do this? Is it just a collision or is it me changing the velocity to 0? should I create a 1 px black rectangle that goes around the screen and test the collision against that?And as a bonus question, any advice on keeping the ball on the wall and creating a pile of balls that stack up on the wall?
--
HaxeFlixel Development Community
See our github https://github.com/haxeflixel/ and our documentation http://haxeflixel.com/documentation/
---
You received this message because you are subscribed to the Google Groups "HaxeFlixel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haxeflixel+...@googlegroups.com.
Visit this group at http://groups.google.com/group/haxeflixel.
To view this discussion on the web visit https://groups.google.com/d/msgid/haxeflixel/b44fbf3e-7217-4233-976d-3f20b49aab5f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.