there are ways to do perfect collision, google CDK collision kit if you are interested. it works pretty simple and is easy to use in your own projects.
@joshanator1 This video was uploaded 3 years ago. I believe YouTube was SD only at that point. But if you look at the web site, or subscribe to the podcast, you can see the HD version.
@legobatman1 Depends on how you want it to work. There is no one solution. Try the top-down driving game in the book -- that is one solution. But it may not work with your game design. It depends.
A flag is just a variable. For instance, you could create a Boolean variable called alreadyHit, a property of that object. Start it off with false as its value, then set it to true.
Cheers, I saw quite a few of your videos on your website (much better quality and totally readable code), gave me all the basics I needed to get going with flash game programming.
You mean you couldn't read the code in the video? That's because you need to go to the Web site to see higher resolution video and/or download the code.
Ah, so that's what the true / false thing was. Thx, I pulled the code from my teacher's program and was like "waaaaa? Why doesn't making it false affect anything?" I was working with boxes anyways so I couldn't see any difference. :P
A better answer is usually to draw a bunch of invisible (alpha = 0) boxes over the image you want to hit test, and then do the object hit test to each of those boxes. Its not pixel perfect but it can be pretty damn close. For example in the crecent shape, you could draw 3 to 5 boxes roughly in the right shape over it, and hit test against those instead of the cresent itself.
if you wanted to do a pixel per pixel hit test you would have to cycle through the width/height of the intersecting rectangle with double for loops and do a hittestpoint on both images for every pixel of the intersecting rectangle. If any pixel hit both images in the same spot then you have a collision.
Not horribly difficult code to write, but it would probably cause a lot of Lag if you did it every frame or even on a fast timer. It would have to be something you didn't do very often.
The best way to do what you suggesting is to put it in a function with a parameter N for 'precision.' Inside of this function, first you would do a bounding box check, and then you would double loop for every Nth pt, thus reducing lag drastically.
This video is annoying. Just get to the point. And you didn't say what was different between collision detection in AS3 as opposed to AS2/AS1. It's the same lame stuff. Director has had way better collision detection than Flash, btw.
and what does the old chinese proverb have to do with requesting the code? You want me to find it out someplace else? then I wouldnt have come to watch this video?
theabsolute7: Look at hitTestPoint -- it is a little closer to what you want. But you'll have to come up with your own solution for pixel-to-pixel collisions, using either multiple hitTestPoints or converting to a bitmap. Both are processor-intensive.
my question is how we can test the two objects if they intersect pixel-by-pixel in Flash...
This could be done with bounding box collision at first and secondly with pixel check collision. But how can we read pixel RGBA values in Flash for non-Bitmap MovieClips, in order to do the pixel-wise check?..
PS. Bounding box check collision can be done with "if" check, using (_x,_y,_height,_width) attributes of the object - thus I find it as nothing important.
they really should fix the hitTest object function to make it look for the actual pixels and not the bounding box! in such a modern world of high level programming languages!
there are ways to do perfect collision, google CDK collision kit if you are interested. it works pretty simple and is easy to use in your own projects.
Bart0vds 1 week ago
Thanks, just moved on from as2 to as3! Its not too hard just a little different..
Thanks again!!
FuzeMax 6 months ago
wow. you're supposed to be a programming expert and you can't even bump up the
Resolution so I can see the code?
joshanator1 7 months ago
@joshanator1 This video was uploaded 3 years ago. I believe YouTube was SD only at that point. But if you look at the web site, or subscribe to the podcast, you can see the HD version.
macmostvideo 7 months ago
do you know the code for a wall, like you would find in a maze ?
legobatman1 1 year ago
@legobatman1 Depends on how you want it to work. There is no one solution. Try the top-down driving game in the book -- that is one solution. But it may not work with your game design. It depends.
macmostvideo 1 year ago
Thanks! Now my round character won't float over the platform! :D
mission250 1 year ago
You could download the pixel perfect collision class
coolguyflex 1 year ago
look here, my demo with collision detection with physics:
watch?v=u8q6efIibA0
hafiz9977 1 year ago
if (yellowball.hitTestObject(maze1)) {
stop(moveball);
this.gotoAndStop(2);}
This ismy code, but it is not working. Is there anything wrong with it?
0pamat 1 year ago
Only the space between "maze" and "1" -- instance names can't have spaces. Is the name really "maze 1" -- try naming it "maze1" (no space).
macmostvideo 1 year ago
This has been flagged as spam show
if (yellowball.hitTestObject(maze 1)) {
stop(moveball);
this.gotoAndStop(2);}
This ismy code, but it is not working. Is there anything wrong with it?/
the if statement demands true of false responses to your command. That might be the likely reason why your collision detection can't be executed.
By now if you've found the perfect collision code please message me. I'm having the same trouble
BLESSMAN11 1 year ago
is there any way of counting how many collisions an object has had/made?
anything would be great
Scatam 2 years ago
Yes. Just create a variable and add one to it each time there is a collision.
macmostvideo 2 years ago
how do you make it so that when your object hits another object, your object stops. Like a character hitting a wall.
shark10666 2 years ago
Many ways. Just set a flag so you know it has hit, and check that flag before moving it any more.
macmostvideo 2 years ago
How do we set a 'Flag'? I can't find anything on this.
182sambo 2 years ago
A flag is just a variable. For instance, you could create a Boolean variable called alreadyHit, a property of that object. Start it off with false as its value, then set it to true.
macmostvideo 2 years ago
does it matter if you say crescent.HitTestObject(mouse blah blah) or mouse.HitTestObject(cresent blah blah)
coolkid19901 2 years ago
I don't believe so.
macmostvideo 2 years ago
It would be very nice if you made a tutorial on how to see if two movieclips are colliding. Instead of just saying that is complicated o.O
kongreklump 2 years ago 15
thanks for the tutorial :) helped a lot
ShiningNegro 2 years ago
Cheers, I saw quite a few of your videos on your website (much better quality and totally readable code), gave me all the basics I needed to get going with flash game programming.
brianmtyler 2 years ago
i could'nt see a thing :D
HEYLON96 3 years ago
You mean you couldn't read the code in the video? That's because you need to go to the Web site to see higher resolution video and/or download the code.
macmostvideo 3 years ago
Ah, so that's what the true / false thing was. Thx, I pulled the code from my teacher's program and was like "waaaaa? Why doesn't making it false affect anything?" I was working with boxes anyways so I couldn't see any difference. :P
VacantPsalm 3 years ago
A better answer is usually to draw a bunch of invisible (alpha = 0) boxes over the image you want to hit test, and then do the object hit test to each of those boxes. Its not pixel perfect but it can be pretty damn close. For example in the crecent shape, you could draw 3 to 5 boxes roughly in the right shape over it, and hit test against those instead of the cresent itself.
funinvegas1 3 years ago
you could use the Atan2 function to create
a circle peremiter of the object
flashprosoveryou 3 years ago
if you wanted to do a pixel per pixel hit test you would have to cycle through the width/height of the intersecting rectangle with double for loops and do a hittestpoint on both images for every pixel of the intersecting rectangle. If any pixel hit both images in the same spot then you have a collision.
Not horribly difficult code to write, but it would probably cause a lot of Lag if you did it every frame or even on a fast timer. It would have to be something you didn't do very often.
funinvegas1 3 years ago
The best way to do what you suggesting is to put it in a function with a parameter N for 'precision.' Inside of this function, first you would do a bounding box check, and then you would double loop for every Nth pt, thus reducing lag drastically.
sandfire1on1 3 years ago
This video is annoying. Just get to the point. And you didn't say what was different between collision detection in AS3 as opposed to AS2/AS1. It's the same lame stuff. Director has had way better collision detection than Flash, btw.
BedStuyBro 3 years ago
You can't read the code in this video.
sneakyimp 3 years ago 6
You can see a higher resolution version of the video at the FlashGameU web site. You can also download the source there.
flashgameu 3 years ago
@flashgameu would be nice if you put a link in the description.
therealorberon 2 months ago
@sneakyimp I put it on full screen and I can read it fine.
stupidgenius107 4 months ago
the CODEEEE!
anandodasgupta 3 years ago
If you give a man a fish he eats for a day. If you teach a man to fish he eats for a life time.
lautan 3 years ago
and what does the old chinese proverb have to do with requesting the code? You want me to find it out someplace else? then I wouldnt have come to watch this video?
anandodasgupta 3 years ago
theabsolute7: Look at hitTestPoint -- it is a little closer to what you want. But you'll have to come up with your own solution for pixel-to-pixel collisions, using either multiple hitTestPoints or converting to a bitmap. Both are processor-intensive.
macmostvideo 3 years ago
my question is how we can test the two objects if they intersect pixel-by-pixel in Flash...
This could be done with bounding box collision at first and secondly with pixel check collision. But how can we read pixel RGBA values in Flash for non-Bitmap MovieClips, in order to do the pixel-wise check?..
PS. Bounding box check collision can be done with "if" check, using (_x,_y,_height,_width) attributes of the object - thus I find it as nothing important.
theabsolute7 3 years ago
Sure. No magic to it, though -- you just have to examine several points yourself.
macmostvideo 3 years ago
Could you set multiple hitTestPoint along the curve of a circle?
imtehshit 3 years ago
they really should fix the hitTest object function to make it look for the actual pixels and not the bounding box! in such a modern world of high level programming languages!
mate2000 3 years ago
Thank you, exactly what I needed! And to people saying its too blurry. He has a high res version.
Please read the description of videos. Its there for a reason.
IonDuel 4 years ago
to blurry
nailadathug 4 years ago
to blurry i couldnt see the code
sckum555 4 years ago