Author Topic: Flixel-GDX: Help with Box2D Collision  (Read 1798 times)

sheep42

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Flixel-GDX: Help with Box2D Collision
« on: Sat, Jan 10, 2015 »
Hi All,

I am working on my first original game prototype and I'm struggling a bit. Please feel free to tell me if I'm doing something stupid, I'm here to learn as much as I can and I've only got Google to guide me.

Background info: The game is a 2d, top-down game that involves moving around the screen and avoiding enemies. When I started the game I was using Flixel-GDX on its own and everything was going well, but then I decided that I wanted the enemies to have a field of vision that covers only a certain area in front of them which will trigger the logic that makes them follow the player. After looking into it a bit I thought it would be a good idea to create the field of vision as a polygon and test for a collision with the player. I figured out that I could not create polygons in Flixel, so I set up Box2D which allows for the creation of many types of shapes. After getting that set up, I converted all of my sprites to B2DFlxSprite and now I'm having issues and any help would be awesome.

My Issue:

When I use Flixel collision, I have to cast the B2DFlxSprite to a FlxObject and it's adding 11 pixels to the screen position. This is problematic because I have a sprite which is removed from the screen and later re-drawn and it gets offset by 11px.

When I use Box2d collision, nothing happens. I played with the collision examples a bit and read about how collision is handled in Box2d and I was able to get a working demo running with dragable objects. I think the issue might have something to do with the fact that I'm setting the velocity of my sprites with the FlxSprite functions, but I'm not sure.

Can anyone provide some insight on this? I feel like there's something important that I'm just not getting.
Thanks!

-Dan

Wing Eraser

  • Guest
Re: Flixel-GDX: Help with Box2D Collision
« Reply #1 on: Sun, Jan 11, 2015 »
One thing, don't mix Quadtree (flixel's default collision system) with Box2D. Collision and motions needs to be done with one algorithm.
Another thing is, you can find a lot of information about Box2D on google. Also keep in my mind, FlxBox2D is just a wrapper to simplified things. You can still use the normal way of box2d, but you'll have to handle the rendering yourself.
Be sure to have debug rendering turned on to see the shapes.

sheep42

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Flixel-GDX: Help with Box2D Collision
« Reply #2 on: Sun, Jan 11, 2015 »
One thing, don't mix Quadtree (flixel's default collision system) with Box2D. Collision and motions needs to be done with one algorithm.

So, if I understand you correctly you're saying I should use Box2D for both sprite motion and collision right? Right now I'm using Flixel for motion with Box2D collision and was beginning to suspect that was part of my issue. I have been doing quite a bit of Googling about Box2D, but I'm new to it and there are some things I feel like I haven't quite grasped yet. Thanks for your help!

Wing Eraser

  • Guest
Re: Flixel-GDX: Help with Box2D Collision
« Reply #3 on: Sun, Jan 11, 2015 »
Ah yes. Have you read the manual of Box2D? I wrote everything you need to know before starting using FlxBox2D.

sheep42

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Flixel-GDX: Help with Box2D Collision
« Reply #4 on: Wed, Jan 14, 2015 »
I have read through the docs and I've tried building some samples, but I think I need to spend more time playing with box2d on a smaller scale in order to understand it. On another note I realized the other day that i was so focused on flixel that i forgot about lib-gdx, lib-gdx has polygon support and I'm thinking I might try to do it that way since I have a better grasp on it.