Game Development Community

Changing ImageMap in GuiBitmapButtonCtrl?

by Watermark · in General Discussion · 08/17/2011 (2:34 am) · 5 replies

Environment: iTorque 1.4.1 on Mac OSX.

Hi, I am a beginner and can't seem to find the info to solve this problem:

How to change the picture on a GuiBitmapButtonCtrl to an in game static sprite?

The control I want to change is called button_Picture. I have a static sprite in the editor called enemyImageMap. I set it so when I press a button, it calls:

button_Picture.bitmap = new enemyImageMap();

Which doesn't seem to work. So here are my questions:

1. How do I change the bitmap on a GuiBitmapButtonCtrl (and related Gui)?

2. How do I create a new imagemap using an in-game static sprite datablock? e.g. I have t2dImageMapDatablock enemyImageMap, how do create copies of this with just code?

And a somewhat related question
3. Say I have a static sprite in the level called mySprite. How can I change that picture?

mySprite = new enemyImageMap();

Something like this?

You help appreciated!

About the author

Three iTorque 1.5 games published: Sorceria 1: The Mad Doctor RPG Sorceria 2: Sunken City Sagas: RPG Boardgame and Name Generator For more info see our site: http://wmrpg.weebly.com


#1
08/18/2011 (7:19 am)
You have some rather basic wrong assumptions regarding syntax and general reference of how TorqueScript works.

Take a look at the documentation for start, should clarify all your questions.
#2
08/19/2011 (4:44 am)
See, it's not that I haven't read the documentation. I spent hours upon hours on the documentation(s) but unfortunately could not find the answers to the questions I posted. As new users to this tool, our only methods of learning how to use it are two, both with...complications. Let me explain:

Method 1: The Official Documentation
iTorque is a powerful engine with the ability to make very complex games. However, the official documentation is lacking in tutorials for "complete" games. After reading it I can make incomplete mini games with no title screen or different levels but the rest I have to figure out. For example, how do I go to the next level? Or for example Rainy Day, Why is there no tutorial on how to control it with a virtual gamepad (like with Game Salad)? IMHO, there should be a tutorial on how to make a complete game from start to finish. It could be as simple as a simple platformer with 2 stages and 1 boss.

Method 2: Search for it in Forums or Web
When I search for a particular solution, much of what I find is either A. outdated (usu from 2004~2006) or B. designed for a different Torque platform (3D, X, etc.). Just on how to read XML took me a long time because most of what I found was either plain wrong or maybe used to work for some other version in a galaxy far, far away.

iTorque especially seems to differ somewhat from the other versions. Some code I found worked after tweaking, and imho, most of code I found don't. iTorque was said to be based on Torque2D, so I thought hey there's this Platform Starter Kit (yes, I know it says it doesn't work with iTorque), but it might be similar enough to point me in the right direction, yes? So I bought that but well...the code in there seems worlds away to a beginner like me. Especially since most of it doesn't work (like the author said, I know, I know, anyway...). (Then it doesn't seem to work for TGB 1.7.5 either, and TGB's buttons don't seem to work...but that's another story.)

Then I found this book: "The Game Programmer's Guide to Torque" (copyright 2006) which I read once through but it started to feel like "The Theoretical Guide to Torque." Ok, maybe that's going a bit far. It's more like say, trying to use Visual Studio 2010 by reading a guide to Visual Studio 2003: The functions are there, but in all the wrong places with different syntax.

It really ain't helping. Just figuring out which sample code is the right version takes up a lot of time.

Don't get me wrong. I think iTorque is awesome! I had tears of moving when I first successfully deployed a prototype to iPhone. Oh! It really worked as advertised! Which I must say, is better than Adobe Flash's claim of working for iOS...so GarageGames kudos there.

Anyways, what I'm trying to say is, I do think there can be more help for us fans right? Again, this is just my personal experience. Maybe some other iTorque users understand all of this and has a secret Compendium of How to Do Everything in iTorque, in which case, please tell me where to get it.

So, help is welcome. Meanwhile, I shall go back to digging through the aforementioned documentation(s) and do some praying.
#3
08/19/2011 (5:44 am)
Ok mate, I see you're finding frustrating the first times with Torque. Mich and company are working hard to fill this gap for the newcomers, on the reference material.

In the meanwhile, plese, dont dispair, I will look into your questions again in a couple of hours, when found a moment after the friday gets sorted out.

I'll be back to you soon. (Edit: if doesn't someone beat me helping you)
#4
08/19/2011 (8:18 am)
Quote:1. How do I change the bitmap on a GuiBitmapButtonCtrl (and related Gui)?
The basic confusion I see here is that "Gui" elements, doesnt use imageMaps, they directly invoke bitmap files. "T2d" elements, on the other side, make use of predefined imageMaps.

So to change the bitmap of a gui element, you shall use:
highscore.bitmap = "route_to_bitmap/bitmap";
OR
highscore.SetBitmap("route_to_bitmap/bitmap");

Quote:2. How do I create a new imagemap using an in-game static sprite datablock? e.g. I have t2dImageMapDatablock enemyImageMap, how do create copies of this with just code?
This works rather the other way.
You define imageMaps (through t2dImageMapDatablock). Then the collection of t2dImageMapDatablocks works like a library for later use.

This imageMaps declarations, in time, are used by t2dStaticSprites which are the objects that you show on screen.

So, to create multiple on-screen similar sprites, you have to create the desired number of objects (t2dStaticSprite) all making use of the same imageMap.

Quote:3. Say I have a static sprite in the level called mySprite. How can I change that picture?
So, given the above answer, what you need in order to change the image of a sprite, is to change its imageMap field. And you can do that like this:
mySprite.imageMap = enemyImageMap;
OR
mySprite.SetimageMap(enemyImageMap);
Where "enemyImageMap" is a predefined t2dImageMapDatablock.


Hoping it helps!
#5
08/19/2011 (6:20 pm)
Thanks mate! You've helped me much. I also want to share with others a few other details that I've found for those who ran into the same issues. So in more detail:

1. How do I change the bitmap on a GuiBitmapButtonCtrl (and related Gui)?

I found the "route_to_bitmap" needs to be an exact path. So for example:

highscore.setBitmap("~/data/images/highscore.png"); // This works with t2dSceneObjects but not in GUI

highscore.setBitmap("/Applications/iTorque2D_1_4_1/MyProjects/MyGame/projectFiles/game/data/images/highscore.png"); // This works in GUI.

2. How do I create a new imagemap using an in-game static sprite datablock?
Below is the code that worked for me. First, remember to put the managed ImageMap datablock in the level:

%mySprite = new t2dStaticSprite();
%mySprite.SetImageMap(EnemyImageMap);
%mySprite.SetSize(64,64); // width and height
%mySprite.SetPosition(-50,-50); // x and y
myScene.addToScene(%mySprite); // myScene what I named the t2dSceneGraph in Object Tree

3. Say I have a static sprite in the level called mySprite. How can I change that picture?
Do as Novack says.