Solved Autoadjust camera on player spawn

Question that is answered or resolved.

kimono

Well-known member
Hi, I'm searching a method to have the camera directly on the player when the level begins.
For wide levels, if the player begins at x=1000+, the camera will scroll from left to right.
I tried to raise the camera scrollspeed and cameraxoffset but this funtion locks the screen.
Do you know how to have this camera on player spawn? Thank you all :)
 
I usually adjust camera position with script at beginning of level to go where player starts.
Here's example from Robo Magi:
Code:
spawn	Empty
@script
void main()
{
    void P1 = getplayerproperty(0, "entity");
    int x = getentityproperty(P1,"x");
    int y = getentityproperty(P1,"y");

    changeopenborvariant("xpos", x-320);
    changeopenborvariant("ypos", 690-y);
}
@end_script

This script acquires player 1's x y coords then adjusts camera position to player's position. 320 and 690 need to be defined on your own. 690 was found from trial n error while 320 is basically half of game's horizontal resolution.
That's for 1 player; For 2 or more players, the script could be more complex cause aside of acquiring each player's x y coords, balanced camera position (for covering all players) must be calculated from those coords.
 
Thank you, problem resolved by Bloodbane. 2 conditions for this script to work correctly: spawn at 0 coord and declared at the end of the level.txt in order to no move the other entities :).
 
Back
Top Bottom