Correct measurements for the viewfinder


Hi, can you help me find a way to fit the crosshair into the desktop and prevent it from stretching too much?
My game is 640x360 in size.
When I aim, it stretches too much and always ends up outside the screen.

I’m guessing this only happens when you move the mouse to the left of the screen, and when moving the mouse to the right it’s ok?

Are you repositioning the cursor image when it’s width is changed? If not, then as you move the mouse to the left, the image is increased in width and the centre of it moves to the right. This magnifies or increases the distance between the centre and mouse pointer. Here’s what’s happening visually (the red line is the distance from the object centre to the cursor:

width-er

1 Like

Yes, it’s corrected to the right, and it works fine, but if I aim at other positions, I get the problem.
So, do I have to resize the cursor width? In what event do I have to intervene?

Do you want the crosshair to just stretch towards the side of the mouse, or to resize but stay centred?

If you want it to stretch, then I think you’ll need to use the Hitbox’s origin instead of the centre (assuming it’s at the top left of the image) - AngleBetweenPositions(Playerhitbox.X(), Playerhitbox.Y() - 5, MouseX(), MouseY())

If you want the crosshair to stay centred on the screen while stretching, then you’ll probably need to change the Playerhitbox origin to the centre of the image.

eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrr
77777777

It already remains centered on the player.
I entered center(x)(y) to (x)(y) as mentioned,
but I’d like to know how I can set a limit so that it doesn’t go beyond the edge of the screen when the player extends to aim.

Can anyone help me? How can I set the maximum amount of crosshairs that extends to the end of the screen?

I made a mistake in this post - it should have read DistanceBetweenPositions(Playerhitbox.X(), Playerhitbox.Y() - 5, MouseX(), MouseY())


You could add an action after you set the width of the mirinocursore to set the width to min(mirinocursore.Width(), ScreenWidth()/2) (see note below). I think that should keep the cursor width to 1/2 the screen.

Note - you could just have one action to set the width, though it’s a bit harder to read: min(DistanceBetweenPositions(Playerhitbox.X(), Playerhitbox.Y() - 5, MouseX(), MouseY()), ScreenWidth()/2)

2 Likes

I finally figured out where my problem lies, but I still haven’t been able to solve it.
All the game sprites are in the game layer, while I use the base layer for the HUD.
At the beginning of the scene, I set a zoom that halves the screen size, and this causes the cursor to always go off-screen.
How do I enlarge the cursor by calculating the zoom?


The issue is the mix of a scaled layer and a non-scaled base layer.

You’re getting the position of the Playerhitbox object, which is on the scaled layer “game”, and checking the mouse position which is on the unscaled layer “base layer”. This is really screwing up the calculations, and it’s a bit of a mathematical nightmare to work it all out.

So I went the simple route, and used the mouse position on the layer “game”. I also changed the layer of the bomb to “game”, otherwise it too would need complex calculations to position and target correctly.


Teaser and explanation on what I did:

mirinocursore

I added a variable named ratio. This is to cater for the difference in the mirinocursore’s sprite width and the distance between the origin and LandingPoint. An explanation why:

Say the sprite width is 100 pixels, and the distance between the origin and LandingPoint is 80 pixels, or 80% of the sprite’s width. If the mouse moves to 200 pixels away, the sprite is enlarged to 200 pixels, and the LandingPoint is 160 pixels from the origin - 40 pixels short of the mouse.

By setting the ratio variable to width/(distance between origin & LandingPoint) (or 100/80 = 1.25), we can use this value to multiply the width so that the LandingPoint is actually at the mouse position. So if the mouse is 200 pixels away, multiplying that by 1.25 gives us a width of 250 pixels. Since the LandingPoint is 80% of the way across, it’s position is now 80% of 250 = 200 pixels.

Here are the modifications I made to get it to work:

image

Why does the cursor disappear? Where am I going wrong?
If I disable the “crosshair cursor” width and angle events, it reappears.

Because the point names are case sensitive. It’s LandPoint, with a capital ‘P’, meaning PointX(“Landpoint”) = 0 and leaving ratio as a large number:

image

1 Like

Oh, how careless! Thank you so much.
One last question: What if I wanted to replicate the same thing for touch controls? I initially developed the game for the mobile version and am now converting it to PC as well.
How can I extend the object to the end of the screen?
In this case, the joysticks are already in the base layer.


Are you using a MultiTouch Joystick object? If so (and say it’s named “MTJoystick”) maybe change the mirinolancio width to MTJoystick.StickForce() * ScreenWidth() / 2.

Yes, I initially developed the game for mobile, but I don’t use any extensions. The joystick code is the one shown above, and the force variable isn’t recognized.

Ah, ok, I didn’t spot that screen shot. Then try changing the mirinolancio width to (min(RightButtonBackgroud.Distance(RightButton) / RightButtonBackgroud.Variable(Joystick.JoyDinstanceMaximum), 1) * (ScreenWidth() / 2).

So what that’s doing is finding the ratio of the RightButton position to the maximum distance (limiting it to 1) and multiplying that ratio to half the screen width.

so it goes too far off the screen and if I move the joystick towards the center it doesn’t get smaller but remains enlarged