The problem there also when i click in a different position, i would fix this because in my game there are many scene with a long backgorund and the player is forced to click at the screen side repeatedly.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
//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;
}
By continuing to use this site you agree to the use of cookies. Please visit this page to see exactly how we use these.
Page created in 0.064 seconds with 15 queries.