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.

AppGameKit Classic Chat / 2D without a sprite instance for each blit/tile

Author
Message
Nelvin
10
Years of Service
User Offline
Joined: 23rd Nov 2014
Location:
Posted: 28th Nov 2014 12:09
Is there a way to do 2d Rendering without creating a sprite instance for everything visible on the screen?

Let's say you have a tilemapped game with a map of 500x500 tiles - it probably will kill AppGameKit to use 250.000 sprites and, even if not, it would be such a waste of resources because tilemaps usually are managed in tight arrays and they don't need much data per tile.

Tilemaps are just one sample so don't narrow it down on this one, it's the same whenever there's something to draw that doesn't need any/much (sprite)state and/or for stuff where anything that's required is most easily calculated in an implicit way using other game relevant data structures.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Nov 2014 16:49 Edited at: 28th Nov 2014 16:50
You can at a very simple level pasteImage(), though you would have to do this every frame as it is destroyed each time.

Next level up, you could pasteImage() your map of images and then getImage() the larger picture. This could be pasted back as one larger image each frame, or put onto a large sprite which will take care of itself.

Lastly, you only need enough tiles to cover the screen, plus two extra rows/columns. As the sprites scroll off one end of the screen, you reuse them at the other side. Change the sprite image as it gets reused.

If multiple sprites use the same image, you only need one copy of the image for all of the sprites that use it.

Quidquid latine dictum sit, altum sonatur
Nelvin
10
Years of Service
User Offline
Joined: 23rd Nov 2014
Location:
Posted: 28th Nov 2014 18:46
Thanks for your reply.

I can't find a pasteImage in the API - if you meant something like CopyImage that would not be a good fit as it's marked as slow, i.e. it's updating textures in the background.

Pasting images onto a big image would waste a huge amount of resources and be limited by VRam and max texture sizes. Also it would only work with static maps.

Sprites are an option, even though not the best (would have to reset the image, coords, UV coords each frame and these may have hidden performance costs) but, if there's no better way, probably the only one available at the moment.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 28th Nov 2014 19:17
Better to keep a "window" of on-screen tiles and reload when when moving, surely?

-- Jim - When is there going to be a release?
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 28th Nov 2014 22:13
I'm creating a 2D platform game and AppGameKit seems to manage fairly large numbers of tiles (sprites) really pretty well. I'm using the view offset to scroll around a persistent map. Maps to date have been around 50-75 by about 200 and I'm also using parallax layers with transparency and getting FPS in the high hundreds. You might want to do some very crude tests as a proof of concept to see if this system works for you as it is simple to implement. Just bash out a random 'map' of tiles and see what performance you get. Might not work for mobile devices performance wise but certainly PCs and macs should cope well.
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 28th Nov 2014 22:31 Edited at: 28th Nov 2014 22:35
Hi,

How about


Im pretty sure this fit's your requirements.
Made the code for you in a vew minutes..
What I did is.. I draw the same sprite at the desired position, but only within the borders.
You will notice the frame boost if you zoom in or get out of the map.

And just ask, if you have anny questions.

Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 29th Nov 2014 10:46
I have used a text object in v1 to show a large number of tiles, I'll see if it works in v2 as well later on today.

I am the one who knocks...
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Nov 2014 12:53
Quote: "Sprites are an option, even though not the best (would have to reset the image, coords, UV coords each frame and these may have hidden performance costs)"


As mentioned by DavidAGK and Janbo, the secret is to use the view offset. For 90% of the time there are no coordinates to reset. The UV coordinates never change (I presume you are talking about the UV of the images on the sprites?)

A small check tells you when a row/column of sprites drops out of view, and at that point you move them to the opposing side with appropriate images. An array of the map will keep track of which sprite and image is assigned to which tile.

Quidquid latine dictum sit, altum sonatur
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 29th Nov 2014 20:03
Here's an old example I made using text to make a tile map...

I am the one who knocks...

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-25 11:51:57
Your offset time is: 2024-11-25 11:51:57