Game Development Community

setLinearVelocityX on Gui Elements

by Aditya Kulkarni · in Torque Game Builder · 02/04/2010 (6:26 am) · 6 replies

Is there any way I can do that without using guiT2DObjectCtrl or schedules?

#1
02/04/2010 (11:59 pm)
In general, you've got 2 options. One is to look for the Plastic Games resource that has animations for the GUIs. The other is to attach the GUI to a scene object and call setLinearVelocityX on that scene object.

The first requires a source license, so you'll probably want the second.
#2
02/05/2010 (3:39 am)
Problemo...

I first do this
Canvas.pushDialog(dialogue);
createDialogueObj();

'createDialogueObj' creates a new static sprite, attaches it to the gui object 'mainDialogueHud' and sets the X velocity as 50

function createDialogueObj() {
   $dialogueObj = new t2dStaticSprite() {
    imageMap = "image1ImageMap";
    frame = "0";
    canSaveDynamicFields = "1";
    Position = "-114 0";
    size = "6 11";
    layer = "0";
    mountID = "3";
    class = dialogueObj;
  };
  
  $sceneGraph = sceneWindow2D.getSceneGraph();
  $sceneGraph.addToScene($dialogueObj);
  
  $dialogueObj.attachGui(mainDialogueHud,sceneWindow2D,false);
  $dialogueObj.setPositionTarget("-7 0", true, true, false, 0.01);
  $dialogueObj.setLinearVelocityX(50);
}

function dialogueObj::onPositionTarget(%this) {
   error ("TARGET POSITION REACHED!");
   %this.setLinearVelocity(0,0);
   $dialogueObj.detachGui();
}

function dialogueMouseArea::onMouseDown() {
   echo ("DIALOGUE MOUSE AREA CLICKED!");
   $dialogueObj.detachGui();
   $dialogueObj.safeDelete();
   Canvas.popDialog(dialogue);
}

Problem is that Canvas.popDialog doesn't work, not even from the console. I did dialogue.isAwake() and it returned a '0', but the gui is still being shown on the screen.
#3
02/05/2010 (3:48 am)
Tried it again.

dialogue.isAwake() returns 0 AFTER calling Canvas.popDialog(dialogue), but the gui actually remains on screen.
#4
02/05/2010 (6:36 am)
It looks like there might be 2 things going on here:

1) You attach "mainDialogueHud" to the sprite but try to remove just "dialogue".

2) I think that when you attach, it gets owned by the scene window. You might try "sceneWindow2D.remove(mainDialogueHud);". That should be enough, but it may not hurt to do a "mainDialogueHud.setVisible(false);".
#5
02/05/2010 (7:00 am)
'mainDialogueHud' is a child to 'dialogue', so I thought removing dialogue would do it.

sceneWindow2D.remove works like a charm. I was doing $dialogueObj.detachGui() before popDialog, so shouldn't that remove it from the scenewindow?

William strikes again...Thanks man!
#6
02/05/2010 (4:17 pm)
DetachGui is just detaching it from the scene object, but still leaves it as a child of the scene window.

Anyway! Glad it all worked!