How to find absolute screen coordinates for a pixel inside the game window

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • How can I get the absolute screen coordinates of a pixel (for example the hot spot of an active obj) even when the program window is stretched, zoomed, moved away from the borders of the screen, etc. and pixels are very big?

    I need to control a cursor both with mouse and with arrow keys, having the two methods to sync properly: when I leave the mouse the cursor can be taken by the arrow keys just where it is, and viceversa when I stop moving with keys the actual mouse position must be set just where the cursor is, and that's where the problems start to show.
    I have a movable game window that can be scaled to 3X, 4X, 5X, 6X its original dimensions or set fullscreen and I need to move the actual mouse position (using Mouse Obj) to the position of the active object cursor. Obviously its coordinates are pixel-based inside the frame and are also influenced by the eventual scrolling and most of all by the scaling factor.

    I've used an expression like

    Set Actual X of mouse to WinXPos( "Window Control" ) - (X Left Frame * Scale) + (X("CursorObject") * Scale)
    Set Actual Y of mouse to WinYPos( "Window Control" ) - (Y Top Frame * Scale) + (Y("CursorObject") * Scale)

    Mouse obj sets the Actual Mouse X and Actual Mouse Y and it works fine (with a scale multiplier) until the game window is smaller than the screen and you don't get any black borders; but when screen ratio isn't the same you get a very annoying offset with keys movement.
    Maybe I could figure out a way to include the possible offset in the expression, but I think that getting the absolute screen coordinates of a pixel (with approximation, I suppose, when the window is scaled and the pixels are fat) could fix the problem more easily.

    Thank you in advance

    Please login to see this link.

  • Does your window have a frame-border-width you didn't consider? Can you separate you centering code to a new project and share it with us? May be than I or someone else can figure out, what to do. Your code looks good but I didn't complete understand the circumstances it which it stops working.

  • How do you take into consideration that your user can move your cursor with arrows to another position while the mouse have not moved, and then once using the mouse, the cursor will fly to it's old position? Seems strange to me.

    Why not use two cursor objects? One moved by the mouse. And the second, set to the mouse cursor position as soon as you press a key and moved with your keyboard. Make each of them visible when needed and voila.

  • Please login to see this link.

    Please login to see this picture.

    implemented a few years ago, to fix offset of mouse when game has black border or stretched.
    it will take frame size & app size as input then compute scale with the size of render window.
    you can use the border offset to offset the entire game window.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!