Game Development Community

Stringing Images Together

by Robert Fritzen · in Torque 3D Professional · 09/14/2012 (11:46 am) · 8 replies

Alright, so now I have a new and fun challenge at hand. I've created a new Weapon HUD (shows both my primary/secondary and equipment item). One task I'd like to do is to change my ammo display from being a simple ammo / clip text field, to a string of images indicating the current clip status.

Pretty much, I have various different "small" images in my game, indicating the different weapon classes, and two of each (one for fired bullet, one for still in clip). I can easily get the variable information regarding how many of each I need to have, but my problem is, how do I efficiently stream together these images into a GUI Container. Obviously Image size field will matter here depending on the size of the gun's clip. And I don't think having a crapload of guiBitmap objects is relatively memory friendly here.

Suggestions? Oh, and you might want to give this a shot. I plan on releasing my entire weapon system as a resource for the community when it's done and working. You know you want it ;)

#1
09/14/2012 (12:17 pm)
If you can fit all the images in a reasonable sized single image (less than say 2048x2048) then I suggest creating your own GUI control that makes use of bitmap array rectangles of which is a supported feature of the GuiControlProfile class and use that together with GFXDrawUtil::drawBitmapSR() functions.

To see examples of doing that look at how GuiButtonCtrl draws its themed buttons using GuiControlProfile::constructBitmapArray() in GuiButtonCtrl::onWake() and renderSizableBitmapBordersFilled() in GuiButtonCtrl::onRender(). You'll want to look at how renderSizableBitmapBordersFilled() (in guiDefaultControlRender.cpp) is making use of the GFXDrawUtil::drawBitmapSR() calls.

It seems complicated at first, but once you figure out how to use GuiControlProfile::constructBitmapArray() and GFXDrawUtil::drawBitmapSR() functions then you're pretty much home free. The actual image file needs to use a color key as an array delimiter which is the color used at pixel location 0,0 within the image and then you draw lines to separate your individual images of which is what GuiControlProfile::constructBitmapArray() uses to populate the GuiControlProfile::mBitmapArrayRects RectI vector. So, make sure that when you pick a hot color to use, most themes use #FF0000 (Red) then never use that same exact pixel color value within your individual subimages else you could confuse/break GuiControlProfile::constructBitmapArray().

#2
10/01/2012 (9:38 am)
Thought I'd post an update here, I got this working out to how I need it. Here's the end result:

phantomdev.net/staff/phantom139/images/newWeaponHud.png
And to those of you who need a control like this, I've posted my source code for it Here. It's a pretty straight forward tool to use, just see the console function declarations at the end of the CPP file to see how to use it.
#3
10/01/2012 (12:02 pm)
In game picture or video? This sounds really cool.
#4
10/03/2012 (1:28 pm)
Really cool! :-)
#5
10/06/2012 (11:16 am)
@Frank: Sorry about that.. I missed that post and didn't see it.. Here's an in-game picture of it.

In-Game ScreenShot

*edit: had to use a link because re-sizing images doesn't appear to happen here
#6
10/10/2012 (12:44 pm)
"...string of images..." Sorry, not following. What does this control do exactly? Does it animate a list of images? Does it hold an array of images? If it holds an array, what does it do that a GuiCtrlArrayCtrl or GuiStackCtrl don't do already?
#7
10/10/2012 (4:02 pm)
It displays a line of images, basically in a straight line (or a string, hence the name) I suppose you could think of it as GuiLinearBitmapCtrl also?

It's not actually an array of images, but mainly a repeated image with a number count specified by you, You also can define a cutoff image and a respective point at which the control will switch to using the second image instead of the main one.

Does that make more sense?
#8
10/10/2012 (5:38 pm)
Ok, yeah, that makes sense now. Thanks.