Game Development Community

Issue with addLinkPoint()

by Phil Shenk · in Torque Game Builder · 06/21/2005 (5:30 pm) · 6 replies

I saw some stuff posted about this on another thread, and it seemed to be resolved. I just can't get it to work though. Here's an entire piece of stripped down code that doesn't seem to make a proper linkPoint

function initialiseClient()
{
	// Initialise Base Client.
	InitBaseClient();
	
	// Key-Bindings.
	GlobalActionMap.bind(keyboard, tilde, ToggleConsole);
	GlobalActionMap.bindCmd(keyboard, "alt enter", "", "toggleFullScreen();");
	
	// Initialise Canvas.
	InitCanvas("T2D");

	exec("./demoDatablocks.cs");
	
	// Load-up Datablocks.	
	exec("./datablocks.cs");
	// Load-up GUIs.
	exec("./mainScreenGui.gui");
	// setup stuff
	//exec("./setup.cs");
	
	// Set GUI.
	Canvas.setContent(mainScreenGui);
	// Set Cursor.
	Canvas.setCursor(DefaultCursor);
	
	// Setup Scene.
	setupT2DScene();
}

function destroyClient()
{
	// Destroy fxSceneGraph2D.
	if ( isObject(t2dSceneGraph) )
	t2dSceneGraph.delete();	
}

function SetupImages()
{
	// Set up the image datablocks
	datablock fxImageMapDatablock2D(playershipImageMap)
	{
		mode = full;
		textureName = "~/client/images/ship";
	};
	
	datablock fxImageMapDatablock2D(crossHairImageMap)
	{
		mode = full;
		textureName = "~/client/images/crossHair";
	};	
}

function CreatePlayer()
{
	$player = new fxStaticSprite2D() {scenegraph = t2dSceneGraph;};
	$player.setImageMap( playershipImageMap );
	$player.setPosition("0 0");
	$linkIndex1 = $player.addLinkPoint("0 0");
	
	echo("player position set at :" @ $player.getPosition() );
	echo("$linkIndex1 set at :" @ $player.getLinkPoint($linkIndex1) );
	echo("$linkIndex value is :" @$linkIndex1);
	$mousePos = "0 0"; //just start it at something, before a mousemove event
	
	$linkMarker = new fxStaticSprite2D() {scenegraph = t2dSceneGraph;};
	$linkMarker.setImageMap( crossHairImageMap );
	$linkMarker.setPosition( $player.getLinkPoint($linkIndex1) ); // set the cross hair sprite to the linkPoint's position

}

// --------------------------------------------------------------------
// Setup T2D Scene.
// --------------------------------------------------------------------
function setupT2DScene()
{
	// Create fxSceneGraph2D.
	new fxSceneGraph2D(t2dSceneGraph);
	
	// Associate Scenegraph with Window.
	sceneWindow2D.setSceneGraph( t2dSceneGraph );
	
	// Set Camera Position to be centered on (0,0) with
	// view width/height of (100/80).
	sceneWindow2D.setCurrentCameraPosition( "0 0 100 75" );

	dbgsetparameters(80,"test"); // set the debug parameters so Brain Edit can connect
	
	SetupImages();
	CreatePlayer();

	schedule (33, 0, "mainLoop");

}


function mainLoop()
{
	$player.setPosition( $mousePos );
	$linkMarker.setPosition( $player.getLinkPoint($linkIndex1) );
	//echo( "p = " @ $player.getPosition() @ " m = " @ $mousePos @ "  r = " @ $player.getLinkPoint($linkIndex1) );
	schedule (33, 0, "mainLoop");
//
}

function sceneWindow2D::onMouseMove( %this, %modifier, %worldPosition, %mouseClicks )
{
	$mousePos = %worldPosition;
}

look in the console, and the value echoed out seems to be out of range. Could be I'm doing something wrong, but the addLinkPoint() function seems to be wiggy.

FYI, I used to have the SetupImages() and CreatePlayer() functions in a separate .cs file. For some reason when they were out there, the addLinkPoint() would work, but only when set it to ("0 0"). Some other value like ("1 1") would either be ignored or incorrect (the example of "1 1" would put the point directly above the player sprite.

#1
06/21/2005 (7:52 pm)
I believe this is going to be fixed in the next release, but currently you must make a call to setSize() before you can properly add linkpoints.
#2
06/21/2005 (8:24 pm)
Wow, so I'm not crazy. I was tearing my hair out. Seems like this is true for mounting also, since that wasn't working either.

Works now though! Thanks.
#3
06/21/2005 (8:32 pm)
Should this be in the bug forum? I didn't see this specific issue...
#4
06/22/2005 (1:03 am)
Phil,

This is a simple one to fix and will indeed be included in the next update.

Change the fxPhysics2D constructor in "fxPhysics2D.cc" to...

//-----------------------------------------------------------------------------
// Constructor.
//-----------------------------------------------------------------------------
fxPhysics2D::fxPhysics2D() :	T2D_Stream_HeaderID(makeFourCCTag('2','D','P','M')),
						T2D_Stream_Version(0X00000002),
						mLocalSerialiseID(1),
						mInitialised(false),
						mRefObjectId(0),
						mRefMetaString(StringTable->insert("")),
						mSize(10.0f, 10.0f),
						mHalfSize(5.0f, 5.0f),
						mDensity(defaultDensity),
						mCollisionScale(1.0f, 1.0f)
{
	// Set Vector Associations.
	VECTOR_SET_ASSOCIATION( mCollisionPolyList );
	VECTOR_SET_ASSOCIATION( mCollisionPolyBasisList );
}

The bad here is an uninitialised "mHalfSize" class member. Setting the objects size will initialise it. Without initialisation, you'll get garbage mounts/links etc.

Sorry for the confusion here.

EDIT: This isn't the exact change in the update (because it contains a nasty class-member initialisation dependancy) as this is tangled-up in many other changes but this will work in v1.0.2.

- Melv.
#5
06/22/2005 (8:06 am)
Hey Melv,

Thanks! I don't have the build environment set up, so I'll wait for the update.

Glad you're feeling better, btw.

-Phil
#6
06/22/2005 (11:39 am)
Thanks Phil. :)

- Melv.