Game Development Community

Scriptobjects & sprites

by John Coyne · in Torque Game Builder · 04/08/2006 (11:50 am) · 1 replies

Hi.
I have a scriptobject with a sprite inside it. I want to set some properties of that sprite, the 1st being that it should respond to mouse clicks later.


function rocket::onAdd(%this)
{
   %this.sprite = new t2dStaticSprite() {sceneGraph = t2dScene;};
   %this.sprite.setSize(%this.size);
   %this.sprite.setPosition(%this.home);
   //%this.sprite.setImageMap(%this.image);
   %this.sprite.setImageMap("genericBaseImageMap");
   //%this.dump();
   //create random trajectory
   %this.sprite.setLinearVelocityX(getRandom(-10,10));
   %this.sprite.setLinearVelocityY(getRandom(-10,10));
   %this.sprite.clickable = true;  //*********<--------here*******
   %this.controller(%this);
}

later on, when I'm processing mouse clicks like this:

function sceneWindow2D::onMouseDown(%this, %mod, %worldPos, %mouseClicks)
{
   %objList = t2dScene.pickPoint(%worldPos);
   %objCount = 0;
   %objCount = getWordCount(%objList);
   echo(%objCount @ " objects in list");
   for(%cnt = 1; %cnt <= %objCount; %cnt++)
   {
      %obj = getWord(%objList, %cnt);
      if(%obj.clickable == true)
      {
         %obj.dump();
      }
      else
      {
         echo("Clickable = " @ %obj.clickable);
      }
   }
}

It seems that "clickable" either isnt getting set, or isnt getting read properly (returns nothing).
Is there any reason this would be the case?

Also, my plan is to copy the ID of the scriptobject into its own sprite, so i can call a function in the script object to handle clicks on the sprite. Is this a good way to do this?

#1
04/08/2006 (12:49 pm)
Nevermind, Paul Dana pointed out the problem on IRC, turns out it was the for loop starting at 1 instead of 0.