Game Development Community

Tell a GuiSrpiteControl who's his parent

by DiegoGdVU · in Torque 2D Beginner · 10/18/2013 (6:59 pm) · 2 replies

I just want to tell the GuiSpriteControl below that %guiParentControl is his parent, right now the sprites are filling the whole screen, i'm not using taml becuase the ammount of spriteCtrl i'm creating is unknown at compile time, i'm trying to create a health system similar to The legend of Zelda.


function createHP(%amount)
{
	%posX=10;
	%posY=10;
	%guiParentControl = new GuiControl()  
	{
		Name="BackgroundMenu"  ;
		canSaveDynamicFields="0"  ;
		isContainer="1"  ;
		Profile="GuiDefaultProfile"  ;
		HorizSizing="right"  ;
		VertSizing="bottom"  ;
		Position="0 0"  ;
		Extent="1024 768"  ;
		MinExtent="8 2"  ;
		canSave="1"  ;
		Visible="1"  ;
		Active="1"  ;
		hovertime="1000"  ;
	};
    
	Canvas.pushDialog(%guiParentControl);
	//echo(%guiControl.getparent());
	
	for(%i=0;%i<%amount;%i++)
	{
		%hpCrystal= new GuiSpriteCtrl()
		{
			Name="genericLifeCrystal"  ;
			canSaveDynamicFields="0"  ;
			isContainer="0"  ;
			Profile="GuiDefaultProfile";  
			HorizSizing="relative"  ;
			VertSizing="relative"  ;
			Position=%i*%posX SPC %posY ;
			Extent="10 10";  
			MinExtent="8 2"  ;
			canSave="1"  ;
			Visible="1"  ;
			Active="1"  ;
			hovertime="1000";  
			Image="mainModule:gems";
			setImageFrame=2;
		};		
		
		Canvas.pushDialog(%hpCrystal);
	}
	//echo(%hpCrystal.getparent());
	
}

#1
10/18/2013 (9:47 pm)
Try:
%guiParentControl.addGuiControl(%hpCrystal);

and remove
Canvas.pushDialog(%hpCrystal);

I have some gui examples in my project: https://github.com/practicing01/Dots_and_Crits/blob/master/modules/Dots_and_Crits/scripts/Load_Play/Load_Cards.cs
#2
10/19/2013 (12:46 pm)
Thanks that worked, only thing i dont know is thatmy sprites are translucid/tranparent for some reason.