Scenegraph & behaviors?
by amaranthia · in Torque Game Builder · 03/21/2008 (1:50 pm) · 1 replies
Well, I've found my problem, but I'm not sure how to solve it....
If I create the static sprites in my level (Village.t2d), everything works fabulously.
example:
However, in my game, all sprites are generated on the fly. To do this, I have to reference the current scenegraph. When I do this, the behavior doesn't work on objects that are mounted to the item that I'm trying to move.
example:
Any ideas?
If I create the static sprites in my level (Village.t2d), everything works fabulously.
example:
new t2dStaticSprite() {
imageMap = "RabbitTailImageMap";
frame = "0";
canSaveDynamicFields = "1";
Position = "22.459 -17.961";
size = "8.000 8.000";
MountOwned = "0";
MountInheritAttributes = "0";
mountID = "7";
mountToID = "6";
};
new t2dStaticSprite() {
imageMap = "RabbitShotImageMap";
frame = "0";
canSaveDynamicFields = "1";
useMouseEvents = "1";
Position = "22.459 -17.961";
size = "8.000 8.000";
WorldLimitMode = "BOUNCE";
WorldLimitMin = "-50.000 -37.500";
WorldLimitMax = "50.000 37.500";
LinkPoints = "0.000 0.000";
mountID = "6";
_behavior0 = "MouseDraggableBehavior centerOnMouse 1";
};However, in my game, all sprites are generated on the fly. To do this, I have to reference the current scenegraph. When I do this, the behavior doesn't work on objects that are mounted to the item that I'm trying to move.
example:
function scene::BuildSpecialImage(%this)
{
new t2dStaticSprite() {
sceneGraph = %this;
imageMap = "ShotGlassImageMap";
frame = "0";
canSaveDynamicFields = "1";
Position = "22.459 -17.961";
size = "8.000 8.000";
MountOwned = "0";
MountInheritAttributes = "0";
mountID = "7";
mountToID = "6";
};
new t2dStaticSprite() {
[b]sceneGraph = %this;[/b]
imageMap = "ChocolateShotImageMap";
frame = "0";
canSaveDynamicFields = "1";
useMouseEvents = "1";
Position = "22.459 -17.961";
size = "8.000 8.000";
WorldLimitMode = "BOUNCE";
WorldLimitMin = "-50.000 -37.500";
WorldLimitMax = "50.000 37.500";
LinkPoints = "0.000 0.000";
mountID = "6";
_behavior0 = "MouseDraggableBehavior centerOnMouse 1";
};
}Any ideas?
Associate amaranthia
To mount the object, you can't simply set the fields like I did above (unless you do this in a level file). You have to use the mount method. This was my fix:
First, I created my dynamically-generated objects in scene.cs. I removed mounts and links:
new t2dStaticSprite(Tail) { imageMap = "RabbitTailImageMap"; canSaveDynamicFields = "1"; Position = "22.459 -17.961"; size = "8.000 8.000"; }; new t2dStaticSprite(Rabbit) { imageMap = "RabbitImageMap"; canSaveDynamicFields = "1"; useMouseEvents = "1"; Position = "22.459 -17.961"; size = "8.000 8.000"; _behavior0 = "MouseDraggableBehavior centerOnMouse 1"; };Then, after I've done this, I mount Tail to Rabbit like this: