123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|686|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Concept/Design -> Drawing NPCs on scrolling tilemap

Tue, 27 Jan 2009, 13:33
Afr0
I'm making an RPG.
I have a scrolling tilemap. The 'engine' I'm using has functions for converting screen-coordinates to and from tile-positions.
Now, the problem is as follows;
If my map is larger than the combined size (width and height) of the screen, how do I draw the NPCs? I can't draw them outside of the actual screencoordinates, because then they will never display!
I'm guessing I'll need some kind of function or algorithm for calculating when the player is within a given section of the scrolling tilemap.
Any ideas?

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Tue, 27 Jan 2009, 13:51
blanko1324
I always - not saying this is probably the best way - kept track of the coordinates of the top-left corner of the tile map. Then, I set the NPC's location in relation to those coordinates.

For example, a NPC with coordinates 500,500, would really be (map_x + 500, map_y + 500). This way, the NPC's would move with the map.

Then, using that, if the true NPC coordinates were on-screen, I'd draw them.

-=-=-
My Twitter
Tue, 27 Jan 2009, 14:59
Jayenkai
Yeah, and then only draw

If mapx+SpriteX=>-SpriteWidth and mapx+SpriteX<=ScreenWidth and mapy+SpriteY=>-SpriteHeight and mapy+SpriteY<=ScreenHeight

So that you only draw when the sprite's area is visible within the screen area.

|edit| Make sure that you check the sprite width, as above, so you don't get that annoying thing where the left of a sprite is off the left of the screen, so the whole damn sprite vanishes! |edit|

-=-=-
''Load, Next List!''
Tue, 27 Jan 2009, 19:53
JL235

There is one problem with this, some things you draw don't have a specific width/height. Like if your drawing lots of particles randomly around the NPC, you'll need to take into account where they are in relation to the NPC and how big the particles images are. This is then more difficult if they are independant objects of their own with no set width/height.