Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
HeathLocke

Is it bad to create lots of rects?

Question

I'm editing a script (releasing soon!) and I want to tile some pictures together. The same picture could be repeated like, from 64 times to more than 200. It should be a 32x32 picture, but I wonder if would be bad to create one rect for every picture, because maybe it could cause performance problems or something like that.

By creating a bitmap/rect I mean (and would probably do) something like this:

#the x and y would be passed on a for loop
bitmap = RPG::Cache.picture("picture")
rect = Rect.new(x, y, bitmap.width, bitmap.height
self.contents.blt(0, 0, bitmap, rect)

So, should I do it like this? Or is there any way to clone a picture or something like that? I haven't got time to look at the stock scripts to see if they have something like this but I plan on doing that tomorrow.

Thanks in advance for your attention!

Edited by HeathLocke

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

wouldn't it just be easier to assemble them in a painting program and the display one larger image, and just have a few with the minor changes you need?

 

and with that many images yes it will slow the fps considerably.

Share this post


Link to post
Share on other sites
  • 0

I had thought about that, but the sizes would be user adjusted and I didn't wanted to require the user to edit the background images, if possible.

But you gave me an idea, I could try making one image screen sized and then just adjust the rect so it crops the rest. I'll give that a try and report back.

Share this post


Link to post
Share on other sites
  • 0

In my experience with scripting so far, what causes the most drain on resources is the Redraw. Once a graphic is made, it can be left alone and not redrawn unless altered in some way. Redrawing each and every frame 20, 40, or 60 times a second, that will murder performance. It can be checked with Update, then if it is different, then do a Redraw.

Share this post


Link to post
Share on other sites
  • 0

Well, it worked! I'm using a 640x480 picture and then adjusting the rect size as I need. Here is a code snippet for future reference:

bitmap = RPG::Cache.picture("pic")
self.contents.blt(0, 0, bitmap, Rect.new(0, 0, gridWidth, gridHeight))

I'll mark dolarmark's answer as solved since it answers the thread question.

 

@Heretic86: That's good to know, thanks! In this code I don't think there are any redraws but I hope I'll remember to check if they're altered on future scripts.

Share this post


Link to post
Share on other sites
  • 0

To answer the original question in case someone still wondered about it, Rects are just RGSS objects which serve as a reference to identify a region in a picture - i.e. it's essentially an array containing a x, y, width and height values and nothing more, no actual graphic processing is involved in the making of a Rect object nor in its use. So you're basically asking if it's bad to create a lot of arrays, and the answer is: not in itself, but it might be if you can handle things differently. For example, if I understand HearthLocke's situation correctly, gridWidth and gridHeight are constants, so he's actually making hundreds of duplicates of an object which hold exactly the same information, whereas he could use just a single one.

 

Using this:

RECT_GRID = Rect.new(0, 0, gridWidth, gridHeight)

Then calling blits with:

self.contents.blt(0, 0, bitmap, RECT_GRID)

should work just fine, and avoids creating thousands of useless objects which need to be garbage collected later.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...