You are not logged in.
Pages: 1
Hi,
I made a script that checks if a sprite at a given position meets a point.
You can use it when you want to draw a sprite and check if the user clicks on it.
///point_on_sprite(px,py, spr, x,y)
//
// Returns if the point (px,py) meets
// the sprite spr at the point (x,y)
//
// Code by Husi
/// GMLscripts.com/license
{
var tmp_mask, tmp_x,tmp_y, collision;
tmp_mask = mask_index;
tmp_x = x;
tmp_y = y;
mask_index = argument2;
x = argument3;
y = argument4;
collision = false;
if (position_meeting(argument0,argument1, id)) {
collision = true;
}
mask_index = tmp_mask;
x = tmp_x;
y = tmp_y;
return collision;
}
Example:
draw_sprite(sprite, subimage, x,y);
if (mouse_check_button_pressed(mb_left)) {
if (point_on_sprite(mouse_x,mouse_y, sprite, x,y))
show_message("you clicked at the sprite");
}
Last edited by Husi012 (2017-01-15 12:48:30)
Offline
This is a good idea for script. I can imagine some uses for it and I think others may as well.
Thanks for the submission and welcome to the forums.
Abusing forum power since 1986.
Offline
Pages: 1