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 / Tile Map Performance Problems

Author
Message
slewrate
13
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Austin, Texas
Posted: 2nd Jun 2012 07:59
I am trying to draw a Tiled (tmx) tile map using a tile sheet with SetSpriteAnimation instead of loading each single sprite.


And inside the loop function I draw the map



After drawing the map my all other sprites move extremely slow.
I have a very fast PC, thus my guess is I must be doing something wrong.
Does anybody know a way of drawing large tile sets fast ?
Any other suggestions are appreciated.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 2nd Jun 2012 12:15
How many sprites is used?

Have you tryed the draw sprite command instead?

I made an simple tile mapper for boinka droid where i only created sprites in the same amount to cover the screen + 1 row on the side and top and bottom.
That one is outdated now after all the updates.
Neads to be rewritten because of the changes in sprite depth.

Where i then simply shuffeled them around when they where off screen.
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 2nd Jun 2012 16:32 Edited at: 2nd Jun 2012 16:48
if you use my tiled map thingy I posted and it is free code it dose that already. if you are looking at that code it is not updated. I made a better version of it already because I found bugs. I want to replace the main charactor with something new I am learning with charactor workshop.


Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps.
Developed the tiled map engine seen on the showcase.
Veterian for the military.

Attachments

Login to view attachments
polomint
12
Years of Service
User Offline
Joined: 3rd Apr 2012
Location: Lancashire, United Kingdom
Posted: 2nd Jun 2012 16:42
@3d : Do you have a link to your updated tile engine?

Blackberry App Development & ZX Spectrum Game Development.
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 2nd Jun 2012 17:21 Edited at: 2nd Jun 2012 18:41
Right know I am improving it with charactor workshop which is not done yet. I am helping baxs
lash hopefully. Any way the make charactors will be replaced by something what you see in charactor workshop. I still get bugs with my engine if you don't use the right format. Any way I would. might cut up code so you don't see my game I reposted it in showcase but I don't have documentation. If you look at the code it might confuse you. An animation is the fastest way and set sprite frame I get fast results.

Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps.
Developed the tiled map engine seen on the showcase.
Veterian for the military.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 2nd Jun 2012 21:24
Slewrate, dumb question, but you aren't creating the sprites every sync loop, right?

Cheers,
Ancient Lady
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 2nd Jun 2012 22:05
Quote: "Slewrate, dumb question, but you aren't creating the sprites every sync loop, right?"

You know I was wondering the exact same thing

And it's kind of implied with the statement.
Quote: " inside the loop function I draw the map"


AGK manages sprites so well - thousands of them - without issue, slowdowns are almost always cause by the programmer interfering
slewrate
13
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Austin, Texas
Posted: 2nd Jun 2012 22:50
@Marl, @Ancient Lady,
I think you guys have a point.

My thinking behind putting the drawMap function into the loop was that if I scroll the map, I have to redraw parts of the map. But I guess I don't have to redraw the entire map, which is what I'm doing I guess.
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 2nd Jun 2012 23:21
Do you know about SetViewOffset() ?

It will move the view over a world area larger than the display.

You may not have to redraw any of the map.
slewrate
13
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Austin, Texas
Posted: 2nd Jun 2012 23:46
@Marl:
I'm not aware of that command. Wouldn't that imply that I have to draw the entire world at once?
I would like to put together a platformer with large levels. Drawing a large level in its entirety....hmm wouldn't that be bad performance wise?
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 3rd Jun 2012 00:00 Edited at: 3rd Jun 2012 00:04
yea you guys are all right that is what I do with mine I draw the world once and then use setviewoffset. You draw your world every loop that is why it is so slow. and you can draw different segments of the map just have to do a little math and it will draw that section of the map. I don't like that because it is not very effeciant so I use levels, and case select.

Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps.
Developed the tiled map engine seen on the showcase.
Veterian for the military.
slewrate
13
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Austin, Texas
Posted: 3rd Jun 2012 00:05
@3d point in space:
So do you draw a tile map that is several screens large and move over it with setviewoffset ?
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 3rd Jun 2012 00:31
Quote: "Drawing a large level in its entirety....hmm wouldn't that be bad performance wise?"

Depends on how big you are talking, but generally no.

In essence, sprites are simply pointers to the images they display so are very efficient space wise.

If you do it manually, you determine which tiles are on screen and calculate their positions.

Using the view offset, their world positions aren't changing, and their positions relative to the screen all change together.

AGK already tracks what is on screen and what is not so only draws the relevant portion. Anything AppGameKit does internally is going to be much faster.

Plus with setViewZoom(), you can zoom in and out as well which would be a pain to do manually.
slewrate
13
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Austin, Texas
Posted: 3rd Jun 2012 00:41
@Marl: Thanks for your advise. I will test setviewoffset tonight

Thanks to everybody for their suggestions.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 3rd Jun 2012 00:49 Edited at: 3rd Jun 2012 00:50
Quote: "I would like to put together a platformer with large levels. Drawing a large level in its entirety....hmm wouldn't that be bad performance wise? "

It will have an impact on memory thats why i used a limited amount i shuffeled around

But i suggest that you use setview offset first and draw the entire map.

Then optimize if you nead it?

Dont forget that agks 2d is actually 3d meshes that look like 2d
So works the same as an 3d engine where the stuff off screen shouldt have to much impact on performance?
Most open gl 2d is working this way as its true 2d canvas is extremely slow.
slewrate
13
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Austin, Texas
Posted: 3rd Jun 2012 03:46
All right. I draw a large map just once, and move over it via setviewoffset. This seems to work . The only thing that bothers me is that occasionally I can see how parts of the screen is redrawn. For instance you can see the first parts of a tile being shifted one pixel. The way I use setViewOffset is by simply adding 1 to the x or y coordinate. I wish I could scroll the map a bit more smooth.

Still though, this is pretty good.
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 3rd Jun 2012 04:13
Quote: "The only thing that bothers me is that occasionally I can see how parts of the screen is redrawn."

Possibly due to slight timing differences between your device refresh and your scroll speed.

Ideally, all in-game movement should be linked to the timing of your device - be it windows, android, ios or whatever.

This is commonly called timer based movement and you are fortunate that Baxslash has some excellent guidelines on the matter in the newsletter.

http://www.thegamecreators.com/pages/newsletters/newsletter_issue_111.html#6

Quote: "The way I use setViewOffset is by simply adding 1 to the x or y coordinate. I wish I could scroll the map a bit more smooth."

One is not the smallest number and one Pixel is not the smallest amount you can scroll.

If you use floating point values for the scroll offset then you can scroll fractions of pixels.

It might sound odd ad first, but you'll get used to it.
slewrate
13
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Austin, Texas
Posted: 3rd Jun 2012 04:18
I will look into this. Thank you Marl.

One last thing (and sorry to high jack my own thread),
I added a player sprite to which I added physics like so:


and it's now moving down towards the tiles. Is there a simple way of having this sprite to collide with all my tiles ?
Again, sorry for throwing this in as it is not related to the original question.
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 3rd Jun 2012 04:30
wow your doing every thing that I do in my program that sounds like you know what your doing. and I use object groups and raycasting

Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps.
Developed the tiled map engine seen on the showcase.
Veterian for the military.
slewrate
13
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Austin, Texas
Posted: 3rd Jun 2012 07:08
I believe I added now timer based movement.
My Sync Rate is set to (60,1);


The map scrolls pretty smooth yet I still have this weird redraw effect.

Any suggestions are appreciated.
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 3rd Jun 2012 07:27
I have no clue cant see your code you just show loop. I don't have a screen shot eather so have no clue.

Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps.
Developed the tiled map engine seen on the showcase.
Veterian for the military.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 3rd Jun 2012 10:15 Edited at: 3rd Jun 2012 10:18
If you get huge frame rate changes so could it show a weird redraw.
You dont mean screen tear?

Because that could be your device that is slow or bad?
slewrate
13
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Austin, Texas
Posted: 3rd Jun 2012 15:45
Sorry for not posting my code. It got quite late last night.



And this is the map Class:



@Cliff Mellangard:
I seriously doubt that it is a device related issue. It's a new system and runs most modern titles without hick ups.

At any rate. My main sprite is still falling through the map and the redraw still happens.
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 3rd Jun 2012 16:22
i think it is because you have a very large map. I would draw sub sections of your your hole map. Using a procedure of drawing a section of your map instead of the hole map and erasing the previous subsection will work.
like only load the top 1/4 of the map or 1/8 and if you go off the screen load the other part of the map. May not be your solution.

Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps.
Developed the tiled map engine seen on the showcase.
Veterian for the military.
slewrate
13
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Austin, Texas
Posted: 3rd Jun 2012 16:41
@3d point in space: I think that makes sense. I also notices if I use significantly smaller maps that I don't see the redraw effect.

I'll try to implement a different technique.

Now, I am just not sure how I would 'erase' what's already been drawn.
What would be my reference to the sprites that I want to get rid off (especially the ones off screen) ?
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 4th Jun 2012 08:49 Edited at: 4th Jun 2012 13:56
use a vector to keep track of the sprites that where created in your for loop that is what i do. your function look simular to mine. after you get the on a spot on the vector then erase all the sprites on the vector then do a .~vector after you erase the sprites.


Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps.
Developed the tiled map engine seen on the showcase.
Veterian for the military.
slewrate
13
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Austin, Texas
Posted: 13th Jun 2012 05:56
Thanks @3d point. I was wondering initially, why you did the pushback in your code, but now it makes sense.
slewrate
13
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Austin, Texas
Posted: 15th Jun 2012 23:32
I have cut down this code to a bare minimum, trying to draw a map for just one screen. Despite the map being only 25*18, I still experience this weird redraw effect. In addition, I tested the executable on 4 different Windows 7 machines (modern systems with decent power), the result remains the same. My map doesn't scroll smooth.



Any suggestions are as always appreciated.
XanthorXIII
AGK Gold Backer
13
Years of Service
User Offline
Joined: 13th May 2011
Location:
Posted: 16th Jun 2012 07:43
Have you tried taking off agk::SetSyncRate(60,0)? I've heard that can cause strange issues.

Also, I noticed this section of code

clone=agk::CloneSprite(tileSheet);
agk::SetSpriteFrame(tileSheet,map[x+y*25]);
agk::SetSpritePosition ( tileSheet, bx+xp, by+yp );

It looks like you are assigning something to the variable clone but not doing anything with it. Also if you are cloning the entire sheet multiple times which it appears you are doing, that may cause you memory issues. You may want to revisit how you are doing the animation for the tiles.

Login to post a reply

Server time is: 2024-11-23 17:05:24
Your offset time is: 2024-11-23 17:05:24