View Full Version : Keeping track of images...

05-14-2008, 06:49 AM
I'm using a 'progressive indexing' sort of image display for my GUI. Basically, I've created custom functions for displaying images, and create an index var that increases every time it's called. This lets me easily show images without having to worrying about placing a free index on it.


function onCreated() {
for (i=0;i<player.fullhearts;i++) imgshow(crap);
function imgshow(paramstuff) {
Would display images for each of the player hearts. Problem is, because it is a HUD, it is displaying a lot of dynamic statistics. Hearts lower, rupees decline and so on. This creates a problem I have with if, say, my player hearts lower, the hearts don't disappear because I haven't hidden them. Because I am using a system where images won't always have the same index, I'm having a hard time figuring out how to hide images that are no longer needed.

Any idea how to fix this? I figure I'm going to have to find a way to compare the last number of images being displayed with the next amount of images to be displayed, but I'm having a problem figuring out how to do that because the only way to do that would be to 'predict' how many images are going to be displayed next.

05-14-2008, 08:25 AM
const HEARTS = 500;
const RUPEES = 600;


05-14-2008, 08:42 AM
The thing is, it's not that simple. The imaging system I'm using is used for ALL images. GUI background, icons, rupees, numbers.

05-14-2008, 08:52 AM
function imgshow(paramstuff,imgtag) {
if (imgtag != "") this.imgindex.(@imgtag) = imgid;

Then retrieve via findimg(this.imgindex.sometag).

05-14-2008, 09:08 AM
See, that's the thing. I don't really want to categorize them. I want to apply the logic:
if (newimagecount < oldimagecount) hideimgs(newimgcount,oldimagecount);
I don't need to hide any certain images, like hearts. I just need to be able to hide images no longer being used(that aren't being drawn). Because the way my system works, the indexes of hearts that are lost would most likely be recycled and used for something like key icons.

Right now I'm doing hideimgs(200,imgid) before the script to hide ALL images before they're drawn again. In my past though I have noticed this is taxing and I want to avoid hiding them each time they're redrawn.

05-14-2008, 10:44 AM
Maybe make some sort of a hash function? Like:

function doShowImg(text) {
temp.hash = myhash(text);
for (i = 0; i < 100; ++i) {
if (findimg(hash*100 + i).title in {text, ""}) {
with (findimg(hash*100 + i)) {
this.title = text;

function onCreated() doShowImg("hpbar");

Of course you would have to add other params for the various showimg elements but that's just something to give you an idea. Also, I'll leave the hash function up to you but it should return some sort of integer of course. This also assumes that you won't be using more then 100 images for each element that shares the same index on the hash table.

After that, something could be scripted fr hiding the images and when hideimg() is called, the "title" var would be deleted so you wouldn't need to worry about that ;).

Hope that helps.

05-14-2008, 10:53 AM
Why not something like this?

this.imgindex = 200;

// display stuff

if (this.lastimgindex>0)
hideimgs(this.lastimgindex, this.imgindex);
this.lastimgindex = this.imgindex;

05-14-2008, 11:01 AM
Zero: Yours confuses me :( I'll have to go over it after I go to bed.
Stefan: I've tried that. hideimg after the showimgs causes it to flicker. It works, but the flickering is very distracting, and I can't imagine having that after every update of a rupee or something.

05-14-2008, 03:13 PM
Why not just loop through maxhearts instead?

05-14-2008, 04:52 PM
Zero: Yours confuses me :( I'll have to go over it after I go to bed.

Basically, the has function just takes the text (be it a gui name or so) and returns some sort of number. A very SIMPLE example of a hash function might be:

function hash(i) return i%10;

Of course, that is designed for integers, not strings. It's a programming technique designed mostly for creating hash tables that are used in sorting and such but I think it would work pretty well in this situation.

EDIT: Here's a simpler alternative if you don't want to deal with hashing:
In the onCreated of a "Main"-like system wnpc, put:global = new TStaticVar("_");

Then in the globalfunctions class:
function onCreated() {
this.showimgtable = {

function getImgIndex(text) return 201 + this.showimgtable.index(text); // If index is -1, then it will return 200

function getImg(text, obj) with (obj) return findimg(getImgIndex(text));

Now it's easy to showimgs:

showimg(_.getImgIndex("hearts"), "heart.png", 204, 405);
_.getImg("fullhearts", this).image = "fullhearts";

Make sense?

05-14-2008, 06:46 PM
Why not just loop through maxhearts instead?
Here's a small clipping from the script to show what I'm doing, exactly.

function onTimeout() {
hideimgs(200,imgid); // This is what I'm doing currently to hide them


function guiShow() {
for (i=0;i<player.fullhearts;i++) {
if (i==int(player.hearts) && player.hearts.pos(".")>0) imgshow(12+(i*16),12,{36,0,16,16},5);
else if (i<int(player.hearts+.5)) imgshow(12+(i*16),12,{20,0,16,16},5);
else imgshow(12+(i*16),12,{52,0,16,16},5);


function shownumbers(num,x,y) {
for (i=0;i<num.length();i++) imgshow(x+(i*12),y,{numref.pos(num.charat(i))*14,3 2,14,16},5);

function imgshow(x,y,part,layer,colors,mode) {
if (mode!=null) changeimgmode(this.imgid,mode);
else changeimgmode(this.imgid,1);
if (colors!=null) changeimgcolors(this.imgid,colors[0],colors[1],colors[2],colors[3]);
else changeimgcolors(this.imgid,1,1,1,1);

As for Zero, from what I'm gathering you're categorizing images. I'm not sure that's exactly what I want to do.

05-14-2008, 10:21 PM
Why not an array of what index points to what?

05-14-2008, 11:21 PM
Because I don't need to know what points to what. I don't need to hide any specific images, just know WHEN to refresh them. I think the simplest solution is what I'm using now, I guess.

05-14-2008, 11:27 PM
Stefan: I've tried that. hideimg after the showimgs causes it to flicker. It works, but the flickering is very distracting, and I can't imagine having that after every update of a rupee or something.
Do it after, not before, it's not flickering

05-14-2008, 11:30 PM
I have done it after. It flickers every time the images are hidden and redrawn.

05-15-2008, 01:59 AM
Why not only hide what you need to hide, and change everything else?

05-15-2008, 02:19 AM
That's the problem I'm having. I have no idea how to make it hide what I need to hide.

05-15-2008, 10:59 AM
You can't really track dynamically indexed images without having some sort of categorization.

No really, you can't.

enum IMAGE {

hideimgs(IMAGE.HEARTS*200,IMAGE.KEYS*200 - 1);

I mean if you find a better way, let me know, but that's how I do it.

05-15-2008, 11:40 AM
I found a way to do it... I mean, I'm not tracking them, but I got them to hide. It was buggy though, sadly, so I had to drop it.

05-15-2008, 11:52 AM
I'm working on some drawing functions for arcs / beizer curves with polygons. Interested?

05-15-2008, 11:56 AM
Heh, no thanks. Already explained it in my other thread as to why I don't think I'd take that road. I think it's just simpler to use images.