Jump to content


Photo

Pick the correct instance **SOLVED


  • Please log in to reply
4 replies to this topic

#1 gamzta

gamzta

    GMC Member

  • New Member
  • 85 posts
  • Version:GM8

Posted 17 June 2012 - 06:55 AM

Hello,

I have a bunch of instances of the same object on the screen. I created them using the instance_create code. Now when I hit one of them I want it to explode. I don't have a problem with the game knowing which one gets hit because I kill that instance and it works. But when I tell it to create the instance for the explosion on the position of obj_blue_block.x and obj_blue_block.y it puts the explosion on the very first one created (blue block that is). I want it to put the explosion on the block being hit.

Please explain how to code that in gml. I am guessing I need to know where that blue block is at but there is no way to know that because they are created in random places on the screen.

Edited by gamzta, 17 June 2012 - 07:46 AM.

  • 0

#2 Mr. Munchkin

Mr. Munchkin

    GMC Member

  • GMC Member
  • 681 posts
  • Version:GM:Studio

Posted 17 June 2012 - 07:14 AM

If you want the explosion to appear when it's destroyed, just put this in the destroy event of obj_blue_block
effect_create_below(ef_explosion,x,y,0,c_red);

Hope that helps :)

Edited by Mr. Munchkin, 17 June 2012 - 07:14 AM.

  • 1

#3 gamzta

gamzta

    GMC Member

  • New Member
  • 85 posts
  • Version:GM8

Posted 17 June 2012 - 07:32 AM

If you want the explosion to appear when it's destroyed, just put this in the destroy event of obj_blue_block

effect_create_below(ef_explosion,x,y,0,c_red);

Hope that helps :)


Ok, normally I pick up on this code very quickly, however, that code has me even more confused O_o

My explosion is not a real explosion but a gif file I made with 25 images in it that break the brick up. So not sure if effect_create_below is some sort of built in explosion lol.

Second, do I replace x,y with something or just leave it x,y?

Third, what the heck does the c_red do?

While waiting on response I will also look this up in manual to get a better feel for it.

Thanks for the help too :)
  • 0

#4 Pixel8ed72

Pixel8ed72

    Musical Brony

  • GMC Member
  • 408 posts
  • Version:Unknown

Posted 17 June 2012 - 07:33 AM

Do you want the effect of an explosion, or an actual explosion object?

If the first, Mr. Munchkins code will work fine.

If not, there are two options:

In the bullets Collsion with a Block event, put this at the end;

with(other)
instance_create(x,y,obj_explosion)

In the blocks Destroy Event(or collision with a bullet):

instance_create(x,y,obj_explosion)

Hope it all works out!
;)

EDIT:
Ninja'd.
:ninja:

Create an object for the explosion and name it obj_explosion, or something easy to refer to.

In the creation, set it's image_speed to a desired value.

In the animation end event, destroy it.

When a block is hit, use the code I gave you to create the explosion.
:)

Hope that helps!

Edited by TerraCrafter, 17 June 2012 - 07:35 AM.

  • 2

#5 gamzta

gamzta

    GMC Member

  • New Member
  • 85 posts
  • Version:GM8

Posted 17 June 2012 - 07:45 AM

Do you want the effect of an explosion, or an actual explosion object?

If the first, Mr. Munchkins code will work fine.

If not, there are two options:

In the bullets Collsion with a Block event, put this at the end;

with(other)
instance_create(x,y,obj_explosion)

In the blocks Destroy Event(or collision with a bullet):

instance_create(x,y,obj_explosion)

Hope it all works out!
;)

EDIT:
Ninja'd.
:ninja:

Create an object for the explosion and name it obj_explosion, or something easy to refer to.

In the creation, set it's image_speed to a desired value.

In the animation end event, destroy it.

When a block is hit, use the code I gave you to create the explosion.
:)

Hope that helps!


*** SOLVED ***
That worked perfectly! Thanks! Problem Solved :)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users