monkey island camera movement style

Started by Giowe, Thu 27/01/2011 11:34:43

Previous topic - Next topic

Giowe

in ags, when I have a room larger than the screen resolution, how do I make the camera follow the player like in Monkey Island when the player gets near the edge of the screen, instead of what happens with the default settings?

GarageGothic



Ali

Please let me know how you get on, because I think the edge-of-screen part of the module might need tuning dependent upon character size/walking speed.

Giowe

now i simply downloaded the modul and runned the program and it crash... :\

monkey0506

That's helpful. Thanks for letting us know anything at all about the crash so that we can effectively determine the reason why the crash took place and the necessary steps to resolve it..oh, wait.

subspark

Haha. Awe go easy on the new kid monkey! It's probably his first time in the shark pool that is the tech forum.

Sparky.

Ali

You need to create certain custom properties (PxPos etc...) for the module to work. They are outlined in the module header, you can read the module thread for more information.

If that's not the problem, please let me know.

iamlowlikeyou

You can also try to switch off the player character's function "movement follow animation" (or something similar) - that makes the scrolling smooth... However you must then adjust the movement speed and maybe fiddle with the animation, to avoid "gliding" effect.
So far it's working fine for me, and I find it an easier way to get smooth scrolling, than importing a module.
I don't know if there's a backside I haven't discovered yet, though.

Ali

That's a different kind of 'smooth' movement to the one the module provides. The module provides easing in and out of camera movement, so that it does not stop dead the instant the character does, which can be jarring at higher resolutions.

However, it's not the smoothness Giowe wanted, it's the scrolling happening near the edge of the screen. I recently worked that in to the module, and I'm looking for feedback on how it works.

Giowe

ok, it works perfectly as i want. i have one last problem. in monkey style camera the movement was all at the same speed, in your version we have a beautifull fade in and fade out of the camera movement that i don't want. i don't know if i well explain myserf, in other words, this is you camera movement  --> ---- --- -- - - - - - - - - - - -- --- ----
this is the movement that i want --> - - - - - - - - - - - - - - -

Ali

Ah... then I'm afraid this module can't help the easing in and out is what it's designed to do. Actually, I thought MI used easing in/out  - I'm sure some of the LucasArts games did.

Anyway, you could modify this simple code to get an approximation of what you want:

Code: ags
int targetX;

int targetY;



function on_event (EventType event, int data) {

  if (event == eEventEnterRoomBeforeFadein){
    
    targetX = player.x-System.ScreenWidth/2;
    
    targetY = player.y-System.ScreenHeight/2;
    
  }

}


function repeatedly_execute_always(){
  
  SetViewport(targetX,  targetY);
  
  
  
  if (player.x>GetViewportX()+(System.ScreenWidth-100)) {
    
    if (targetX < Room.Width-System.ScreenWidth) targetX = targetX+1;
  }
  
  if (player.x<GetViewportX()+100) {
    
    if (targetX > 0)targetX = targetX-1;
  }
  
  
    if (player.y>GetViewportY()+(System.ScreenHeight-70)) {
    
    if (targetY < Room.Height-System.ScreenHeight) targetY = targetY+1;
  }
  
  if (player.y<GetViewportY()+70) {
    
    if (targetY > 0)targetY = targetY-1;
  }
  
  
  
}


I've only tested it at 320x200 and with horizontal scrolling. I don't know how well this will work for very wide rooms. In monkey island the scrolling begins when the player is near the edge and continues until they are in the centre of the screen. This code won't do that, but it's a start.

Giowe

//Backgorund sliding: LEFT MOVEMENT IS BUGGED, THERE IS A DELAY ..... TO DO: MAKE THE CHECK FOR THE ROOM WIDTH
//-----------------------------------------------------------------------------
//Pseudo const
int S_VELOCITY = 3;
int S_DISTANCE = 160;
//-----------------------------------------------------------------------------
//Global var
int xCameraCenter;
int halfScreenSize;
//State var
int movementVersor = 1; // 1 for right movement -1 for left movement
bool enableMovementRight = false;
bool enableMovementLeft = false;
//-----------------------------------------------------------------------------
//Set the new center:
//Put the character in the center of the screen
function on_event (EventType event, int data)
{
  if (event == eEventEnterRoomBeforeFadein){
    halfScreenSize = System.ScreenWidth/2;
    xCameraCenter = GetViewportX() + 160 -player.x;
    if(xCameraCenter < 0) xCameraCenter = 0;
  }
}
//-----------------------------------------------------------------------------
function repeatedly_execute_always()
{
  SetViewport(xCameraCenter, 0 );
  //Check the event and set the direction
  if (  player.x > S_DISTANCE + halfScreenSize + GetViewportX() ){
    enableMovementRight = true;
    movementVersor = 1;
  }
  if (player.x < (GetViewportX() + S_DISTANCE) ){
    enableMovementLeft = true;
    movementVersor = -1;
  }
  //if the movement is enabled
  if(enableMovementRight == true || enableMovementLeft == true) xCameraCenter = xCameraCenter + movementVersor*S_VELOCITY;
  if(xCameraCenter >= player.x - halfScreenSize ){
    enableMovementRight = false;
  }
  if(xCameraCenter <= player.x - halfScreenSize ) enableMovementLeft = false;
}

this is the code that my scripter gived to me, still have a little problem, but it works, i'l post the final version tomorrow, but if someone needit...

Calavera

This is my final version for background sliding in monkey island style ....

Code: ags

//Backgorund sliding: 
//-----------------------------------------------------------------------------
//Pseudo const
//
//S_VELOCITY is the camera speed. 0 no movement
//
int S_VELOCITY = 3;
int S_DISTANCE = 160;
//-----------------------------------------------------------------------------
//Global var
int xCameraCenter;
int halfScreenSize;
//State var
int movementVersor = 1; // 1 for right movement -1 for left movement
bool enableMovementRight = false;
bool enableMovementLeft = false;
//-----------------------------------------------------------------------------
//Set the new center:
//Put the character in the center of the screen 
function on_event (EventType event, int data)
{
  if (event == eEventEnterRoomBeforeFadein){
    halfScreenSize = System.ScreenWidth/2;
    xCameraCenter = GetViewportX() + 160 -player.x;
    if(xCameraCenter < 0) xCameraCenter = 0;
  }
}
//-----------------------------------------------------------------------------
//Camera motion
function repeatedly_execute_always()
{
  SetViewport(xCameraCenter, 0 );
  //Check the event and set the direction 
  if (  player.x > S_DISTANCE + halfScreenSize + GetViewportX() ){
    enableMovementRight = true;
    movementVersor = 1;
  }
  if (player.x < (GetViewportX() + S_DISTANCE) ){
    enableMovementLeft = true;
    movementVersor = -1;
  }
  //If the camera is on the left border or right border disable the movement
  if( Room.Width <= GetViewportX() + halfScreenSize*2 ) enableMovementRight = false;
  if(GetViewportX() == 0) enableMovementLeft = false;
  //Check if the camera and the player are in the same position
  if(xCameraCenter >= player.x - halfScreenSize) enableMovementRight = false;
  if( xCameraCenter <= player.x - halfScreenSize) enableMovementLeft = false;
  //if the movement is enabled
  if( enableMovementRight == true || enableMovementLeft == true ) xCameraCenter += movementVersor*S_VELOCITY;
}

SMF spam blocked by CleanTalk