SOLVED collision check for draw_sprite_ext?

A

AlphaBeta1

Guest
I'm going to make a game with a lot of sprites. Making all sprites as objects creates a lot of trouble. I wrote the Main rules in a rule object and managed to draw it with draw_sprite_ext. However, I cannot check Collision.

Briefly; How to make a collision check of a sprite drawn with draw_sprite_ext?
 

Felbar

Member
Check the manual for the area titled Collision Checking Without A Mask,
or learn how to deactivate objects not in view and then you can still use objects.
There is at least one article about this in the YoYo blogs area and a several others
in the forums.

 
A

AlphaBeta1

Guest
Check the manual for the area titled Collision Checking Without A Mask,
or learn how to deactivate objects not in view and then you can still use objects.
There is at least one article about this in the YoYo blogs area and a several others
in the forums.

I think these are used to make a manual collision. So how do I get a position in the sprite? 4 positions are required to create a rectangle. How can I set them to locations within the sprite?
 

Felbar

Member
I am not sure what you mean but you can get a sprites width and height

var width = sprite_get_width( some_sprite_index );
var height = sprite_get_height( some_sprite_index );

with its x and y positions which you presumably have
you can create a rect for the collision functions.

if you are not going to use the objects/collision mask way
your going to have to create and keep track of positions and
some kind of collision shape for each sprite so you can feed them
into the collision functions.

Alternatively create your own custom collision system.
 
A

AlphaBeta1

Guest
I am not sure what you mean but you can get a sprites width and height

var width = sprite_get_width( some_sprite_index );
var height = sprite_get_height( some_sprite_index );

with its x and y positions which you presumably have
you can create a rect for the collision functions.

if you are not going to use the objects/collision mask way
your going to have to create and keep track of positions and
some kind of collision shape for each sprite so you can feed them
into the collision functions.

Alternatively create your own custom collision system.
I'm making a clicker game where I need to use many sprites. In short, when you reach a certain "click" value, it will change the sprite it will use. However, it would be pointless to open an object for each sprite. To do this, I write the draw_sprite_ext code on an object and draw the desired sprite. But I want the mouse to perceive the collision mask of this sprite. Place_meeting code does not work. So when I couldn't find the code to detect the sprite's collision mask, I tried to create a collision manually. But now I'm trying to find out if there is a way to access the coordinates inside the sprite.

sorry for my ban english. i use google translate
 

Felbar

Member
OP wants to do sprite collisions without using objects

get the mouse position and use point_in_rectangle , get the rectangle of the sprite the way I showed you
 
From what I understand, OP wants to avoid using objects because they think they need to create one object for each sprite-- which is unnecessary. Checking collisions is not the purpose of drawing sprites, rather it is what objects are for. And checking collision with point_in_rectangle() is not precise, which can lead to unexpected behavior.
 

Slyddar

Member
@Felbar 's suggestion would be the way to go. Use the rectangle_in_rectangle function, along with the sprite_get_ functions to determine the dimensions of the sprite. If you are planning on having multiple sprites being drawn from one object, you still need to store the sprites positions in order to run the collision check against, so you may as well populate a data structure early on with things such as sprite x,y origin, x/y position, and it's width/height. You could then reference this for the collisions so you are only sourcing the information once.
 
Last edited:
A

AlphaBeta1

Guest
OP wants to do sprite collisions without using objects

get the mouse position and use point_in_rectangle , get the rectangle of the sprite the way I showed you
I want to avoid creating objects


From what I understand, OP wants to avoid using objects because they think they need to create one object for each sprite-- which is unnecessary. Checking collisions is not the purpose of drawing sprites, rather it is what objects are for. And checking collision with point_in_rectangle() is not precise, which can lead to unexpected behavior.
I want to avoid creating objects. I think this can lead to some bad results. Also, creating an object for every sprite is unnecessary. But I haven't tried it as sprite_index.
 

Slyddar

Member
I want to avoid creating objects. I think this can lead to some bad results.
I would consider explaining some reasons for this, as there are people here who have used Gamemaker for 10+ years, with vast experience on the best ways of doing things. As a new user you might be overthinking something where they can offer advice on a better way to achieve your goal. What you are wanting to do seems overly complex. How many sprites do you estimate you will be drawing at once?
 
A

AlphaBeta1

Guest
@Felbar 's suggestion would be the way to go. Use the rectangle_in_rectangle function, along with the sprite_get_ functions to determine the dimensions of the sprite. If you are planning on having multiple sprites being drawn from one object, you still need to store the sprites positions in order to run the collision check against, so you may as well populate a data structure early on with things such as sprite x,y origin, x/y position, and it's width/height. You could then reference this for the collisions so you are only sourcing the information once.
so... there is no way to use the sprite's collision mask (unless it turns into an object). I tried to go from the width and height of the object, but since every sprite I use will have different collision locations, I was investigating whether this is an easier method.
 
A

AlphaBeta1

Guest
I would consider explaining some reasons for this, as there are people here who have used Gamemaker for 10+ years, with vast experience on the best ways of doing things. As a new user you might be overthinking something where they can offer advice on a better way to achieve your goal. What you are wanting to do seems overly complex. How many sprites do you estimate you will be drawing at once?
I just want the button to change to another sprite when the click value reaches a certain number. So I will add a lot of buttons as there is a feature in many clicker games
 

Slyddar

Member
I just want the button to change to another sprite when the click value reaches a certain number.
The just change the instances sprite_index to whatever other sprite you want, at that point, using sprite_index = spr_new_sprite. It will then change it's sprite and will now use the mask of the new sprite.
 
A

AlphaBeta1

Guest
The just change the instances sprite_index to whatever other sprite you want, at that point, using sprite_index = spr_new_sprite. It will then change it's sprite and will now use the mask of the new sprite.
You can change the sprite_index of an object, and check collision against it.
Yes it works. Thank you so much

I guess we need to play with the height and width of the sprite so that the title does not deviate from the subject. We can draw a handmade colission with point_rectangle with the width and height values we get with Sprite_get_width (and height). So at least that's how I got it. Thank you very, very much
 
Top