Problems...

10 posts

Flag Post

I have a problem. Maybe a disease or something but here it is:

 	if (_root.ban.hitTest(_root.enemy)) {
	trace('dead');
} else {
	this.gotoAndPlay(1);
}
}

The enemy is a stickman, the ban is an attack by a hero. Where should I put the code and how do I fix it?

 
Flag Post

is “ban” the attack movieclip of your stick guy inside him im guessing? because if it is you need to write the instance name of the one outside it too so like

_root.hero.ban.hitTest

you need to mention all the other movieclips its in.

Where do you put the code? You need to put it in something, you can put it on any movieclip and make sure you have -

onClipEvent (enterFrame) {
if (root.hero.ban.hitTest(root.enemy)) {
trace(‘dead’);
} else {
this.gotoAndPlay(1);
}
}

 
Flag Post

Take a look at Super Ban Jude

It was supposed to have a ban feature but well…

The hero is some chicken guy that’s supposed to be me. The enemy is the stickmens (EmilyG, gamegrl…)

 
Flag Post

Jude,

Here is a very simple example, once you get more experience you will find better ways of doing it, but I wanted to make this simple for this case.

First, make sure that all of your movieclips have instance names. So, let’s assume Eggy is correct and that ban is a movieclip within hero. Make an instance name for both hero and ban. Now, since you can move back and forth already, I’m going to assume that you have an onEnterFrame function handling the arrow keys. Outside of this function make another function called detectHit (or whatever you want to name it) and put this code.

if(hero.ban.hitTest(enemy))
{
    trace("dead");
}

Also remember to put “enemy” as the instance name of the enemy… since you have more than one enemy you will either have to have multiple if statements or perform a loop (if statements will be easier for you, and as long as there are not many enemies you will be fine).

So, now that you have this function you can put detectHit(); into your onEnterFrame code.

Let me know if this works for you.

 
Flag Post

Heh, it didn’t work. Eggy was right about that ban thing. Ok, let me get it straight. I’ve made a function on

 function detectHit(){
if(hero.ban.hitTest(enemy))
{
trace(“dead”);
}
}
and put it into my on (enterFrame) code. Care to explain me which on (enterFrame) do you mean? (Call me a n00b, lolz)

 
Flag Post

Sorry, I should have explained that. the onEnterFrame should be on the frame where the character is being controlled on your main timeline. So wherever you have code that is handling the left and right movement is where you’ll want to put the detectHit();. However, I think this may be causing you an issue: The code you just posted (the function) put that bit of code OUTSIDE the onEnterFrame function. But keep it on the same frame. You are just calling the function in the onEnterFrame loop. Let me know if this works for you, if not then I will work up an example fla for you.

Also, I just reread your comment and this may also be an issue. you want to use

onEnterFrame = function {
}

As your main loop, not on (enterFrame). And it is possilbe that you are using onClipEvent… if this is the case it may be better to change it to onEnterFrame, but for sake of ease you can still use my advice but replace onEnterFrame with onClipEvent.

 
Flag Post

I need an aspirin, can you gimme an example .fla file. Thanks in advance :).

 
Flag Post

Jude,

Here you go. I threw it together really fast so let me know if there are any problems. Also let me know if you have any questions.

hit test example

 
Flag Post

Hey, thanks for the help :)

 
Flag Post

No problem. Let me know when you update Super Ban Jude!