Documentation

Tutorial: Moving Entity

Entities can be attach to added to any Display Object. This allow the following example code to be attach to any Object, be Sprite, Text or a Shape, and have it move due to the player's input.

Example Code


/* Initialise Two Fixed variables to hold position */
new Fixed:x = 0.00;
new Fixed:y = 0.00;
new Fixed:z = 0.00;

/* Display Object variable */
new obj = -1;

/* We want to get the position on entity start up, so we use the Init function */
public Init(...)
{
    /* We want to store, position for current entity to x, y variables. A empty sting access current entity, other wise you could use a entity ID to get it's position  */
    EntityGetPosition(x, y, z, SELF);
    obj = EntityGetNumber("object-id", SELF);
}


main()
{
    /* Get Player 1 Axis Values and add them to the entity positions */
    x += InputAxis(0)* GameFrame2();
    y += InputAxis(1)* GameFrame2();

    ObjectPosition(obj, fround(x), fround(y), 1, 0, 0);
}

Comments

Comming Soon