GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2017-01-15 12:27:27

Husi012
is coding
From: Germany
Registered: 2016-08-29
Posts: 2

point_on_sprite

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.

Expand///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:

Expanddraw_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

#2 2017-01-19 06:28:47

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: point_on_sprite

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

Board footer

Powered by FluxBB