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;
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185
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);
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
EVAS_API 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:2024
EVAS_API void evas_object_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
Move the given Evas object to the given location inside its canvas' viewport.
Definition: evas_object_main.c:1171
EVAS_API Evas * evas_object_evas_get(const Eo *eo_obj)
Get the Evas to which this object belongs to.
Definition: evas_object_main.c:2662
EVAS_API void evas_object_text_text_set(Eo *obj, const char *text)
Sets the text string to be displayed by the given text object.
Definition: evas_object_text.c:2356
EVAS_API void evas_object_text_font_set(Eo *obj, const char *font, Evas_Font_Size size)
Set the font family or filename, and size on a given text object.
Definition: evas_object_text.c:2340
EVAS_API Evas_Object * evas_object_text_add(Evas *e)
Creates a new text object on the provided canvas.
Definition: evas_object_text.c:366

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);
EAPI EPhysics_Body * ephysics_body_box_add(EPhysics_World *world)
Create a new box physics body.
ephysics_body_geometry_set(text_body, x, y, -15, w * 5 / 6, 46, 30);
ephysics_body_friction_set(text_body, 0.1);
EAPI void ephysics_body_restitution_set(EPhysics_Body *body, double restitution)
Set body's coefficient of restitution.
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.
EAPI void ephysics_body_friction_set(EPhysics_Body *body, double friction)
Set body's friction.

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.

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.
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition: eina_types.h:533

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