Game Development Community

About mounting camera & tilemap wrap

by Hugeone · in Torque Game Builder · 09/21/2005 (8:16 am) · 9 replies

I have mounted the camera with player object, and I can move the player freely.

But I find that the tilemap's wrap property is invalid. I can move to the edge of the tilemap.

If I donnot use the mount function, the tilemap can scroll wrappedly.

About the question, please give me a suggestion or a method, thanks in advance !

-- HugeOne

#1
09/21/2005 (4:27 pm)
I had the same problem. The solution can be found here.
#2
09/23/2005 (8:51 am)
@Phillip
I am sorry to tell you that the solution is invalid.
I donnot konw whether is my code error. If you have free time, I can send my code to you through a email.

If the other friends have some solution, please give me a suggestion.
Thanks a lot !
#3
09/23/2005 (9:32 am)
You ought to post your code up here :) That way if someone gets time they can grab it and test it and see if they can help.
#4
09/23/2005 (7:06 pm)
@Matthew
I will post my code here.

function WorldLayer::loadTileMap()
{
	// *******************************************************
	// Create Tile-Map Scroller.
	// *******************************************************
	%scrollerMap = new fxTileMap2D() { scenegraph = t2dSceneGraph; };
	
	// Load Tile-Map.
	%scrollerMap.loadTileMap("~/client/maps/seaage.map");
	$SeaLayer = %scrollerMap.getTileLayer( 0 );
   
	%layerSizeX = getWord( $SeaLayer.getTileCount(), 0 )*16;
	%layerSizeY = getWord( $SeaLayer.getTileCount(), 1 )*16;

	//计算其中心坐标点
	%LeftTopStartX = (%layerSizeX-100)/2;
	%LeftTopStartY = (%layerSizeY-75)/2;

	$SeaLayer.setPosition( %LeftTopStartX SPC %LeftTopStartY );
	$SeaLayer.setSize( %layerSizeX SPC %layerSizeY );
	$SeaLayer.setTileSize( "16 16" ); //BLOCK 128*128像素
	$SeaLayer.setLayer( 31 );
	$SeaLayer.setWrap( true, true );
	
                //----------------------------------------------------------------
	$WorldMapLayer = %scrollerMap.getTileLayer( 2 );

	//检测获取到的层的尺寸
	%layersizex = getWord($WorldMapLayer.getTileCount(), 0) * 16;
	%layersizey = getWord($WorldMapLayer.getTileCount(), 1) * 16;

	%startPosX = (%layersizex-100)/2;
	%startPosY = (%layersizey-75)/2-106*16;

	$WorldMapLayer.setPosition( %startPosX SPC %startPosY );
	$WorldMapLayer.setSize( %layersizex SPC %layersizey );
	$WorldMapLayer.setTileSize( "16 16" ); //BLOCK 128*128pixel
	$WorldMapLayer.setGroup( 3 );
	$WorldMapLayer.setLayer( 15 );

	$WorldMapLayer.setCollisionMasks( $playerCollisionGroups, $playerCollisionLayers );
	$WorldMapLayer.setCollisionActive(true, true);    
	$WorldMapLayer.setCollisionPhysics(true, true);

	$WorldMapLayer.setWrap( true, true );
}

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" );

	// Add your custom code here...

	//Youll see the cyan border
	t2dSceneGraph.setDebugOn( BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5));

	// load tilemap
	WorldLayer::loadTileMap();

	//setupWorldMapBlock();
	setupShip();

	setupSelectObjectBorder();
	mouseInit();      

	// mount the camera to shipElement
	sceneWindow2D.mount( $shipElement );
	
	// Setup Ship Controls.
	setupShipControls();
}

function createShipElement()
{
   $shipElement = new fxStaticSprite2D()  { scenegraph = t2dSceneGraph;  };
   $shipElement.setGroup( 1 );
   $shipElement.setLayer( 10 );

   $shipElement.setPosition( "0 0" );
   $shipElement.setSize( "8 8" );
   $shipElement.setImageMap( ShipElementImageMap, 2 );

   $shipElement.setCollisionActive( true, true );
   $shipElement.setCollisionPhysics( true, true);
   $shipElement.setCollisionMaterial( standardMaterial );
   $shipElement.setCollisionPolyCustom( 4, "-1 0 -0.1 -0.6 0.98 0.15 -0.1 0.7" );
   $shipElement.setCollisionMasks( $enemyCollisionGroups, $enemyCollisionLayers );
   $shipElement.setCollisionCallback( true );

   $shipElement.tag = "ShipElement";
}

continued ...
#5
09/23/2005 (7:07 pm)
When we move the shipElement, I use the code following this.

//-----------------------------------------------------------------------------
// Ship Player Up.
//-----------------------------------------------------------------------------
function shipUp()
{
   // Set it moving up.
   $shipElement.setLinearVelocityX( 0 );
   $shipElement.setLinearVelocityY( -$movementSpeed );
}

//-----------------------------------------------------------------------------
// Ship Player Up (Stop).
//-----------------------------------------------------------------------------
function shipUpStop()
{
   // If we're moving up then nullify any upward movement.
   if( $shipElement.getLinearVelocityY() < 0 )
      $shipElement.setLinearVelocityY( 0 );
}

//-----------------------------------------------------------------------------
// ship Player Left.
//-----------------------------------------------------------------------------
function shipLeft()
{
   // Set it moving left.
   $shipElement.setLinearVelocityX( -$movementSpeed );
   $shipElement.setLinearVelocityY( 0 );
}

//-----------------------------------------------------------------------------
// Ship Player Left (Stop).
//-----------------------------------------------------------------------------
function shipLeftStop()
{
   // If we're moving left then nullify any leftward movement.
   if( $shipElement.getLinearVelocityX() < 0 )
      $shipElement.setLinearVelocityX( 0 );
}

//-----------------------------------------------------------------------------
// ship Player Right.
//-----------------------------------------------------------------------------
function shipRight()
{
   // Set it moving right.
   $shipElement.setLinearVelocityX( $movementSpeed );
   $shipElement.setLinearVelocityY( 0 );
}

//-----------------------------------------------------------------------------
// Ship Player Right (Stop).
//-----------------------------------------------------------------------------
function shipRightStop()
{
   // If we're moving right then nullify any rightward movement.
   if( $shipElement.getLinearVelocityX() > 0 )
      $shipElement.setLinearVelocityX( 0 );
}

//-----------------------------------------------------------------------------
// ship Player Down.
//-----------------------------------------------------------------------------
function shipDown()
{
   // Set it moving down.
   $shipElement.setLinearVelocityX( 0 );
   $shipElement.setLinearVelocityY( $movementSpeed );
}

//-----------------------------------------------------------------------------
// ship Player Down (Stop).
//-----------------------------------------------------------------------------
function shipDownStop()
{
   // If we're moving down then nullify any downward movement.
   if( $shipElement.getLinearVelocityY() > 0 )
      $shipElement.setLinearVelocityY( 0 );
}


Question:
If I use
Quote:sceneWindow2D.mount( $shipElement );
, tilemap's wrap property is invalid. The tilemap does not scrolls wrappedly.
When I dismount the camera with the shipElement, tilemap's wrap property is effective.


About these code, I think it must have some tricks, please give me a suggestion . Thanks in advance.
#6
09/24/2005 (11:17 am)
Anybody can tell me why not about this matter ?
I am waiting for a reply , thanks .
#7
09/24/2005 (11:41 am)
Need to give folks some time! It's the weekend here (11:41 AM on the east coast), and our board participation is normally lower on the weekends.
#8
09/25/2005 (10:59 am)
Wrapping doesn't work if you mount the camera to the player. It only works if you scroll the tile map (setAutoPan()) which basicly keeps the camera in one place.

-Peter
#9
09/25/2005 (10:26 pm)
@Peter

I know what you said. Thanks at first.
But I think, the T2D engine will be better if it supports the function.
Now ,it does not support it , I will design my game project again using "setAutoPan()".

If anybody can find a solution about it ,please tell me . Thanks.

Thanks everybody.