View Full Version : collisions
jrjacket13
11-01-2004, 06:18 PM
in stick rpg i noticed how when you go to a certain point you got teleported to another spot. i was wondering how you do that because i just can figure it out.
The Brown Cow
11-01-2004, 06:27 PM
The easiest way to perform a collision detection is using hitTest(). This method checks to see if the bounding box of one movie clip is touching the bounding box of another.
Syntax:
mc_first.hitTest(mc_second);
If mc_first is touching mc_second, this evaluates to true. If not, it is false.
So, to enter a building, we need to see if the man movieclip is touching the building's entrance movieclip. If it is, we go to another frame. (This is a simple method, there are much better ways, but they can require hundreds more lines of code)
if (mc_man.hitTest(mc_entrance)) {
_root.gotoAndStop("building_interior");
}
jrjacket13
11-02-2004, 06:56 AM
thx, ive been looking for a good tutorial but all the ones on flashkit.com are confusing. but i understood this, thx alot!
VENGEANCE
11-02-2004, 04:23 PM
Dude, if you can't do that, then you almost certainly aren't ready to make an RPG. Trust me on this. Learn a bit more and come back to it later.
jrjacket13
11-02-2004, 06:33 PM
actually thats about the only thing i dont really know how to do and now that i know how to do it, making the game should go pretty well :wink:
EDIT: I also need help with one more thing. making walls using hittest method. ive tried it and i cant figure it out, can you help me out with that too?
edmarriner
11-29-2004, 08:15 AM
what have i done wrong?
i followed what tbc said i when my man go into the other mc he just walks under !
in the frame i put this code ;
if (mc_man.hitTest(mc_entrance)) {
_root.gotoAndStop(2);
}
stop()
on the man i put this code ;
onClipEvent (load) {
moveSpeed = 19; } onClipEvent (enterFrame) {
if (Key.isDown (Key.RIGHT)) {
this._x += moveSpeed; } else if (Key.isDown (Key.UP)) {
this._y -= moveSpeed; } else if (Key.isDown (Key.DOWN)) {
this._y += moveSpeed; } else if (Key.isDown (Key.LEFT)) {
this._x -= moveSpeed; } }
and gave him the instace name of "mc_man"
my other movie clip ( which will be the door ) no code
gave him the instace name of "mc_entrance"
then made a new frame .
this what i got ;
http://img7.exs.cx/my.php?loc=img7&image=start.swf
help !!!
:?: :?: :?:
arkhan
11-29-2004, 09:21 AM
take that stop part out..the code will go as it enters the frame, so it will play onde, and then stop..what you have to do, is another frame with a gotoAndPlay back to that frame
edmarriner
11-29-2004, 09:51 AM
thanks
:D
edmarriner
11-29-2004, 09:59 AM
arrrrrrrr that did not work
now this happends
http://img95.exs.cx/my.php?loc=img95&image=start2.swf
please help me someone !!!!!
DarkReality
11-29-2004, 10:37 AM
Try not to double post. There's an edit button next to the blue card button and/or the quote button. Use it to edit your posts. Double posts aren't really welcome here.
Do the same thing as you did the first time without the frame looping back. That's an incredibly ugly thing to do when dealing with scripting. Instead, change the
if (mc_man.hitTest(mc_entrance)) {
_root.gotoAndStop(2);
}
stop()
into
_root.onEnterFrame {
if (mc_man.hitTest(mc_entrance))
{
_root.gotoAndStop(2);
}
stop()
}
or it could be
_root.onEnterFrame() {
if (mc_man.hitTest(mc_entrance))
{
_root.gotoAndStop(2);
}
stop()
}
I'm not quite sure of the syntax. But that'll check for a hittest in each frame. Another thing you might want to do is change your framerate to something above 20, otherwise it looks choppy (the brain can interpret 20 images per second, anything about that will melt into a moving object).
The Brown Cow
11-29-2004, 03:28 PM
Wrong syntax for the handler there...
stop();
_root.onEnterFrame = function() {
if (mc_man.hitTest(mc_entrance)) {
_root.gotoAndStop(2);
}
}
arkhan
11-29-2004, 04:16 PM
usually i use
stop();
function _root.onEnterFrame(){
code code code
}
but I usually tell people to do the gotoAndPlay tecnique..not sure why, but its the firist one I think of..
The Brown Cow
11-29-2004, 04:21 PM
I didn't know that would work... cool.
edmarriner
11-30-2004, 12:51 PM
thanks guys.
sry about the double post , wont do it again . :oops:
it works now.
now my games can more gameplay area
:D
also can anyone tell me how to put more than one hitTest() in a frame.
i tried just puting it twice but that did not work. i also tries this ;
_root.onEnterFrame = function() {
if (man.hitTest(entrance))|| (man.hitTest(spikes) {
_root.gotoAndPlay(23);
}
}
but i want it when you hit into the spikes you go to one frames and if you into the entrance mc you go to another.
please can someone tell me how this is done.
thanks
ed
vBulletin® v3.7.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.