Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Tiles and performance

Author
Message
Krisacz
15
Years of Service
User Offline
Joined: 3rd Mar 2009
Location: UK, Manchester
Posted: 15th May 2009 11:11
Hi everyone,
Together with my friend we making title-based game. We will probably store maps data in external files and loading them to arrays like that:



As you can see there will be 1000 sprites of tiles at one time on screen, because we are using 1280 x 800 resolution (tile size 32x32, 1280/32 = 40, 800/32 = 25, 40x25 = 1000). Obviously will manage all not visible sprites so always on screen will be no more than 1000 + some for gui etc.
Problem is that when I loading them (these 1000 sprites) on a screen FPS drops down from 60 to 27-30! I know that's a lot of sprites at one time, so is there a way (routine) to do it different?
We using PNG file format for tiles, and we building these maps in external map editor. I tried using less sprite and I didn't have any problems up to about 600-650 sprite at once, above that FPS significally going down. Can I get some advise from experienced programmers in that area? Thanks!
Scottie Dog
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location:
Posted: 15th May 2009 15:53 Edited at: 15th May 2009 16:06
Are you clearing the whole screen each frame.
Does every tile change each frame

Have a look at the dbPasteSprite command.
This along with setting a work screen means that you can draw/redraw only the bits of your screen that are changing....

for example say we are scrolling the whole screen down 6 pixels and only want to draw the new top row:
Scottie Dog
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location:
Posted: 15th May 2009 16:01
Following on from the above.

Dont forget to hide the sprite you are using
dbHideSprite(x);

Using sprites this way means that you can still use diffusion and alpha values...

If you dont want to do anything clever.. Do you need to use it as a sprite, instead you can just skip straight to dbPasteImage.

dbPasteImage(Image, x, y) will paste an image without transparency,
dbPasteImage(Image, x, y, 1) will treat black as transparent so anything underneath is seen through the image...
Theres a small performance hit for using transparent, but its nothing compared to the performance hit of using a sprite in the first place.

Play with the commands, you should be able to get used to have your background draw as images, whilst your foreground is draw with sprites...
Krisacz
15
Years of Service
User Offline
Joined: 3rd Mar 2009
Location: UK, Manchester
Posted: 15th May 2009 16:06
And about your questions:
Before main loop I've loaded whole screen (double loop, X & Y) and then if player is moving I re-draw all visible sprites with new positions.

Thanks for example, I will try that and I will post results.
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 19th May 2009 16:15
Case dependent, images can be faster. If you need to redraw your field of view every frame, sprites are seriously advantageous. If you can live with most of it being static until interacted with, images will be much better. What sort of tile game is this? It seems every one has been assuming it's a sort of RPG.


My site, for various stuff that I make.
Krisacz
15
Years of Service
User Offline
Joined: 3rd Mar 2009
Location: UK, Manchester
Posted: 20th May 2009 12:24
Yeah it's mix of games like Heroes of Might&Magic, Puzzle Quest and RPG with huge word, quests, crafting etc.

BTW I tried couple of ways to do it and the best which worked for me is dbPasteImage, it's fast and doesn't slow my program even up to 2000 images. So now I have 4 layers:
1st Ground like grass, water, snow etc. - made by dbPasteImage
2nd Trees, mountains, rocks etc - also made by dbPasteImage
3rd Hero, npc's, buildings, and other active objects - dbSprite
4th GUI and everything above - dbSprtie

Because of that we are not limited of map size, even huge map like 10 screen on 16 (12 800 px on 12 800 px) in a file will take only 400-500 Kb(which is nothing compare to previous solution, don't even ask ).

Map itself is stored in vector of vectors in map editor and it's saved to txt file. Other txt will be 2nd layer, next txt will be collisions, and txt for objects etc.

Login to post a reply

Server time is: 2024-10-01 01:25:33
Your offset time is: 2024-10-01 01:25:33