lcl wrote:@Bamby1983: That's not what I meant with mouse look. Your example is the same that skydereign suggested.
But thanks anyway.
Ahh sorry, I misunderstood the requirement. I believe what you're looking for is the kind of mouse look you see in first-person shooter games. Yes, it
is possible to achieve this using GE. The attached GED file contains a working demo I just whipped up.
Just copy-paste the following code in the respective places and change the names of the 2 actors involved in your code (Background and Crosshairs). You will need to select the option to "Hide" your mouse cursor in the game settings to remove it from your screen. The Crosshair you see is actually an actor that is programatically anchored to the center of your screen.
The following code will:1) Enable you to use mouse look as is done in FPS games
2) Continue scrolling the screen when the mouse is at the periphery of the screen.
3) Anchor the crosshairs at the center of the screen
4) Prevent you from moving beyond the background image boundary. This code will dynamically calculate the required values and therefore does not need to be modified for a new background image or view size
Paste the following in the global code. It is to declare a couple of variables we will be using:
- Code: Select all
int xmouse_prev=xmouse;
int ymouse_prev=ymouse;
Paste the following in the view actor's "Create" event.
- Code: Select all
// Initializing mouse position in variables
xmouse_prev=xmouse;
ymouse_prev=ymouse;
And finally, paste the following code in the view actor's "Draw" event.
- Code: Select all
if(xmouse!=xmouse_prev) { // If the horizontal mouse position has changed
view.x+=(xmouse-xmouse_prev); // Moving the view along with the mouse
Crosshairs.x+=(xmouse-xmouse_prev); // Moving the crosshairs along with the view
xmouse_prev=xmouse; // Setting value of xmouse_prev to xmouse for the next frame
}
else if (xmouse<=20) { // If the mouse is at the extreme left of the screen
view.x-=10; // Moving the view to the left
Crosshairs.x-=10; // Moving the crosshairs to the left
}
else if (xmouse>=view.width-40) { // If the mouse is at the extreme left of the screen
view.x+=10; // Moving the view to the left
Crosshairs.x+=10; // Moving the crosshairs to the left
}
if (view.x<=Background.x-(Background.width/2)) {
view.x=Background.x-(Background.width/2);
Crosshairs.x=view.x+(view.width/2);
}
else if (view.x+view.width>=Background.x+(Background.width/2)) {
view.x=Background.x+(Background.width/2)-view.width;
Crosshairs.x=view.x+(view.width/2);
}
if(ymouse!=ymouse_prev) { // If the horizontal mouse position has changed
view.y+=(ymouse-ymouse_prev); // Moving the view along with the mouse
Crosshairs.y+=(ymouse-ymouse_prev); // Moving the crosshairs along with the view
ymouse_prev=ymouse; // Setting value of ymouse_prev to ymouse for the next frame
}
else if (ymouse<=20) { // If the mouse is at the extreme left of the screen
view.y-=10; // Moving the view to the left
Crosshairs.y-=10; // Moving the crosshairs to the left
}
else if (ymouse>=view.height-40) { // If the mouse is at the extreme left of the screen
view.y+=10; // Moving the view to the left
Crosshairs.y+=10; // Moving the crosshairs to the left
}
if (view.y<=Background.y-(Background.height/2)) {
view.y=Background.y-(Background.height/2);
Crosshairs.y=view.y+(view.height/2);
}
else if (view.y+view.height>=Background.y+(Background.height/2)) {
view.y=Background.y+(Background.height/2)-view.height;
Crosshairs.y=view.y+(view.height/2);
}