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

Click On Sprite

Sourav

Member
i want to click the generated sprites.Can anyone help me please ..Thanks in advance


here is the code:
for(i = 1 ; i <=50 ; i++){

yy = (((btn_height / 2)+spaceBetweenItem) * i) + scr_scrollable_get_scroll_data(oScrollable) ;


draw_sprite(sLoot6,i, yy,250 );


}
 

trippity

Member
That code snippet doesn't give us much insight..

I'm assuming you want to interact with loot that is generated?
I'm also going to assume this loot comes out of some kind of chest for example?

If the above assumptions are correct - I would suggest you generate an object instead of just drawing a sprite. Something like this:

GML:
instance_create_layer(X, Y, layer, obj_loot);
obj_loot.sprite_index = sLoot6
Or take it a step further and just create a function
GML:
generate_loot(x_pos, y_pos, sprite){
instance_create_layer(x_pos, y_pos, layer, obj_loot);
obj_loot.sprite_index = sprite
}

// Example use
generate_loot(200, 150, sLoot6)

Then you can add a click event in your parent obj_loot

On click:
//Do something
//Destroy self
 

Ommn

Member
in "step" Event
GML:
if mouse_check_button_pressed(mb_left)
{
    var __sphw=sprite_get_width(sLoot6)
    var __sphh=sprite_get_height(sLoot6)
    for(var i=1;i<=50;i++)
    {
        yy = (((btn_height / 2)+spaceBetweenItem) * i) + scr_scrollable_get_scroll_data(oScrollable) ;
        if point_in_rectangle(mouse_x,mouse_y,yy-__sphw,250-__sphh,yy+__sphw,250+__sphh)
        {
            //Do you want
        }
    }   
}
 

Sourav

Member
That code snippet doesn't give us much insight..

I'm assuming you want to interact with loot that is generated?
I'm also going to assume this loot comes out of some kind of chest for example?

If the above assumptions are correct - I would suggest you generate an object instead of just drawing a sprite. Something like this:

GML:
instance_create_layer(X, Y, layer, obj_loot);
obj_loot.sprite_index = sLoot6
Or take it a step further and just create a function
GML:
generate_loot(x_pos, y_pos, sprite){
instance_create_layer(x_pos, y_pos, layer, obj_loot);
obj_loot.sprite_index = sprite
}

// Example use
generate_loot(200, 150, sLoot6)

Then you can add a click event in your parent obj_loot

On click:
//Do something
//Destroy self

Thank you so much to help us who r new in GML.
 

Sourav

Member
in "step" Event
GML:
if mouse_check_button_pressed(mb_left)
{
    var __sphw=sprite_get_width(sLoot6)
    var __sphh=sprite_get_height(sLoot6)
    for(var i=1;i<=50;i++)
    {
        yy = (((btn_height / 2)+spaceBetweenItem) * i) + scr_scrollable_get_scroll_data(oScrollable) ;
        if point_in_rectangle(mouse_x,mouse_y,yy-__sphw,250-__sphh,yy+__sphw,250+__sphh)
        {
            //Do you want
        }
    }  
}
Thanks a lot
 
Top