We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Images created with get are slow
Page Index Toggle Pages: 1
Images created with get are slow (Read 533 times)
Images created with get are slow
Apr 18th, 2006, 7:58pm
 
Hi,
I'm trying to create a simple tile based web game and currently load each of the 124 tiles as a separate GIF file. This takes a very long time to load. I also have all of the (16*16px) tiles in one large image file (256x256). I am trying to load them like so:

for(temp=0; temp<=124; temp++)
 {
   a=temp%16;
   b=(temp-a)/16;
   tiles[temp]=tempImage.get(a*16, b*16, 16,16);
 }

This code loads the tiles faster than loading 4 tiles separately, but the resulting PImage tiles[] slow the game to an absolute crawl. I don't get it. Are my PImages somehow different than they were when I loaded them like so:

for(temp=0; temp<=124; temp++)
 {
   tiles[temp] = loadImage("Tiles/"+str(temp)+".gif");
 }

Thanks!
Joseph D.
Re: Images created with get are slow
Reply #1 - Apr 18th, 2006, 10:20pm
 
Oddly, it runs full speed when I run use:
set( (i%16)*tileSize, (floor(i/16))*tileSize,tiles[map[i]]);
instead of:
image(tiles[map[i]], (i%16)*tileSize, (floor(i/16))*tileSize);

I presume this is a bug. The difference is 60fps to 3spf Tongue
Re: Images created with get are slow
Reply #2 - Apr 18th, 2006, 11:04pm
 
set() is faster because it can just copy the pixels directly from the image. the image() function has to respond to the tint() color and any scale/rotate/translate calls so it will be slower than cases where you just want to draw the pixels directly. image() has to be more general, and in the default renderer that makes it really slow.
Re: Images created with get are slow
Reply #3 - Apr 19th, 2006, 6:08pm
 
Perhaps a link at the bottom of the image() function to set() with a note like "A faster more direct way of drawing an image" just so the next guy to come along doesn't stumble like I did?
Page Index Toggle Pages: 1