So im making a game … very very very simple one… ive created my bug killing spray and also the enemy butterfly… but what do you do now to make the butterfly die when its hit with the spray droplets?
A collision detection! When the spray contacts the insect you get a dead insect, so gotoAndPlay a dying sequence or something in your butterfly movieclip.
yeah i tried the collision detection but it wouldn’t work… i named the mc (instance) and attached the collision detection actions to the spray (“bullet”) part of the game but no detection ever happened… im doing all this by the way using the tutorial from this site… so i checked the fire tut and the collsision detection tut and have tried to combine with out success…
heres the AS …
on the spray or otherwise none as the “bullet”:
onClipEvent (load) {
this._visible = 0;
if (_root.fire == 1) {
this._x = _root.Spray._x;
this._y = _root.Spray._y;
}
}
onClipEvent (enterFrame) {
if (this != _level0.bullet) {
if (_root.fire == 1) {
this._x -= -10;
this._visible = 1;
}
if (this._x<0) {
this.removeMovieClip();
}
}
}
onClipEvent (enterFrame) {
if (_root.bullet, hitTest(_root.bf)) {
_root.bf = gotoAndPlay (2);
} else {
_root.bf = gotoAndStop (1);
}
}
the other part of all this is the “spray” bottle which is a button that when pressed fires the “bullet” which in theory when it hits that little butterfly (“bf”) should detect a collsision and nail it…but nothing??
hope thats not to complicated sounding
anyone got any ideas?
here’s a demo .fla … :h:
nobody got a clue then.
help
I tried modifying it, but no matter what I did, even though it logically should of worked, it didn’t.
Your code is actually working. The problem is that you have several “bullets”(not mc) firing at once sometimes hitting,sometimes missing so the text will not change.
try
onClipEvent (enterFrame) {
if (_root.bullet, hitTest(_root.butter)) {
_root.text += 1;
} else {
trace(“missed”);
}
}
nb/text is not such a good name for a variable
i did try only one bullet but it still would not work… heres another .fla , this one is the fire tutorial from this site modified with the hitTest actions taken from the collision detection tutorial from this site… only one bullet but still no detection…
couldn’t upload it but try it for yourself if you like… its in the flash mx tutorial section…
see if this helps.