• 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!

Is it possible for 1 object to have 2 masks?

mutazoid

Member
I was wondering if one object could have 2 or 3 clickable targets? Or would I need to make 2 or 3 different objects and figure away to keep them moving together?
 
R

rui.rosario

Guest
Yes, if you check the clicking position yourself (mouse_x/mouse_y) you could see if it is within any of those three areas and act accordingly.
 

mutazoid

Member
I think I understand but its a bit tricky. I have a 96x96 object. I can think of 3 rectangles 926x32 each and figure if the mouse position is with in that but what if the object is rotated. This is where I think I need to take an advanced level geometry course (which would be fun)
 

FrostyCat

Redemption Seeker
There is a built-in function for that: point_in_rectangle()

Besides, without any rotation involved, checking whether a point is within a rectangle simply means checking whether its x coordinate falls within the range [left x, right x] and its y coordinate falls within the range [top y, bottom y]. That's pretty basic geometry.
 
R

rui.rosario

Guest
Doesn't that function only check without rotation?

I think the wants a check that works even for rotated rectangles:
and figure if the mouse position is with in that but what if the object is rotated.
 

FrostyCat

Redemption Seeker
Doesn't that function only check without rotation?

I think the wants a check that works even for rotated rectangles:
It checks without rotation, but you can adapt it by transforming the point to check beforehand. Just use the rectangle for when there is no rotation, rotate the point to check by the same amount as the sprite's rotation but in the opposite direction, then check if the rotated point is in the rectangle.
 

TheouAegis

Member
Code:
var a = point_direction( x, y, x_to_check, y_to_check );
var d = point_distance( x, y, x_to_check, y_to_check );
a -= image_angle;
var xx = x + lengthdir_x(d, a);
var yy = y + lengthdir_y(d, a);
var i = image_angle;
image_angle = 0;
if clamp(xx,bbox_left,bbox_right) == xx
switch bbox_bottom - yy >> 5
{
    case 0: //collision in top area
    break;

    case 1: //collision in middle area
    break;

    case 2: //collision in bottom area
    break;

    default: //no collision
    break;
}
image_angle = i;

Not sure if that's what FC had in mind, but that's the first thing that popped in my head when I read the OP's post.
 

Fredrik

Member
I didn't ready every comment above so there might be a better answer.
You can only have one mask for each object, so you'd have to do as I read was mentioned above, use mouse_x and mouse_y. You can use like:

Code:
if mouse_x > xxx and
   mouse_x < xxx and
   mouse_y > xxx and
   mouse_y < xxx
   {something to happend}
 
A

anomalous

Guest
Yes you can have multiple masks, although this may not be a good place for that.
You can use multiple objects..one object per interaction, nothing wrong with this method, it can be more intuitive and cleaner for some.
You can also use coordinates. Both methods have pros/cons and strong followings of either camp, both are fine.

But as a matter of information, it is sometimes useful to have multiple masks for the same object, and you can do it easily.

mask_index = (some_sprite); // do this as much as you need to, an object can have any number of masks...

Let's say you have a precise mask only for one specific check, and you use a circle mask for the rest of your game.
Before that one check, from that object you can change the mask_index to the precise sprite...check collision (and maybe set the sprite offsets if needed), then change it back.
I do this with selecting a character, which uses the exact outline of the character in any animation frame. But for all other collisions (move, shoot, etc.), its defaulting to a basic circular shape.
 
3

347_Jake

Guest
There is a built-in function for that: point_in_rectangle()

Besides, without any rotation involved, checking whether a point is within a rectangle simply means checking whether its x coordinate falls within the range [left x, right x] and its y coordinate falls within the range [top y, bottom y]. That's pretty basic geometry.
Oh wow! Awesome! I wrote a mouse_over() script forever ago and have been using that, but this is way better.
 
Top