- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

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);
evas_object_show(text);

# 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_restitution_set(text_body, 0.95);
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.

ephysics_body_evas_object_set(text_body, text, EINA_FALSE);

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