So i have sprites that are should be un-walkable for my character.
The problem is im not sure how to do this.
Here is what i am trying. I am having the sprites added to a Linked List when they are loaded from the level.
Then i iterate through the list to detect if the character is colliding with any of the unwalkable sprites/tiles.
I do this on the engines update thread which runs about every second.
Here is how i am doing this:
mScene.registerUpdateHandler(new IUpdateHandler(){
@Override
public void onUpdate(float pSecondsElapsed) {
Iterator<Sprite> wall_collision = unwalkable_Sprites.iterator();
while(wall_collision.hasNext()){
Sprite sprite = wall_collision.next();
if(character_sprite.collidesWith(sprite)){
}
}
}
@Override
public void reset() {
// TODO Auto-generated method stub
}
});
So the question is how do i position the character when it collides with the unwalkable tile so the character doesnt even cross over into the tile..To the user it should seem like a boundary.
Does anyone have any suggestions or know how i can do this?
Look into this example
use the same code for you un-walkable tiles as “ground” in example. You should use static bodies:
Here you can use Shape as in example or for example Sprite
//final Shape yourTile = new Rectangle(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH, 2);Sprite yourTile = new Sprite(...);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, yourTile, BodyType.StaticBody, wallFixtureDef);
Here you can find box2dExtension for AndEngine (it need for using Bodies)
Sorry for my English 🙂 Hope this will help you.
P.S. and you don’t need to check collisions for this issue anymore.