I’m trying to achieve the functionality that when moving the mouse to one of the window borders the camera scrolls in that direction.
I came up with a two layer approach. The bottom layer holds the game map and the top (gui) layer has mouse sensitive areas at the borders that move the camera in the perticular direction when the mouse is over it.
Unfortunately this works very choppy (see attachment).
Do you have an idea how to imporve this?
Thanks in advance
(Project created wit GD 4.0beta, may not work in older GD versions)
scrolltest.zip (5.18 KB)
It looks like the stretching of the objects cause the stuttering. Using fullsize textures on the scrolling objects fixes the issue.
I tried using the method mentioned here:
But it doesn’t work on Linux since the "ScreenWidth/Height() / SceneWindowWidth/Height() function don’t work properly on Linux and return “0”.
I made this project on Linux and it works for me. But maybe I don’t unterdstand exactly what is your issue.
And I can’t open your project because GD 4.0 is not yet on Linux.
Scrolling.zip (8.57 KB)
thanks for your help.
I have created a new project in version 3.6.84 to show you the issue.
The window should scroll left and right when the mouse is at the border. A left click or pressing any key should quit the application in fullscreen mode.
But somehow it doesn’t or better to say in 9/10 cases the game won’t react for clicks or keypresses. Scrolling to the right where “SceneWindowWidth()” or “ScreenWidth()” is the limit doesn’t work.
(Activating fullscreen in your example hinders the camera from scrolling right and down)
Warning, running the game in fullscreen mode will probably require killing the process on linux.
fullscreen_error_3.x.zip (3.83 KB)
Hello. I tested your project.
Concerning the key/mouse bug : this is because when you run your game, the focus is not on your game. But sometimes, I don’t know exactly why, the game takes the focus. To be sure this issue never happen, you have two options :
- you don’t run your game in fullscreen mode and you let the player decide. If you make, for example, a button to press, this will activate the focus on your game.
- if you want to run your game in fullscreen, just uncheck the box “Deactivate input when focus is lost” in the properties of your scene.
But I recommend you to make a little launcher for your game : a small scene where you can simply click on “Play” and get the focus for your input. It is always better to deactivate the input when the focus is lost.
Concerning the scrolling to the right, the issue comes from the fact that the right border of your screen is always 800 and not the width of your screen. I created a third text object which displays MouseX() : when I put my mouse to the right, MouseX() = 800 and not 1600 (my screen is 1600*900 px). So your mouse will never be >= SceneWindowWidth().
This is very easy to correct (look at the linked project )
(concerning my example, I forgot to add a little margin on borders )
Fullscreen.gdg (16 KB)
Thank you very much for your help.
Starting the game in windowed mode and going “real” fullscreen with a start button is a good compromise.