Destroy actor on overlapping actor with specific image
Jeffrey97_0000
Member Posts: 13
Hi,
I'm creating a game in which you have to throw an actor to another actor (which pops-up randomly). Now I want the first actor to be destroyed if it collides with the image of the random actor. The random actor contains two images 1 invisible image and one visible image. I only want the actor which I trow towards the other actor to be destroyed if the visible image of the random actor shows up.
I'm stucked while creating the code. Can anyone help?
Thanks in advantage!!
Comments
I'm not sure how you are making your actor/image invisible.
The usual way is to simply make the alpha channel = 0.
So if you were using this method (alpha = 0) then in the random actor place a rule which says . . .
When this actor collides with the first actor and when alpha = 1
--Destroy this actor.
@Socks
Hi, thanks for your quick reply.
This is what I used to create the visible/invisible actor. The images change from visible to invisible and I'm trying to create a rule which destroys the actor if the visible image is active. Do you know a rule like that?
Again, thanks in advantage!
When this actor collides with the first actor and when self.image = "name of visible image file"
--Destroy this actor.
@Socks
I already tried that one but it doesn't work. I thought it could be because the other actor is also using the same line of code. Maybe there's a code for the visible actor wich destroys the throwable actor?
Thanks in advantage!
Could you take a quick screenshot of the rule that doesn't work.
@Socks
Yes, this is the rule that doesn't work.
I uploaded the image to my own server because I didn't know how to upload it to the forum.
It's hard to tell, but did you simply type the word monkey into the box, or did you first hit the little expression 'e' ? Whichever you did you need to enter the name as text rather than an expression, so don't click on the 'e', just type the word monkey into the box.
@Socks
Yes I did it the correct way, maybe you know how to destroy an actor every time my score attribute goes up (+1)? Maybe that's the way to go?
Thanks in advantage!
And your image file is definitely called monkey (all lower case, no spaces at the start or end - etc) ?
The rule you have shown me:
Is in an actor called throw banana
And this actor (throw banana) has an image applied to it called monkey
And when another actor called monkey game collides with the actor throw banana
and the actor throw banana is displaying the image monkey it should be destroyed.
Is that all as it should be ?
Personally I wouldn't use two images, one for visible and one for invisible.
Where you have a change image behaviour (or whatever you are using to change the image) I would instead use - Change Attribute Self.color.Alpha to 0.
The your rule would be:
When this actor collides with the first actor and when alpha = 1
--Destroy this actor.
. . . . . . . . .
P.S
A trick for getting the alpha channel (or any other attribute) to toggle on and off with each click is:
When touch is pressed (or whatever condition you want):
Change Self.color.Alpha . . . to . . . 1-Self.color.Alpha
So if alpha = 0 to start with:
1-0 = 1 (so now the alpha channel is 1)
1-1 = 0 (so now the alpha channel is 0)
1-0 = 1 (so now the alpha channel is 1)
1-1 = 0 (so now the alpha channel is 0)
1-0 = 1 (so now the alpha channel is 1)
1-1 = 0 (so now the alpha channel is 0)
. . . and so on.
Hope that makes sense.
But regardless you rule (the one in the screenshot) should work just fine ?
@Socks
Thanks for the advice, however it's not quite what I'm trying to accomplishe. I thought maybe there is a rule for an actor to destroy another actor when colliding or overlapping. So basically what I meen is: the image of the actor which comes up randomly has a rule like when self.image is ... (Than destroy the other, overlapping, actor.
Do you know if this would be possible?
Thanks again, you're really helping me out here!!
It's not 100% clear what you are after (for me at least), so I can better understand, could you respond to this question:
. . . . . . . . . .
The rule you have shown me:
Is in an actor called throw banana
And this actor (throw banana) has an image applied to it called monkey
And when another actor called monkey game collides with the actor throw banana
and the actor throw banana is displaying the image monkey it should be destroyed.
Is that all as it should be ?
. . . . . . . . . .
The process is pretty straightforward.
Actor A and Actor B.
In Actor B you would have a rule saying when colliding or overlapping with Actor A and when self.image is 'the visible version of the image' then destroy.
Hi, @Socks
The rule I've shown you is indeed in an actor called throw banana. So basically you have to throw the banana to the monkey and by doing that you'll get a point.
Now, I have two actors which must make this happen. One actor is the monkey game actor, this actor has two stages (one in which it shows an invisible image so the player doesn't get any points) (and the second one is an image called "monkey" which is the image inside the actor "monkey game" if the actor "throw banana" overlaps with the actor "monkey game, image: monkey" than I want the actor "throwing actor to be destroyed. The problem with my rule now is that it will destroy the actor " monkey game" and not the actor "throwing banana".
So in short I want the actor " throwing banana" to be destroyed if it collides or overlaps with the specific image "monkey" within the actor "monkey game".
Now my question is how can I let the image " monkey " inside actor "monkey game" destroy the actor "throwing banana" when they collide? So I thought maybe there's a rule for that?
Do you know?
Thanks in advantage!
Make a boolean game.attribute - let's call it 'X'
. . . . . . . . . . . .
In the Monkey Game actor place a rule that says:
When self.image = Monkey
--Change game.X to 1
---Otherwise
----Change game.X to 0
. . . . . . . . . . . .
In the Throwing Banana actor place a rule that says:
When actor overlaps or collides with Monkey Game and X=1
--Destroy this actor
. . . . . . . . . . . .
@Socks
I see what you're trying to do but there's only one problem, whenever I create a boolean attribute and try to make the last rule you suggested I can't create the rule "and X=1" it says X=true/false.
What am I doing wrong?
Thanks in advantage!
@Socks
I found a method that does work! I put the position of the invisible image offscreen so it can't be touched. And if the image is visible it's positioned on screen so it can collide with the other actor!
Thanks for helping me!
Nothing ! 1 and 0 and true and false are interchangeable, GameSalad will recognise either, but if you don't want to (or cannot) use 1 and 0 then use true and false or Cheese and Chocolate or X and Y or A and B or On and Off . . . . etc, basically use whatever you like, once you are able to communicate two states from one actor to another via a Game.Attribute.
No problem, glad you worked it out.