EPhysics - Bouncing Text

The purpose of this example is to demonstrate the EPhysics_Body binding to a text (Evas_Object)

For this example we'll have an EPhysics_World and one basic EPhysics_Body.

The basic concepts like - initializing an EPhysics_World, render geometry, physics limiting boundaries, were already covered in EPhysics - Bouncing Ball

Creating the text

Create a basic evas_object_text.

Evas_Object *text;
text = evas_object_text_add(evas_object_evas_get(test_data->win));
evas_object_text_text_set(text, "EPHYSICS");
evas_object_text_font_set(text, "Sans", 54);
evas_object_color_set(text, 95, 56, 19, 255);
evas_object_move(text, WIDTH / 4, HEIGHT / 8);

Creating the body

Create a simple EPhysics_Body.

Note that we use ephysics_body_geometry_set() to define its size because the evas_object has a different size that we want to represent physically. The text may have accent or letters like j and g.

text_body = ephysics_body_box_add(test_data->world);
ephysics_body_geometry_set(text_body, x, y, -15, w * 5 / 6, 46, 30);
ephysics_body_friction_set(text_body, 0.1);

Binding

After creating the body and the text, now we need to bind them.

We set the last parameter as EINA_FALSE because in this example we don't want to set the physics body position to match evas object position.

Here we finish the example. The full source code can be found at test_bouncing_text.c.

ephysics_body_friction_set
EAPI void ephysics_body_friction_set(EPhysics_Body *body, double friction)
Set body's friction.
ephysics_body_box_add
EAPI EPhysics_Body * ephysics_body_box_add(EPhysics_World *world)
Create a new box physics body.
EINA_FALSE
#define EINA_FALSE
Definition: eina_types.h:502
Evas_Object
Efl_Canvas_Object Evas_Object
Definition: Evas_Common.h:180
evas_object_show
void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1853
evas_object_text_add
Evas_Object * evas_object_text_add(Evas *e)
Creates a new text object on the provided canvas.
Definition: evas_object_text.c:366
ephysics_body_evas_object_set
EAPI void ephysics_body_evas_object_set(EPhysics_Body *body, Evas_Object *evas_obj, Eina_Bool use_obj_pos)
Set an evas object to a physics body.
ephysics_body_geometry_set
EAPI void ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas_Coord z, Evas_Coord w, Evas_Coord h, Evas_Coord d)
Set physics body geometry.
evas_object_color_set
void evas_object_color_set(Evas_Object *obj, int r, int g, int b, int a)
Sets the general/main color of the given Evas object to the given one.
Definition: evas_object_main.c:2063
ephysics_body_restitution_set
EAPI void ephysics_body_restitution_set(EPhysics_Body *body, double restitution)
Set body's coefficient of restitution.