How To Destroy Some Instances
#1
Posted 07 May 2009 - 07:13 PM
Thanks.
#2
Posted 07 May 2009 - 07:16 PM
Edited by AB10784, 07 May 2009 - 07:16 PM.
#3
Posted 07 May 2009 - 08:22 PM
#4
Posted 07 May 2009 - 08:31 PM
Edit: spelling
Edited by AB10784, 07 May 2009 - 08:31 PM.
#5
Posted 07 May 2009 - 08:45 PM
while(collision_line(x-64,y,x+64,y,obj_rock,false,true)>=0)
{
with(collision_line(x-64,y,x+64,y,obj_rock,false,true)>=0)
{
instance_destroy();
}
}Do the same thing for the vertical line, changing the arguments for collision_line() to match it.collision_line(x1,y1,x2,y2,obj,prec,notme) This function tests whether there is a collision between the line segment from (x1,y1) to (x2,y2) and entities of object obj. This is a powerful function. You can e.g. use it to test whether an instance can see another instance by checking whether the line segment between them intersects a wall.
#6
Posted 07 May 2009 - 08:56 PM
then instance create, obj_explosion
\
if_place_meeting(obj_explosion) instance_destroy()
#7
Posted 07 May 2009 - 09:00 PM
while(collision_line(x-48,y,x+48,y,objRock,false,true)>=0)
{
with(collision_line(x-48,y,x+48,y,objRock,false,true)>=0)
{
instance_destroy();
}
}and when I placed a bomb in-game it freezed.
Edited by Necdilzor, 07 May 2009 - 09:08 PM.
#8
Posted 07 May 2009 - 09:09 PM
My mistake.I put this code:
while(collision_line(x-48,y,x+48,y,objRock,false,true)>=0) { with(collision_line(x-48,y,x+48,y,objRock,false,true)>=0) { instance_destroy(); } }
and when I placed a bomb in-game it freezed.
while(collision_line(x-48,y,x+48,y,objRock,false,true)>=0)
{
with(collision_line(x-48,y,x+48,y,objRock,false,true))
{
instance_destroy();
}
}I'm an idiot Edited by Snail Productions, 07 May 2009 - 09:10 PM.
#9
Posted 07 May 2009 - 09:19 PM
#10
Posted 07 May 2009 - 09:22 PM
anyways try to duplicate the code then change the + to - and vice versa.?
EDIT: scratch that ^^ change the x's to y's leave the +/-
Edit2: man Im retarded..... Remove the + and - modifiers from the x and put them on y
Edit: @ Snail productions
^ LOLBtw, if you're getting annoyed at me just hinting at the code instead of downright posting it, then ask.
Edited by AB10784, 07 May 2009 - 09:38 PM.
#11
Posted 07 May 2009 - 09:23 PM
Glad it worksyes it works! but only horizontally, maybe something is missing?
I deliberately left out the vertical code because I didn't want to just hand it to you (more or less wanted to teach you how to do it). But it's pretty much the same thing; duplicate the code, and just alter the collision_line() arguments. Hope that helps.
Edit:
@AB10784:
Yeah, infinite loops are evil
Edited by Snail Productions, 07 May 2009 - 09:28 PM.
#12
Posted 07 May 2009 - 09:26 PM
#13
Posted 07 May 2009 - 09:35 PM
Yes.what arguments do I have to alter? the X's and Y's?
The first two arguments (x-48,y) are coordinates for the first endpoint. The second two arguments (x+48,y) are coordinates for the second endpoint. The line is horizontal, from 48 pixels left of x to 48 points to the right of x. In the vertical line, you want it from 48 points above y to 48 below it.collision_line(x-48,y,x+48,y,objRock,false,true);
Btw, if you're getting annoyed at me just hinting at the code instead of downright posting it, then ask.
#14
Posted 07 May 2009 - 09:45 PM
Edited by Necdilzor, 07 May 2009 - 09:50 PM.
#15
Posted 07 May 2009 - 09:52 PM
Full code here.I'm new to GML and I haven't found out yet how to do it vertically.
while(collision_line(x-48,y,x+48,y,objRock,false,true)>=0)
{
with(collision_line(x-48,y,x+48,y,objRock,false,true))
{
instance_destroy();
}
}
while(collision_line(x,y-48,x,y+48,objRock,false,true)>=0)
{
with(collision_line(x,y-48,x,y+48,objRock,false,true))
{
instance_destroy();
}
}Explanation:The vertical code is:
collision_line(x,y-48,x,y+48,objRock,false,true)>=0The first coordinate here would be (x,y-48), 48 pixels above the object's position. (x,y+48) is the second coordinate, 48 pixels below. So the first instance (lowest instance id) that intersects that line is detected. If that is greater than or equal to 0 (it exists), then destroy it, and check for any other rocks intersecting the line again. Keep doing this until the collision_line() returns a negative number (meaning there are no more rocks in the line), and then stop the while loop.
Pretty complex for beginning GML. I suggest you look up the while statement in the manual for a better explanation.
Anyways, hope this helps, and good luck with your game
#16
Posted 07 May 2009 - 10:15 PM
Edited by Necdilzor, 07 May 2009 - 10:17 PM.
#17
Posted 07 May 2009 - 10:18 PM
No probsEDIT: Damn, I didn't write it right! It works now, thanks a lot for your help!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











