The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.36 / 5.00 33,851 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.09 / 5.00 12,195 ViewsSo I've began trying to expand my knowledge of actionscript ( I barerely know all the basic stuff)
but I figured that if I downloaded scripts and looked at them, I would much easily get the principles of hit tests.
I was very wrong.
To the real subject, I am making a test game, to experiment with different techniques and such.
I am trying to do this:
When the "players"s (a movie clip, containing frames like a "walk" animation and a "punch animation") punch movieclip collides with the "enemy" movieclip.
I want the "enemy" (movieclip with 2 frames, the second one being the death animation)
How can I pull this off?
I for some reason arranged so that the code applies to the player, even though it's written on the enemy mc.
onClipEvent (enterFrame) {}
if (_root.playerpunch.hitTest(this.enemyhit)) {
_root.gotoAndPlay(2);
}
I really have little knowledge of what I'm doing, so if I'm totally off, I would really appreciate any sort of help!
Thanks!
Icycrew
Yeah, I'm not such a big fan of random "original" banners or sentences...
ICYCREW.COM
the problem come from the fact that you are referencing your ennemy in relative with "this" so the script will look for a movie clip inside your hero's movie clip. Use _root. instead and it should be fine. hitTest() in itself is a very easy function eithe you test for an object (mc.hitTest(otherMc)) or a point mc.hitTest(otherMc._x,otherMc._y,true). For more info about collision detection look for a thread called As:Main or get a book on action script like flash 8 action script bible(hightly recommended)
althought for what you are doing I would sugest to look for the distance and position(crouching,jumping,behind the hero, etc.) of the ennemy.
i would strongly recomend trying to understand how the AS is compiled, as it will give you a massive insight on what will work and what wont. Dont just learn that i have to use this. here and _root there etc...
Basically, think of the stage as another movieclip.
to refer to the stage you use _root
inside _root is all your graphics and movieclips and buttons
for example, if you had a movieclip with instance name player on your _root he's target will be _root.player.
the . seperates each instance and the final dot access that instance's properties (which can also be thought of as children of that movieclip)
saying this. obviousally means you are refering to the instance the this. is placed on
so if you had the movieclip with target _root.player. saying this on it will be the same as saying _root.player
if inside your player you had another movieclip, called animation for example its target will be _root.player.animation
get the idea?
also, gotoAndStop() sends a function (thus the () after it, which is the sytax for a function) that sets the target its refering to (before its .) to whatever you put as the parameter inside the gotoAndStop()
eg _root.player.gotoAndStop(5) sends the player to frame 5
hope that helped
At 12/9/09 02:38 PM, Yambanshee wrote: hope that helped
Yes! Thank you!
Thanks everyone, I got it to work! :)
Icycrew
Yeah, I'm not such a big fan of random "original" banners or sentences...
ICYCREW.COM