Added: 4 years ago
From: flashgameu
Views: 37,883
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (45)

Sign In or Sign Up now to post a comment!
  • 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.

  • Thanks, just moved on from as2 to as3! Its not too hard just a little different..

    Thanks again!!

  • 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 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.

  • do you know the code for a wall, like you would find in a maze ?

  • @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.

  • Thanks! Now my round character won't float over the platform! :D

  • You could download the pixel perfect collision class

  • look here, my demo with collision detection with physics:

    watch?v=u8q6efIibA0

  • if (yellowball.hitTestObject(maze­1)) {

    stop(moveball);

    this.gotoAndStop(2);}

    This ismy code, but it is not working. Is there anything wrong with it?

  • 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).

  • is there any way of counting how many collisions an object has had/made?

    anything would be great

  • Yes. Just create a variable and add one to it each time there is a collision.

  • how do you make it so that when your object hits another object, your object stops. Like a character hitting a wall.

  • Many ways. Just set a flag so you know it has hit, and check that flag before moving it any more.

  • How do we set a 'Flag'? I can't find anything on this.

  • 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.

  • does it matter if you say crescent.HitTestObject(mouse blah blah) or mouse.HitTestObject(cresent blah blah)

  • I don't believe so.

  • 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

  • thanks for the tutorial :) helped a lot

  • 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.

  • i could'nt see a thing :D

  • 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.

  • you could use the Atan2 function to create

    a circle peremiter of the object

  • 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.

  • You can't read the code in this video.

  • You can see a higher resolution version of the video at the FlashGameU web site. You can also download the source there.

  • @flashgameu would be nice if you put a link in the description.

  • @sneakyimp I put it on full screen and I can read it fine.

  • the CODEEEE!

  • 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.

  • 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.

  • Sure. No magic to it, though -- you just have to examine several points yourself.

  • Could you set multiple hitTestPoint along the curve of a circle?

  • 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!

  • 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.

  • to blurry

  • to blurry i couldnt see the code

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more