EzDevInfo.com

box2d.js

Port of Box2D to JavaScript using Emscripten

Cocos2d + Box2d or Chipmunk [closed]

OK, im trying to make an iphone version of a game i made here http://scratch.mit.edu/projects/techy/781198 is box2d or chipmunk better and where are some tutorials for each one


Source: (StackOverflow)

Which Box2D JavaScript library should I use?

There are a few different ports of Box2D for JavaScript. Which one is the best?

  • Box2DJS - "converted from Box2DFlashAS3_1.4.3.1 in an automatic manner"

  • Box2Dflash 2.0 ported to JavaScript - "one big nasty hack that just happens to work"

  • box2dweb - "a port of Box2DFlash 2.1a to JavaScript. I developed an ActionScript 3 -to- JavaScript converter to generate the code"

  • HBehrens/box2d.js - "a JavaScript Version of Box2D 2.1a" (Added Nov 21, 2011)

  • kripken/box2d.js - "a direct port of the Box2D 2D physics engine to JavaScript, using Emscripten" (Added Sep 24, 2013)

Any ideas which version http://chrome.angrybirds.com/ uses, if any?


Source: (StackOverflow)

Advertisements

How to detect collision but do not collide in box2d?

How to detect if body collides other body but do not react on this collision.

By default i - detect collision and bodies collide.

If i set fixtureDef filter - bodies do not collide but i can not detect collision.

Help please!


Source: (StackOverflow)

How to stop the forces acting on a body in box2d

I am using box2d on the iphone to create a game. I have a body that is effected by gravity to move down and not right or left. It will get hit by another body and will then be moving right or left. I then have a reset button which moves the body back to its starting point. The only problem is that it is still moving right or left. How can I counteract the forces that a ball is already traveling? How can I get rid of this right and left movement when I reset my game?


Source: (StackOverflow)

Guide for Cocos2d and Box2d on iphone? [closed]

I'm new to the world of game programming but wanted to build a simple physics-based game for the iPhone. Does anyone know of any tutorials for Cocos2D and/or Box2D on the iPhone? The documentation is kind of confusing.


Source: (StackOverflow)

Move body to a specific position - Box2D

I have a b2Body which I would like to move at a certain target position. I don't want to use the SetPosition function. How can I achieve this using :

  1. Changing linear velocities.
  2. Using mouseJoint. (The target position is fixed. Mouse is NOT involved.)

I'm using Box2DAS3 2.1a. Help in any other language would also be appreciated.


Source: (StackOverflow)

Proper Swipe gesture recognizer iOS

I haven't been able to find a tutorial on how to properly setup a gesture recognizer for iOS. I need to detect swipe up & down, and the callbacks for them.

Any help, appreciated. Thanks.


Source: (StackOverflow)

Applying physics to Android View objects

I currently have an android application that utilises the native android views for the UI (e.g. imageviews/buttons etc)

Although this app is not a game, nor requires any heavy graphics or OpenGL, I would like to incorporate a little physics-related interaction. Nothing too significant but maybe display minor collisions/bounces, deceleration/acceleration or possibly friction.

Is this possible to simulate either within the android framework or using an external physics library like jbox2d without having to utilize an entire game engine (like andengine, libgx etc).

P.S. this is for API 15+

Thanks all.


Source: (StackOverflow)

Why use Float.floatToIntBits() in Java float comparisons?

In JBox2d, there exists the following code for Vec2.equals():

@Override
public boolean equals(Object obj) { //automatically generated by Eclipse
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    Vec2 other = (Vec2) obj;
    if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x))
        return false;
    if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y))
        return false;
    return true;
}

I am wondering what purpose the float<->int bit conversions functions serve, here. Does this provide a way to get around Java's float comparison inaccuracy problem (if such is even possible)? Or is it something else altogether? I am wondering if it is an alternative to the epsilon approach:

if (Math.abs(floatVal1 - floatVal2) < epsilon)

PS. for the sake of completeness and interest, here is Vec2.hashCode():

@Override
public int hashCode() { //automatically generated by Eclipse
    final int prime = 31;
    int result = 1;
    result = prime * result + Float.floatToIntBits(x);
    result = prime * result + Float.floatToIntBits(y);
    return result;
}

FYI, I can see perfectly why the conversion functions are used in hashCode() -- hash IDs must be integers.


Source: (StackOverflow)

calculate distance in CGpoint between two CGPoint

i need to calculate distance in CGPoint between given two point(CGPoint)

i refer this and this

but i dont know how to get distance in CGPoint.

so if any one knows Please help.

Thanks.


Source: (StackOverflow)

iPhone physics engine for fluid/water simulation? [closed]

I'm about to start developing a game that's main feature revolves around 2D water simulation. I have thought about starting with Box2D and designing water in that engine, but I'm not sure if it would be efficient, and I don't have any experience with Box2D.

It would be great if there was an engine with good fluid simulation built in. If not, where should I start? I have been searching around for a while and still don't really have a good place to begin.

The water is only going to take up at most 10% of the screen at a time, and my goal is 40 FPS on the 3GS and 45+ on the iPhone 4. Just rough numbers.


Source: (StackOverflow)

Javascript physics engine and simulated infinite curve

I'm trying to do a Tiny Wings like in javascript.

I first saw a technique using Box2D, I'm using the closure-web version (because of the memory leaks fix).
In short, I explode the curve into polygons so it looks like that:

enter image description here

I also tried with Chipmunk-js and I use the segment shape to simulate my ground like that:

enter image description here

In both cases, I'm experiencing some "crashes" or "bumps" at the common points between polygons or segments when a circle is rolling.

I asked about it for Chipmunk and the author said he implemented a radius property for the segment to reduce this behavior. I tried and it indeed did the trick but it's not perfect. I still have some bumps(I had to set to 30px of radius to get a positive effect).

The "bumps" append at the shared points between two polygons :

bump bug

Using, as illandril suggested to me, the edging technique (he only tested with polygon-polygon contact) to avoid the circle to crash on an edge:

slope edging technique

Also tried to add the bullet option as Luc suggested and nothing seems to change.

Here the demo of the issue.
You can try to change the value to check :

  • bullet option
  • edge size
  • iterations count
  • the physics

(only tested on latest dev Chrome)
Be patient (or change the horizontal gravity) and you'll see what I mean.
Here the repo for the interested.


Source: (StackOverflow)

Box2d: mousejoint without inertial delay

I'm using mousejoint to drag bodies in box2d, but it causes inertial delay.

Does it exist any way to drag a body instantaneously?


Source: (StackOverflow)

When to use ShapeRenderer, Mesh + SpriteBatch, Box2D and Scene2D in Libgdx?

I'm new in Android Game Development and after I started with libgdx ShapeRenderer and did a little more search, I became confused if I started with the right foot.

So, what I really would like to know is when should I use ShapeRenderer, Mesh + SpriteBatch, Box2D and Scene2D.


Source: (StackOverflow)

X velocity slowing down when applying Y Linear Impulse with Box2D

I'm using libgdx and box2d as my physics engine. Right now I just have a very simple box being controlled on a single flat surface:

enter image description here

Everything seems to be working well. I control the box with the arrow keys. If I press the right arrow the box will accelerate to the right. When I press the up arrow, the box will jump. Something that was unexpected though was that when the box jumps, it's x velocity slows down. Can anyone tell me why that is and how to fix it?

Player Object with just some Box2d setup:

public class Player extends Entity {
  private static BodyDef createBodyDef() {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.fixedRotation = true;
    bodyDef.position.set(100, 200);
    return bodyDef;
  }

  public Player(World world) {
    super(world, createBodyDef(), Textures.rectangle(Units.m2P(0.7f), Units.m2P(2f), Color.RED));
    FixtureDef fixtureDef = new FixtureDef();
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(50, 50, new Vector2(50, 50), 0f);
    fixtureDef.shape = shape;
    fixtureDef.friction = 0.1f;
    getBody().createFixture(fixtureDef);
    MassData massData = new MassData();
    massData.mass = 90f;
    getBody().setMassData(massData);
  }
}

The Game Screen:

public class GameScreen extends BaseScreen implements InputProcessor {
  private final World world = new World(new Vector2(0, -200), false);
  private final GameView view = new GameView();
  private final List<Entity> entities = new ArrayList<Entity>();
  private final Player player = new Player(world);
  private final List<Integer> pressedKeys = new ArrayList<Integer>();

  public GameScreen() {
    entities.add(player);
    view.setFollowEntity(player);
    MapBodyBuilder.buildShapes(view.getTiledMap(), 1, world);
  }

  @Override public void show() {
    super.show();
    Gdx.input.setInputProcessor(this);
  }

  @Override public void render(float delta) {
    super.render(delta);

    float forceX = 0f;
    float forceY = 0f;
    float force = 15000;
    if (pressedKeys.contains(Input.Keys.LEFT)) {
      forceX -= force;
    }
    if (pressedKeys.contains(Input.Keys.RIGHT)) {
      forceX += force;
    }
    if (pressedKeys.contains(Input.Keys.DOWN)) {
      forceY -= force;
    }

    player.getBody().applyForceToCenter(forceX, forceY, false);

    world.step(delta, 5, 5);
    view.render(entities);
  }

  @Override public void resize(int width, int height) {
    super.resize(width, height);
  }

  @Override public void hide() {
    super.hide();
    Gdx.input.setInputProcessor(null);
  }

  @Override public void dispose() {
    super.dispose();
    world.dispose();
    for (Entity entity : entities) {
      entity.dispose();
    }
  }

  @Override public boolean keyDown(int keycode) {
    if (keycode == Input.Keys.UP) {
      Body body = player.getBody();
      body.applyLinearImpulse(new Vector2(0, 30000), body.getWorldCenter(), true);
    }

    pressedKeys.add(keycode);
    return false;
  }

  @Override public boolean keyUp(int keycode) {
    pressedKeys.remove((Integer) keycode);
    return false;
  }

  @Override public boolean keyTyped(char character) {
    return false;
  }

  @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    return false;
  }

  @Override public boolean touchUp(int screenX, int screenY, int pointer, int button) {
    return false;
  }

  @Override public boolean touchDragged(int screenX, int screenY, int pointer) {
    return false;
  }

  @Override public boolean mouseMoved(int screenX, int screenY) {
    return false;
  }

  @Override public boolean scrolled(int amount) {
    return false;
  }

  public Player getPlayer() {
    return player;
  }
}

Source: (StackOverflow)