Jump to content


Photo

Mouse Click Query


  • Please log in to reply
5 replies to this topic

#1 Conk

Conk

    GMC Member

  • GMC Member
  • 153 posts

Posted 25 March 2012 - 01:18 AM

I'm currently making an inventory system for a game and I'm using objects which appear on screen which you can interact with etc. but they have a delay (as the screen moves with the player). If I use draw instead there will be no lag, so my question is, is there a way to check the area of the screen a mouse click happened in? Like... (x1,y1,x2,y2) and if your mouse click happens in that area, relevant stuff happens... I'm sure this is possibly, but not sure on the function required ):


Thanks in advanced.
  • 0

#2 blopit

blopit

    just like you, only

  • GMC Member
  • 815 posts
  • Version:GM8.1

Posted 25 March 2012 - 04:56 AM

You mean like check if a point is within a rectangle?

Yea it's completely possible! As I always say, "You are only limited by your own imagination!"


//  point_in_rectangle(x1,y1,x2,y2,x3,y3)
//  This script will check if point [x3,y3] is in the rectangle [x1,y1,x2,y2]
//  Returns: 'True' if point is in rectangle else 'False' 

return ((median(argument0,argument2,argument4)==argument4)*(median(argument1,argument3,argument5)==argument5))

You can use it like this:


if mouse_check_button_pressed(mb_left) and point_in_rectangle(x1,y1,x2,y2,mouse_x,mouse_y){
//DO THIS
}

Just ask if you need an explanation or if this wasn't what you were looking for.

Edited by blopit, 25 March 2012 - 04:57 AM.

  • 0

#3 witcher

witcher

    GMC Member

  • GMC Member
  • 396 posts
  • Version:Unknown

Posted 25 March 2012 - 09:46 AM

Is point in rectangle a script or a code
I tried using it but it aint working
I wanted to check if a mouse click is between a rectangle points and if so then snap to centre point of rectangle
  • 0

#4 Conk

Conk

    GMC Member

  • GMC Member
  • 153 posts

Posted 25 March 2012 - 11:55 AM

That's pretty cool :P I don't really program my own functions :L I guess I forget that it's possible, though looking at yours, the simplicity behind it is pretty awesome :P Thank you very much :D

@witcher

You have to put the first code into a script and call it point_in_rectangle, then put the point_in_rectangle(x1,y1,x2,y2,mouse_x,mouse_y) in the step event, the x1,y1,x2,y2 are the co-ord of the rectangle, x3,y3 the mouse coord, simple.
  • 0

#5 witcher

witcher

    GMC Member

  • GMC Member
  • 396 posts
  • Version:Unknown

Posted 25 March 2012 - 12:24 PM

That's pretty cool :P I don't really program my own functions :L I guess I forget that it's possible, though looking at yours, the simplicity behind it is pretty awesome :P Thank you very much :D

@witcher

You have to put the first code into a script and call it point_in_rectangle, then put the point_in_rectangle(x1,y1,x2,y2,mouse_x,mouse_y) in the step event, the x1,y1,x2,y2 are the co-ord of the rectangle, x3,y3 the mouse coord, simple.

Works fine thanks dude
Previously i had put the code in mouse left event
  • 0

#6 Conk

Conk

    GMC Member

  • GMC Member
  • 153 posts

Posted 25 March 2012 - 12:57 PM

Your welcome (:
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users