Game Development Community

Created an imagemap, but TGB doesn't like it?

by Dave "Jellybit" Freeman · in Torque Game Builder · 07/16/2006 (12:32 pm) · 11 replies

First, I create this datablock in datablocks.cs:

new t2dImageMapDatablock(p2_redyieldImageMap) {
      canSaveDynamicFields = "1";
      imageName = "Game/data/images/p2_redyield";
      imageMode = "FULL";
      frameCount = "-1";
      filterMode = "SMOOTH";
      filterPad = "0";
      preferPerf = "0";
      cellRowOrder = "1";
      cellOffsetX = "0";
      cellOffsetY = "0";
      cellStrideX = "0";
      cellStrideY = "0";
      cellCountX = "-1";
      cellCountY = "-1";
      cellWidth = "0";
      cellHeight = "0";
      preload = "1";
      allowUnload = "0";
   };
This is correct, and works, as TGB's level editor made it, and it displayed it fine within the level when using the level editor. So, I decide to try to display it using a .cs script instead of in the .lvl file. I create this function in the new .cs file:

function createToken()
{
        $p2_red = new t2dStaticSprite()
        $p2_red.setImageMap( p2_redyieldImageMap );
        $p2_red.setSize( "6 6" );
        $p2_red.setPosition( "-22.3 -28.3" );
        $p2_red.isSelectable = true;
        $p2_red.objectName = "p2";

}
Now, I grabbed this code directly from the object selection tutorial on TDN, only changing "$test" to "%p2_red", and editing the size/location. T2D hates what I've done, for some reason. It specifically has a problem with this line:
$p2_red.setImageMap( p2_redyieldImageMap );
Why is this? It's the exact name of the ImageMap I created earlier. In fact, I even tried plugging in a random name instead of "p2_redyieldImageMap", and it was fine with that! It just had a problem with the "setSize" line coming right after it. Again, I grabbed this code straight from the tutorial. I have no idea why T2D would cry about it. Any help would be greatly appreciated! Thank you.

#1
07/16/2006 (1:41 pm)
I think it's a problem with this line:

$p2_red = new t2dStaticSprite()

Not your image map. Change that line to:

$p2_red = new t2dStaticSprite()
{ 
     scenegraph = sceneWindow2D.getSceneGraph();
};

This assumes that your scene window is called sceneWindow2D (which it is, by default)
Hope that helps,
Chris
#2
07/16/2006 (3:06 pm)
Oops!!! Sorry, I was trying different stuff to get it to work, and forgot to change it back. Here's REALLY what my createToken function looks like:

function createToken()
{
        $p2_red = new t2dStaticSprite() { sceneGraph = t2dScene; };
        $p2_red.setImageMap( p2_redyieldImageMap );
        $p2_red.setSize( "6 6" );
        $p2_red.setPosition( "-22.3 -28.3" );
        $p2_red.isSelectable = true;
        $p2_red.objectName = "p2";

}
Yikes. Sorry for the confusion. I'll try what you suggested though! Maybe that will help. The above SHOULD work though, right? I mean, it's exactly what's in the tutorial. If it doesn't work, maybe the tutorial needs updating?

EDIT:
It worked!!! Thanks a lot, Chris! Hmmm, I guess the tutorial DOES need updating. I wonder why this worked, but the tutorial didn't... I'm not really sure of the logic behind it. Thanks again!

EDIT2:
Ah, I think I see. Maybe it used to be called t2dScene by default, but no longer? I'll see if I can find the name of the sceneGraph and use it directly (like the code above) instead of using your code. Thanks again!
#3
07/16/2006 (3:15 pm)
Hi Dave,
What exactly does the console say? It seems like it should work.
Chris
#4
07/16/2006 (3:19 pm)
Heh, the sceneGraph the console gave me was 3703! Weird!!! I thought it'd be text, like "t2dScene" in the tutorial... Hmmm... I'll have to look up what a sceneGraph even is... hahah I think I have no clue anymore.
#5
07/16/2006 (3:24 pm)
Glad you got it working :)
#6
07/16/2006 (7:23 pm)
Ok, I'm having more troubles now. I need "t2dScene" to work, as the tutorial teaches. What is "t2dScene" called nowadays? If it's called the same thing, why does TGB say it's invalid wherever used?

Here's the line in the tutorial that's giving trouble:
%objList = t2dScene.pickPoint(%worldPos);
The console gives this error:
/gameScripts/mouse.cs (24): Unable to find object: 't2dScene' attempting to call function 'pickPoint'
It doesn't get "t2dScene". That's what was causing the error that started this thread in the first place, so I think I should find out what it changed to. What's it called nowadays? Thanks!

EDIT: Nevermind :) Found the answer here. Er... sorta. No recommended solution, but now I see that there's a problem.
#7
07/17/2006 (3:21 am)
It's strange that sceneWindow2D.getScenegraph() won't work in all situations for you - is the name of the t2dSceneWindow different where you want to use pickPoint()?

One thing you could try would be to name your scenegraph in the LevelBuilder. Wtihout selecting any objects, choose the edit tab and go to sceneGraph Scripting. Enter a name into the name field and give it a shot. I think though that this would have to be done for every level. I could be wrong, but I believe that TGB does its level switching by switching the scenegraph in the window.

Chris
#8
07/17/2006 (7:04 am)
@Dave - As I stated in the thread you linked to, you can just name your scenegraph. It's no longer named by default (I'm assuming it must have been at one point). As Chris said, SceneWindow2D.getSceneGraph should work for you, but if you really want to use t2dScene, just name your scenegragph t2dScene.

From my original post:

"The scenegraph is created in the level file itself, so you would have to edit that to change it's name (it's not named by default) or give it a name somewhere else, such as your startGame function, by calling [scenegraph].setName([name])."

So, either...

A) Change the name (Chris is right on this one, I forgot you could name it in the Level Builder without having to edit the level file).

-OR-

B) Name the scenegraph elsewhere via setName...
...
SceneWindow2D.getSceneGraph().setName(t2dScene);
...

The first method that Chris suggested might be easier. Good luck.
#9
07/17/2006 (7:11 am)
Also, that number you saw when you echo'd the scenegraph was correct. It was the Object ID of the scenegraph. Any object you echo like that will print out an Object ID. You can actually call functions on an ID just like you would a variable or name (though you wouldn't want to because ID's can change between multiple executions). If you want the name of an object you can use %object.getName(). If you want to know more about the object you can call %object.dump() or %object.dumpClassHierarchy() and they will spam the console with all the methods and fields on that object, or the class hierarchy of the object respectively.

Edit: Note that getName will not always return a name because objects aren't named by default.
#10
07/17/2006 (11:18 am)
@Chris: Wow! that was so easy! It worked beautifully. Thank you again!

@Thomas, Ah! I couldn't figure out how to do that exactly... because I didn't think you could use another ".action()" after a "subject.action()". Thank you! Oh, and in my post above, when I said that there was no recommended solution, that wasn't to say you weren't of any help. I posted that before I even posted in the other thread. Thank you!
#11
07/17/2006 (8:21 pm)
I figured you mightve missed it because you posted and edited on the 16th and I answered the post you linked to on the 14th, so I was just repeating it here. No worries.