-
Notifications
You must be signed in to change notification settings - Fork 0
Use Physic on Scene
Radomiej edited this page Jan 27, 2017
·
6 revisions
Javity Physic based on Box2D. You can easy create physic GameObject and handle collision or trigger events. This is example scene:
public class Scene0Bulider implements SceneBulider {
@Override
public void buildScene(Scene scene) {
JGameObject polygonPhysicObject = scene.instantiateGameObject(new Vector2(200, 280));
polygonPhysicObject.addComponent(new SpriteRenderer("atlas/images.atlas#babel"));
polygonPhysicObject.addComponent(new Rigidbody());
polygonPhysicObject.addComponent(new PolygonCollider(new Vector2(-50, -50), new Vector2(-25, 50),new Vector2(0, 50),new Vector2(25, 0),new Vector2(50, -50), new Vector2(-50, -50)));
JGameObject circlePhysicObject = scene.instantiateGameObject(new Vector2(100, 200));
circlePhysicObject.addComponent(new SpriteRenderer("atlas/images.atlas#babel"));
circlePhysicObject.addComponent(new Rigidbody());
circlePhysicObject.addComponent(new CircleCollider());
// logo.addComponent(new ChangeScene());
JGameObject rectamgPhysicObject = scene.instantiateGameObject(new Vector2(50, 250));
rectamgPhysicObject.addComponent(new SpineRenderer("atlas/images.atlas#babel"));
rectamgPhysicObject.addComponent(new Rigidbody());
rectamgPhysicObject.addComponent(new RectangleCollider());
}
}When you create Physic GameObject you must add:
- Rigidbody component
- any Collider component like RectangleCollider/CircleCollider/PolygonCollider.