Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] Scaling the window and mouse offset issues  (Read 2613 times)

0 Members and 1 Guest are viewing this topic.

Moonkis

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
[SOLVED] Scaling the window and mouse offset issues
« on: November 13, 2013, 10:04:53 am »
SOLVED EDIT:
Silly me not properly checking the sf::View tutorial. The answer lies in converting between pixel to world coordinates!

http://www.sfml-dev.org/tutorials/2.0/graphics-view.php#showing-more-when-the-window-is-resized

ORIGINAL POST:

I'm currently working on my Zombie shooter that was originally for the GameBoy Jam. The resolution is 160x144px which is quite small, however we are allowed to scale the game (not the graphics itself) to make it larger.

sf::RenderWindow window(sf::VideoMode(160*4, 144*4, 32), "Doki Doki DX", sf::Style::Titlebar);
window.setView( sf::View(sf::FloatRect(0,0,160,144)) );
 

The code above is my window scaling code. It works flawlessly except the mouse has a weird offset from the REAL mouse which is a problem since you aim your gun with the mouse and will most likely open another app or click outside of the window seeing as it's not actually there.



In this picture the windows mouse cursor is actually outside of the window, whilst the game cursor (that takes the position of the cursor relative the window) is inside of the window. I can't properly move the mouse around without sliding outside of the window.

I have never scaled a game before and I'm not sure how to "fix" this?

In addition i need to be able to follow my character with a camera however the "mouse" don't keep it's relative position towards the character. I'm not really sure how to solve this, I'v been at it for a while (days) but I'm not sure how to figure out the new position of the...mouse.

I thought getting the new (relative to window) position would have returned the new position relative to where the current view is but that's not how it works.
« Last Edit: November 13, 2013, 11:42:33 am by Moonkis »

 

anything