Game Development Community

Linked ImageMap question

by Keith Goddard · in Torque Game Builder · 11/07/2011 (3:55 am) · 5 replies

I was pointed towards a nifty resource using Linked ImageMaps & particle effects (http://www.garagegames.com/community/blogs/view/19807) and it made me wonder if I could use a linked imagemap to solve another problem I'm dealing with. I don't really know what can be done with these things, so I'm hoping someone on here can give me suggestions.

Firstly, what I'm trying to do is this: I want to dynamically create "pickup items" in a platform game, where the pickup item is represented by an image of a number (e.g. a graphical representation of the number 67). Now, I'm going to do this repeatedly throughout the game, and I'm hoping to generate the "numbers" randomly.

I could, of course, create hundreds of images to represent various numbers, but this seems like an inefficient way of doing it. If I have a linked imagemap representing digits 0-9, could I dynamically create a static image using whichever linked imagemap frames are required? I guess the real question 'm trying to ask is can I create a single static image which utilizes 2 or 3 frames from the linked imagemap, side by side?

#1
11/07/2011 (6:08 am)
Glad you like my resource; I think it's pretty nifty too!

I don't have time to provide a code sample right now but I think you'd want to create a custom script object to do this that you can set a numeric value on and it would do pretty much what I do in the resource you mentioned.

Pseudocode:
%pickup = new t2dScriptObject()
{
  class = "PickUp";
  ...
};
%pickup.createPowerUp(123, "25 25");

function PickUp::createPowerUp(%this, %newValue, %position)
{
   //loop through value and offset the images positions
   for(%i = 0; %i < strlen(%newValue); %i++)
   {
      %xPos = getWord(%position, 0) + (%i * 5);
      %yPos = getWord(%position, 1);
      %newPos = %xPos SPC %yPos; 
 
      //parse the value with the base image map name
      %tempImageMapName = pickupImageNameBase  @ getSubStr(%score,%i,1);
      %this.images[%i] = new t2dStaticSprite() {  
           imageMap = %tempImageMapName;  
           frame = "0";  
           Position = %newPos;  
           size = "5 5";  
           Layer = "0";  
           BlendIgnoreTextureAlpha = "0";  
           mountID = "2";  
           };  
   }
}
...
function PickUp::onCollision(...)
{
...
}

Hope that helps! If you take a crack at it and post back with problems, I'm sure I can help out.
#2
11/07/2011 (6:14 am)
Thanks, Patrick. It's guys like you who make it possible for us beginners to learn Torque despite the somewhat incomplete documentation.
#3
11/07/2011 (6:29 am)
Thanks Keith; that's very kind of you. I've found the forums the most valuable means of learning Torque; especially when very new to it. Persistence is key! I think the docs will be getting better though if the work on T3D is any indicator of where it's going.

Good luck!
#4
11/08/2011 (4:03 am)
I did need to make some adjustments to your pseudocode, Patrick, but I'd not have managed to get this working without your assistance.

In case anyone tries this themselves, I've included the code I used to "generate" the pickup item with the graphical images, and the numerical value of the item.

function NumbersPickupBehavior::createPickupUp(%this, %newValue,%position,%scenegraph)
{
   //loop through value and offset the images positions
   for(%i = 0; %i < strlen(%newValue); %i++)
   {
      %xPos = getWord(%position, 0) + (%i * 3);
      %yPos = getWord(%position, 1);
      %newPos = %xPos SPC %yPos; 
 
      //parse the value with the base image map name
      %this.images[%i] = new t2dStaticSprite() {  
           imageMap = numbersLinkImage; 
           frame =  getSubStr(%newValue,%i,1);
           scenegraph = %scenegraph;
           //frame = "0";  
           Position = %newPos;  
           size = "3 3";  
           Layer = "0";  
           BlendIgnoreTextureAlpha = "0";  
           mountID = "2";  
           }; 
      
   }
   %this.numberValue = %newValue;
}
#5
11/08/2011 (5:24 am)
Slick! Glad it's working for you Keith.