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.

2D All the way! / Sprite Speed Issues - DBP

Author
Message
Captain GerBear
19
Years of Service
User Offline
Joined: 9th Jul 2006
Location:
Posted: 31st Jul 2006 17:26
Hey guys. This may or may not be the right place to ask about this, but I was hoping people could give me some general tips for speeding up sprites. I'm using a map made of sprite tiles pieced together, and even when I have less than 200 sprites onscreen, the level of slowdown is very noticible, and I'm running on a mid-high-end machine.

I've already got a routine that deletes sprites as they leave the viewable area, and re-clones them as they re-enter. I've also reduced the color depth of the images the sprites are pulled from, and my sprite priorities are all below 1000 (When I had them around 12000, my program was completely unplayable) Is 200 sprites just too intense? Or is there some trick I should know about?

Thanks in advance.
Richard Davey
Retired Moderator
24
Years of Service
User Offline
Joined: 30th Apr 2002
Location: On the Jupiter Probe
Posted: 31st Jul 2006 17:33
200 sprites of what size? Running at what resolution?

Bite my shiny metal ass
Captain GerBear
19
Years of Service
User Offline
Joined: 9th Jul 2006
Location:
Posted: 31st Jul 2006 17:36
Of course, sorry. My sprites are 120 x 120 pixels, and I'm running the game at 640, 480, 16
Richard Davey
Retired Moderator
24
Years of Service
User Offline
Joined: 30th Apr 2002
Location: On the Jupiter Probe
Posted: 31st Jul 2006 17:48
Just curious, but why are there 200 sprites of 120x120 on a screen only 640x480 in size? I mean at that resolution, even accounting for scrolling, you could cover the screen with far less.

Just a question anyway.

What speed are you running the game at? (sync rate)

Bite my shiny metal ass
Captain GerBear
19
Years of Service
User Offline
Joined: 9th Jul 2006
Location:
Posted: 31st Jul 2006 17:55
The map is constructed of isometric tiles which are contained in sprites. Because they are isometric, there is a lot of overlap, (And taking into account that the maps have a Z-depth as well, so sometimes tiles are stacked) and because character movement is tile-based, each tile is only slightly larger than the space one character occupies.

As far as the sync, I'm handling it manually in my main loop, not using a predetermined sync rate.
Cash Curtis II
21
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 31st Jul 2006 17:59
Did you set this...

Quote: "SET SPRITE Sprite Number, Backsave, Transparency"


To this?
Quote: "SET SPRITE Sprite Number, 0, Transparency"


You probably did that already, but you never now. Sprites with backsave is very slow.

Also, you said you are deleting them and cloning them. Perhaps this is your problem. Instead of deleting them, you should use a resourced management system that reuses old sprites instead of deleting them. When you call the Sprite command, you can just specify a new image, and it will replace the old one. In that manner, you can use the same sprites over and over again.

Ideally, you'd have a system that requests a sprite for a new tile. It generates a new sprite until the requests stop. It would recycle old sprites. Any time the system needed more sprites (say, a multi layered building popped up on screen) and there weren't enough, it would just request more.

That's how I'd do it, anyway. Like Rich said, you can use far fewer sprites to cover the screen. You've got to manage things efficiently.


Come see the WIP!
Captain GerBear
19
Years of Service
User Offline
Joined: 9th Jul 2006
Location:
Posted: 31st Jul 2006 18:13
I'll double check to see that I've got backsave turned off.
(Can't do it right now as I'm at work)

I'd never thought of trying to recycle the offscreen sprites. Is there a way to change the number of a sprite when using that method? I have to be able to identify a particular spot on the grid by its number (And corresponding sprite number)

And the issue here isn't being able to cover the screen. I could, of course, take each map individually and break it into fewer situation-specific sprites, but that would mean coding each map individually instead of being able to use the grid-based editor I've written, the maps need to be constructed within their grid, one sprite per entry.
Captain GerBear
19
Years of Service
User Offline
Joined: 9th Jul 2006
Location:
Posted: 31st Jul 2006 18:22
I should also add that I'm in the process of coding a Culling routine that will calculate which sprites are obscured by other sprites, and will tell the program not to draw them. The problem is that I'm getting the slowdown on a flat (No Z-depth) map, so culling won't have any effect in that particular situation.
Captain GerBear
19
Years of Service
User Offline
Joined: 9th Jul 2006
Location:
Posted: 31st Jul 2006 18:28
Something else I forgot to mention, my entire map is created from one master sprite. It's an animated sprite with all the tiles in it, and I just set the appropriate frame number for each tile. Is that my problem?
wildbill
20
Years of Service
User Offline
Joined: 14th Apr 2006
Location:
Posted: 2nd Aug 2006 00:17
I may be missing something, but why would you make isometric tiles from sprites instead of images pasted to the screen. I'm not being critical, I've just always used images for my iso tiles and sprites for objects. I was just under the impression images were faster, with less overhead.
Captain GerBear
19
Years of Service
User Offline
Joined: 9th Jul 2006
Location:
Posted: 2nd Aug 2006 16:23
I'm fairly new to Dark Basic so that may well be the case, but I was under the impression that you could only hold 32 images in memory. I'm using a single image, but it contains 128 different sprite tiles, which I can specify with frame numbers. I'm not sure I could do that with images (If I could, I'd love to know how)
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 2nd Aug 2006 16:32
Nah... The upper limit for images is like 65,000+

Depending on memory usage of course, but don't be concearned with limits in DB - it might not be OOP but it's not too bad with this stuff when you get used to it.

Aegrescit medendo
Captain GerBear
19
Years of Service
User Offline
Joined: 9th Jul 2006
Location:
Posted: 2nd Aug 2006 16:41
Can you use Priority with Images the same way you do with sprites? Right now he walks in front of/behind props and raised landmasses correctly, and if I can maintain that using images, I'll definitely give that a try.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 2nd Aug 2006 17:12
What you really need is a zsort before drawing the images - but what your after is certainly possible with plain old PASTE IMAGE.

You'd have to set the order of drawing and store the details in an array, so each loop you fill the array with what needs drawn, Zsort it, then paste in the new order.

It might be a simple case of giving each backdrop piece a Z value of -1, then the character 0, and the foreground 1. Then you would sort on the X position and Z position - that way all the backdrop is drawn, then the characters, then the foreground.

It's not as much of a processor drain as you'd think - the last time I did this it was perfectly fine for performance. There are a couple of tips for speeding this process up - fast tracking that Zsort would be the first place - so maybe keep the Zsort as a reference, like just the array indice stored in another array but in the right order - swapping out the arrays slows things down so that technique could help a lot.

Aegrescit medendo
Captain GerBear
19
Years of Service
User Offline
Joined: 9th Jul 2006
Location:
Posted: 2nd Aug 2006 18:13
So.. I'd need to DIM a secondary array that has enough entries for all my maptiles, props, and characters, and assign them a sort of.. 'pseudo priority' on every loop? And that in conjunction with Paste Image (with around 300 images loaded) will be faster than using about 120-180 sprites with 3 images loaded?

I'll give it a shot but that seems really backwards to me
Captain GerBear
19
Years of Service
User Offline
Joined: 9th Jul 2006
Location:
Posted: 2nd Aug 2006 19:06
... this might sound completely mental, but is PASTE SPRITE faster than just SPRITE ?
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 2nd Aug 2006 19:55
The issue is most likely with Dbpro's 'sprite priority' - It's awful ! Unless it's been fixed recently, the bigger the range in Z, the slower sprites gets. There's a few solutions, one is to implement your own depth handling as has been suggested. Another is compress the Z.

Captain GerBear
19
Years of Service
User Offline
Joined: 9th Jul 2006
Location:
Posted: 2nd Aug 2006 20:09
I don't really understand what you mean when you say "Compress the Z"
Captain GerBear
19
Years of Service
User Offline
Joined: 9th Jul 2006
Location:
Posted: 3rd Aug 2006 08:21
Wow.. I bow before your wisdom =3

I spent the evening crankily rewriting my screen refreshing routine to work with images instead of with sprites, determined to prove that it wouldn't make a difference. The process generated several nasty bugs, but once I stamped them out and got it working, not only was my overlay/underlay effect more convincing (With absolutely zero use of priority), but my framerate nearly -TRIPLED- .. from low 20s to high 50s. I have to cap it, or the player zooms all over the place.

I am very pleased. Thank you.

Login to post a reply

Server time is: 2026-07-08 10:37:45
Your offset time is: 2026-07-08 10:37:45