Author Topic: Help! Using Flixel-GDX + Flixel-GDX-Box2D  (Read 1805 times)

sheep42

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Help! Using Flixel-GDX + Flixel-GDX-Box2D
« on: Sun, Nov 30, 2014 »
Hey Folks,

I'm a new poster to the forum, but I've been using Flixel for a while and I made the switch to Wing Eraser's awesome Flixel-GDX port recently when I discovered it. I've been working on a game and I realized recently that I need to use box2d. I was hoping to get Box2d going using the box2d port located here: https://github.com/flixel-gdx/flixel-gdx-box2d

Unfortunately, there is not a whole lot of documentation for that specific box2d port and I am a bit stuck. I've written a very simple test to render a box on the screen but I have not been able to get it running.

I've been getting this error message:
Code: [Select]
java.lang.NoSuchMethodError: com.badlogic.gdx.graphics.g2d.Sprite.draw(Lcom/badlogic/gdx/graphics/g2d/SpriteBatch;)V
at org.flxbox2d.collision.shapes.B2FlxShape.draw(B2FlxShape.java:518)

I tracked the issue down to the line where the box is added to the world. But I can't figure out why it's failing. When I comment out add(box.create()); The application will build and run, but the box is (obviously) not created. This error occurs when adding any B2FlxShape objects but when I add a normal FlxSprite everything works as expected. Any ideas?

Here's the code that I've got written so far:
Code: [Select]
import org.flixel.FlxG;
import org.flixel.FlxSprite;
import org.flxbox2d.B2FlxB;
import org.flxbox2d.B2FlxState;
import org.flxbox2d.collision.shapes.B2FlxBox;

import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.World;

/**
 * A parent class for testing.
 *
 * @author Ka Wing Chin
 */
public class PlayState extends B2FlxState{

private World world;

@Override
public void create(){
super.create();

FlxG.mouse.show();

B2FlxB.world.setWarmStarting(true);
B2FlxB.setGravity(0, 9.81f);
FlxG.visualDebug = true;

B2FlxBox box = new B2FlxBox(50, 50, 50, 50);
box.setRestitution(.3f);
    box.setFriction(.2f);
    box.setDensity(.8f);
    box.setDraggable(true);
   
    add(box.create());
}

@Override
public void update(){
super.update();

}

@Override
public void destroy(){
super.destroy();
}
}

Any help is much appreciated. Thanks!
-Dan

Wing Eraser

  • Guest
Re: Help! Using Flixel-GDX + Flixel-GDX-Box2D
« Reply #1 on: Tue, Dec 2, 2014 »
Your code seems fine too me. It runs and it does shows the box.

Code: [Select]
public B2FlxMouseJoint mouse;

@Override
public void create()
{
super.create();

FlxG.mouse.show();

B2FlxB.world.setWarmStarting(true);
B2FlxB.setGravity(0, 9.81f);
FlxG.visualDebug = true;

// Add mouse joint.
add(mouse = new B2FlxMouseJoint());

B2FlxBox box = new B2FlxBox(50, 50, 50, 50);
box.setRestitution(.3f);
box.setFriction(.2f);
box.setDensity(.8f);
box.setDraggable(true);

add(box.create());
}

Do the examples run?

sheep42

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Help! Using Flixel-GDX + Flixel-GDX-Box2D
« Reply #2 on: Tue, Dec 2, 2014 »
Hey Wing,

Thanks for the quick reply. I'm not able to get the examples running either, same issue actually. It's good to know the code should be correct. I built flixel-gdx-box2d as a jar and included it as a library in my project and I'm wondering if maybe something went wrong during that process. I'll see what I can figure out.

Thanks!
-Dan

Wing Eraser

  • Guest
Re: Help! Using Flixel-GDX + Flixel-GDX-Box2D
« Reply #3 on: Tue, Dec 2, 2014 »
Hi there. You don't have to build a jar, because flixel-gdx-box2d is also in the nightly builds: http://jenkins.flixel-gdx.com/compress/

sheep42

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Help! Using Flixel-GDX + Flixel-GDX-Box2D
« Reply #4 on: Wed, Dec 3, 2014 »
Perfect, downloading the box2d jars from the nightly fixed my issue, thanks! Also, thanks for writing an awesome Flixel port!

-Dan