• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Clicking within an area using coordinates reletive to a viewport

M

MindTrekker201

Guest
I am currently working on a shop system that creates a sprite as big as the window then smaller sprites as the items sold. I am attempting to make it so if I click within an area while the menu is open (and I have enough coins), I will be able to acquire the listed item. here is my current script to accomplish this, in a script called list_shop(x,y,item,price)
Code:
    if mouse_check_button_pressed(mb_left){
            xx=window_view_mouse_get_x(0)
    yy=window_view_mouse_get_y(0)
    arg0=argument0+256
    arg1=argument1+256
    if xx>argument0 && xx<arg0 && yy>argument1 && yy<arg1{

        if global.coinum>=argument3{
    instance_create_depth(demonium.x,demonium.y,1,argument2)
    global.coinum-=argument3
    }}}
for some reason, in game, clicking the area defined above does not activate the instance_create function.
demonium is player object
global.coinum is coin counter

also, the viewport id is 0 and is set to follow the player object.
in code, the function is used as follows.
list_shop(254,128,gem,1)
 

TsukaYuriko

☄️
Forum Staff
Moderator
Step through your code using the debugger. Analyze at which line the execution stops (which if statement does not evaluate correctly) and analyze the variables and function return values being used, then double-check the conditions which cause the respective values to change to ensure they are being set properly.
 

Relic

Member
Is your room bigger than the view? Is your shop menu behaving like a GUI layer that moves around with the view and won’t always have the same x and y coordinates?

You can try drawing where this clickable region is in the draw event to see if matches where you think you need to click.
 
M

MindTrekker201

Guest
The shop menu is behaving like a GUI and the view is smaller than the room, the view follows the player around so I guess what I want is to somehow get the x,y of the top left corner of my view to then lay out the coordinates of the clicking area.
 
M

MindTrekker201

Guest
Is your room bigger than the view? Is your shop menu behaving like a GUI layer that moves around with the view and won’t always have the same x and y coordinates?

You can try drawing where this clickable region is in the draw event to see if matches where you think you need to click.
The shop menu is behaving like a GUI and the view is smaller than the room, the view follows the player around so I guess what I want is to somehow get the x,y of the top left corner of my view to then lay out the coordinates of the clicking area.
 
Top