Setting a Position Relative to the Screen View?

M

MrChickenGuy

Guest
I want to keep an object at a specified position on the screen at any given time. This is the simplified script I have for a test object at the moment:
Code:
x=view_xview[0]+1000;
y=view_yview[0]+100;
This works fine until the view in the room in extended.
Here is the location of the object before zooming out (the green square):

But when zoomed out, the location changes because now every pixel is .66 of the original size (view changes from 1280x720 to 1920x1080):

The object still moves along with the screen, but because the view in the room is larger, the X and Y coordinates given are no longer at the edge of the screen.
I want to be able to essentially replicate how the Draw GUI event works; keeping sprites in the same location despite the viewport. But through a Step event so I could, for example, create objects at the corner of the screen.
Thanks in advance!
 

CMAllen

Member
You need to modify your offset values based on your 'zoom' factor. Say you have a zoom factor of 2 (that is, every pixel of the room is a 2x2 block of pixels on screen), that means you need to divide your "screen-coordinate" offsets by 2. But wait, what if you have zoomed out, and you have a zoom factor of 1/2 (which is each pixel on screen is now a 2x2 block of pixels in the room)? Then you divide by 0.5.
 

CloseRange

Member
@MrChickenGuy
percentages are your friend. just like if you did view_xview/2 it would always be in the middle (/2 being the same as .5 being the same as 50%)

if your original view is 1280x720 and you want it at 1000 100 then do this:
Code:
x = view_wview[0] * (1000 / 1280);
y = view_hview[0] * (100 / 720);
that will instead get the percent. 1000/1280 and 100/720 are the percents just like .5 would be in the origional one.
 
Top