Drawing sprites on screen

DrKane
Unregistered
 
Post: #1
I'm in the middle of working on my sprites for my rpg engine. I track all entites using fine coordinates(although movements are restricted on a tile grid). My game displays 11 x 11 tiles at a time on the screen(they're offset slightly for scrolling). I've been trying to figure out how to determine where on the screen to draw my enemy sprite. Here's an example of what I've been trying wihtout much success:

Code:
void MoveSprite()
{
     Point enemyPoint = GetEnemyPoint();

     // code.....

     SetRect(&sprite->destScreenRect, enemyPoint.h - (5 * kTileSizeH), enemyPoint.v - (5 * kTileSizeV),
                                                            enemyPoint.h + (5 * kTileSizeH), enemyPoint.v + (5 * kTileSizeH);
}


Point GetEnemyPoint()
{
      Point world, screen;

for (world.h = player.position.h - (6 * 32), screen.h = 0; world.h < ( (player.position.h + 32) + (6 * 32), screen.h < (13 * 32) ); world.h++, screen.h++)
{
        for (screen.v = player.position.v - (6 * 32), screen.v = 0; world.v < ( (player.position.v + 32) + (6 * 32), screen.v < (13 * 32) ); world.v++, screen.v++)
        {
                 if ( (h == world.h) && (v == world.v) )
                 {
                         return screen;
                 }
         }
    }

}


My player sprite works fine I just can't figure out how to practically determine where on the screen to draw the enemy relative to the player's coords. Any suggestions?
Quote this message in a reply
Moderator
Posts: 335
Joined: 2002.04
Post: #2
Have all your co-ordinates relative to the map and have view_x/y variables tracking where you're looking at on the map.

then all sprites (including the player) find out their screen co-ords by my_x - view_x and my_y - view_y . You can quickly check the results to see if they're in the screen bounds and if so, draw them.

The advantages of this are that all entities can easily check distances from each other and you can have 'cut scene' or remote cameras looking at anywhere on the map, rather than being limited to the player's area.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Cocoa/OpenGL drawing full-screen problem ultitech 5 8,361 Jan 13, 2011 01:11 PM
Last Post: SethWillits