Game Development Community

Changing a Sprites class. [solved]

by Max Kielland · in Torque Game Builder · 01/18/2013 (1:10 am) · 4 replies

Hi,

Here is a short demo to illustrate the problem:

function MyActiveClass::onUpdate(%this) {

  // Do stuff
  
  if( ... some logic ...)
    %this.class = "";
}

function MyActiveClass::Create() {

  %sprite = new t2dStaticSprite()
    {
      // ...Initialise some params...
      class = "MyActiveClass";
    };

  return %sprite;
}

Everything works fine so far, the sprite is created and the MyActiveClass::onUpdate is called periodically.
But at some point I don't want this sprite to be active and stop to call the onUpdate callback. My thought was that if I remove/change the class it will no longer call MyActiveClass:onUpdate. But it continues to call onUpdate even after I changed the class name.

How do I remove the onUpdate calls for a single sprite?

#1
01/18/2013 (6:45 am)
You can try setting %sprite.active = false - theoretically this should prevent that object from being updated. If that doesn't work then you might be stuck with bailing from the onUpdate() if the sprite is not active.
#2
01/18/2013 (6:47 am)
Well you had to turn on the 'onUpdate' callback for each object didn't you? Just have that object turn it off
%this.disableUpdateCallback();

OR if that doesn't work just have your disabling logic skip the rest of the function with something like the 'return;' keyword.
#3
01/18/2013 (7:03 am)
Duh!?!

You are absolutely right Alpha-Kand! I guess I have been up for to long :P

%this.disableUpdateCallback();
Did exactly what I was looking for.

Thank you both.
#4
01/18/2013 (11:58 am)
Sorry to bump in.
Alpha I sent you an email.
Please reply :)