Wiki

Clone wiki

agtools / Tutorial 4d - Entities in Local Coordinates #1

Outline

ts4d.png

This step is a minor change to restore our screenspace tracking effect.

The Tick Function

This just re-applies our original (hacky) solution, using some global variables. The entity rectangle position is compensated with the change in world scroll coordinates.

void letter_fntick(entity_t *_pself)
{
    // move each entity according to its own individually configured velocity/direction
    // this time incorporate the scroll as well

    _pself->rx += _pself->vx - g_viewport_changeinx;
    _pself->ry += _pself->vy - g_viewport_changeiny;
}

Summary

The result should show the same exploding text, but apparently fixed in 'screenspace' instead of worldspace.

However this approach isn't too nice. Apart from confusing arithmetic needing scattered among AI code, it's only tolerable providing we can always work in terms of changes or deltas to the entity position. If we have to assign a new absolute position or switch between the two spaces, it starts to get ugly - fast.

We'll now look at a different way to do this which keeps thing simple as the game program gets more complex. Better still, it continues to work for spaces other than 'screenspace'.

Updated