Game Development Community

guibitmapctrl READ OR DIE!!!!!!!!

by Dr. John Nobody · in Torque Game Engine · 05/29/2003 (12:35 am) · 25 replies

thanks for taking the time to read this, now you get to live another day

ok heres the deal, my game needs a page that lets the player select their character, nothing to fancy, I just have buttons for selecting characters (which I have guibitmapbuttonctrl's for and I want them to not only set up the correct player, but also change the bitmap displayed in a guibitmapctrl, heres an example of what the screen looks like

www.border-town.net/multimedia/Eric/playerselectscreenshot.jpg
I have the buttons working fine in that they call a function which sets up the player, but I also have the function modify the guibitmapctrl which is named "DisplayPlayer", here is how I set up the guibitmapctrl

new GuiBitmapCtrl(DisplayPlayer) {
            profile = "GuiDefaultProfile";
            horizSizing = "right";
            vertSizing = "top";
            position = "0 129";
            extent = "366 350";
            minExtent = "8 8";
            visible = "1";
            helpTag = "0";
            bitmap = "./CharacterProfiles/RobotProfile.jpg";
            wrap = "0";
         };

then I call the function setBitmap

DisplayPlayer.setBitmap("./CharacterProfiles/RobotProfile.jpg");

in the playerselect function (which each button calls) I currenty have it set so every button puts up the robotprofile.jpg just untill I get it working. Here's the problem, no bitmap shows up when I make this function call, in the C++ code for the function it tests whether the string is kosher or not and if it isnt it just assigns NULL for the bitmap, which explains why I'm not getting a bitmap displayed when i run that line of code. So you'd think its obviously problems with the string I'm passing, but just to test things further I tried the other function supported in the console setView which should resize DisplayPlayer to 50x50 pixels

DisplayPlayer.setValue(50, 50);

but to no luck, it didnt resize anything, and the console isnt giving me any messages from any of this, just to make sure the line was getting run I tried deleting a parameter and got an error in the console, so I know this is all getting run, its just not working... why god why isnt it working!?!? maybe its the fact that its 4am, maybe its all the loritab I'm on, but I just cant seem to figure this out... any help would be GREATLY appriciated

thank you all for reading through this and hopefully giving it some thought, if any of you ever need a kidney... well you know where to find me *goes to erase adress and phone # from profile*
Page «Previous 1 2
#1
05/29/2003 (3:39 am)
sorry other threads, time to bump myself :)
#2
05/29/2003 (5:24 am)
Eric,

Try to not specify the extension e.g. ("./CharacterProfiles/RobotProfile" and give it another try?

Is the "CharacterProfiles" directory hanging off the directory where the gui is?

Is the file .png and not .jpg?

Perhaps a not-so-obvious typo in the directory/filename?

All I can think of for the moment.

- Melv.
#3
05/29/2003 (9:35 am)
sorry melv, first thing I checked, CharacterProfiles is indeed a directory that that hangs off ui and the images are all jpg's. I've tried rewriting the extension in many many different ways, with just the file, with a an extension going all the way back to fps, I've tried like a gazilion different ways to get this to work, none of which has :(

(on a side note, the extension that I have up there is the one that the other buttons use (the working ones) and even works on the guibitmapctrl if I put it in the bitmap property when I define the object, it only messes up with the setBitmap function... anyone know a little more about the guibitmapctrl? is there just something wrong with it? or is there something wrong with me?)
#4
05/29/2003 (10:55 am)
Eric,

Perhaps this is simply a current directory problem. When you issue the setBitmap command, try using the full path. For example, if it was the FPS example, you could use...

DisplayPlayer.setBitmap("fps/client/ui/crossHair");

Maybe this will help.

- Melv.
#5
05/29/2003 (12:15 pm)
you da man Melv! that worked perfectly... that fixes my changing the bitmap problem, now for my resizing problem... any idea why

DisplayPlayer.setValue(50, 50);

isnt resizing the image to 50x50?

also, now I need to switch the image to different players when their buttons are pressed, to do this I was just going to put if statements in the setplayer1class

function playerSelectGui::setPlayer1Class(%playerClass){
   $pref::Player::playerClass = %playerClass;


   // DisplayPlayer.setValue(50, 50);

    if(%playerClass == roach)
       DisplayPlayer.setBitmap("fps/client/ui/CharacterProfiles/RoachProfile");
    if(%playerClass == robot)
       DisplayPlayer.setBitmap("fps/client/ui/CharacterProfiles/RobotProfile");
    if(%playerClass == drinkingbird)
       DisplayPlayer.setBitmap 
("fps/client/ui/CharacterProfiles/DrinkingBirdProfile");
    if(%playerClass == sputnik)
       DisplayPlayer.setBitmap("fps/client/ui/CharacterProfiles/RoachProfile");
    if(%playerClass == atomico)
       DisplayPlayer.setBitmap("fps/client/ui/CharacterProfiles/RoachProfile");
}

thats the class which sets the player, this is the line of code I use in the guibitmapbuttonctrl to call it, passing a character as a parameter

command = "playerSelectGui::setPlayer1Class(sputnik);";

I seem to be getting an error in the script saying that the string in

if(%playerClass == roach)

and each line like that always equels 0 (which means I'm not passing the string correctly) first off, can the scripting language compare strings in this way? or do I need a special function to compare them as I would in C? if so what is that function and if not does anyone know whats wrong with this?

thanks again for all your help Melv :)
#6
05/29/2003 (12:29 pm)
Eric,

1) The "setValue" command provides offsets to the bitmap only when the "wrap" option is on. The bitmap is otherwise simply resized to the control itself rather than wrapped and there are no options.

2) Use $= for string equality tests and enclose your constant strings in double-quotes.

Hope this helps bud.

- Melv.
#7
05/29/2003 (12:43 pm)
AWESOME! thank you so much Melv, you just saved me a ton of frustration, all my bitmap changing needs are completely fulfilled now :)

got a few questions about the setValue stuff though, when you say wrap, you mean the bitmap apears as its fixed size, but is clipped if the ctrl is to small to display it all and is tiled if its to big for the bitmap? (I might be way off, but thats my best guess as to what wrapping is). If wrap is off and the bitmap is resized to the ctrl, is there anyway to resize the ctrl itself? (thats what I thought setValue did) Heres what I want to do, I was planning on testing the screen resolution and resizing all the buttons and stuff through script based on what screen resolution was detected (I hate the fact that torque doesnt resize a gui along with the screen), if setValue cant do that, is there any way it can be done? I guess I could test screen res and just define my buttons from the start based on what size is detected, but that seems sloppy, I was hoping I could change the sizes on the fly using a function, but if they are static I guess the other way will work. Sorry to ask so many questions, I'm kinda new to the scripting side of things.

Thanks again Melv :)
#8
05/29/2003 (12:53 pm)
Eric,

The "wrap" option on this control has identical functionality to the tile option for Microsoft Windows backgrounds. You can have either tiling (wrapping) or size to fit.

The "setValue" option has the curious feature of offsetting the wrapped bitmap. Try turning the wrap option on in the console editor and entering different setValue commands to see what I mean. Without wrap on, you won't see any effect from setValue.

Of course, changing this controls minimal features would be a really simple matter.

- Melv.
#9
05/29/2003 (1:17 pm)
"Of course, changing this controls minimal features would be a really simple matter."

ok, when you say a simple matter what do you mean? wont I have to add a function to support this in the .cc file? I'd need to be able to update the extent and position variables from script, that would need a new function right? or can I do that now from scripts? (sorry for my newb questions)
#10
05/29/2003 (10:24 pm)
Eric,

Yes, I meant that you would have to change the C++ source but the GUI controls are probably the easiest part of the engine to understand and are fairly trivial to change.

You can amend *any* of the fields you see in the console editor. A command such as ...

MyBitmapControl.position = "100 50";

or

MyBitmapControl.extent = "25 25";

... would change its position/size.

- Melv.
#11
05/29/2003 (10:34 pm)
cool, so then I wouldnt have to change any C++ (which is a good thing, I'd like to do as much through scripts as possible) I could just echo statements like MyBitmapControl.position = "100 50"; straight into the console right? Thanks for telling me about that, just to make sure, theres nothing wrong with that is there? I already tested it and it seems to work, but it wont cause any problems down the road will it?

three cheers for Melv!!!
#12
05/29/2003 (11:59 pm)
Eric,

*Any* fields for *any* object you see in the editor can be accessed this way.

There are a couple of things to be aware of though. Simply changing an object field may not do other stuff like load-up appropriate textures. In this case there is nearly always an actual function to call that changes the field itself but also does the appropriate work. Also, depending on your specific gui, not all controls are redrawn constantly so you need to be aware that you may not see the change unless you trigger a redraw of the control or the whole canvas (which you can do).

All controls are in a hierarchy (as you can see in the gui editor itself) and if a parent control is redraw, then all of its children controls are redrawn also, plus their children.

Typical reasons for any control to be redrawn are that another window covered your game screen, you tasked switched, the gui has just been set or has been uncovered or perhaps it *is* constantly redrawn such as the GameTSCtrl which shows you the 3D world itself.

A good way of kicking a control into redrawing is to call its ".setVisible(true)" method.

- Melv.
#13
05/30/2003 (12:05 am)
cool, thanks again Melv, you have no idea how much all this helps with my gui endevours
#14
05/30/2003 (4:29 pm)
ok, I've been looking for a a way to test the screen resolution, but I cant seem to find any kind of a global variable that stores this info... does anyone know if there is one and what its called? Or if theres any other way to test the screen resolution?
#15
05/30/2003 (6:50 pm)
Off the top of my head, I think it's $pref::Video::resolution

I'm not sure if that will accurately depict the current running resolution (since the prefs may be changed but not applied).
#16
05/30/2003 (7:46 pm)
thanks for the suggestion, but I'm not so sure this is working, I've tried to test this and sometimes it works and sometimes it doesnt, I'm thinking its not updated when you change the screen res or something... not sure

any other ideas?
#17
05/31/2003 (1:19 am)
Eric,

The canvas is the way to go with stuff like this. Don't forget that everything is placed on the canvas, hence calls like Canvas.setContent() / Canvas.repaint() / Canvas.cursorOn(). The Canvas is also based upon the standard GuiControl and so it acts exactly like any other control.

Because of this, you can use Canvas.getExtent() which returns stuff like "1024 768" or "800 600" and it always reflects what you are seeing at the current moment, irrelevant of any script settings.

Hope his helps bud.

- Melv.
#18
05/31/2003 (1:23 am)
Melv = my guardian angel :)
#19
05/31/2003 (1:41 am)
Melv,

hate to be difficutl, but that canvas stuff is giving me errors, I thought I could try a simple

if(Canvas.getExtent() $= "800 600")
echo(DisplayPlayer.extent = "100 100");

but that seemed to cause a compile error, anyway, I kept trying things until I was down to

Canvas.repaint();

and that didnt work either... is there something special I'm supposed to do with this? I was under the assumption that Canvas was an object and I could simply make a function call which would do something or return a value (or both). It looks like Canvas is used in the ways I was using it in other parts of the same script... do these functions have required parameters or something?

I know I can count on you Melv :)
#20
05/31/2003 (2:11 am)
Eric,

Canvas.getExtent() will return your resolution. You can confirm this by issuing a command such as ...

echo( Canvas.getExtent() );

I'm not sure what you're trying to do with the statement in the if() conditional though ...

echo( DisplayPlayer.extent = "100 100" ); Why echo the assignment???

As you've typed it here, it will work though.

Canvas.repaint() simply tells the canvas to redraw all the controls shown. Sometimes changing a parameter on a control will not cause it to redraw so you can force the issue with this command.

It'd probably be best if you posted the compile error.

- Melv.
Page «Previous 1 2