PDA

View Full Version : Static Camera



Pleng
03-21-2008, 08:47 AM
One of the first problems I came across when creating my first game was a way of getting the camera to a fixed position on certain levels (which are designed to be single-screen), and prevent it from following the players movement.

To resolve the issue I placed a new object on the map, well outside of the visible playing area and attached the following script:



function OnInit() //run upon initialization

// Stop the camera tracking the player
GetCamera:SetEntityTrackingByID(C_ENTITY_NONE);

// ooops! Because we stopped tracking the player, and we previously used
// warp points the game reverted to the start map
// best bring focus back to this map really!
// remember to replace "Elevation - Easy (Level 1)" with your map name!
GetMapManager:SetActiveMapByName("Elevation - Easy (Level 1)");

// Scale and position the camera
GetCamera:SetScale(Vector2(0.52,0.52));
GetCamera:SetPos(Vector2(-1523.00,-230.00));


end

function OnPostInit() //run during the entity's first logic update

// we don't put any code here, as the entity never gets displayed on the
// screen!

end

function OnKill() //run when removed

end



To fins out the correct values for the Vector 2 in SetPos, you need to set the screen up in the editor as you would like it displayed on screen, then bring up the console and type:



LogMsg (GetCamera:GetPos())


You can get the current zoom level by clicking on "Options, Map Properties" from the editor.

sirlich
10-08-2009, 12:38 PM
--- That helped... though it would not work inside of the OnInit function... (used copy/paste so syntax was correct) Had to place the code at top of the script without the function/end around it -- not sure why that worked but the OnInit function wouldn't

Pleng
12-10-2010, 01:37 PM
If you have a line:

AssignPlayerToCameraIfNeeded(this);

then you'll need to remove it or comment it out