flash actionscript:
I read the Help panel information on BitmapData.hitTest but I find it very vague... For example, the first parameter is: "A point that defines a pixel location in the current BitmapData instance." What's that supposed to do!?! :) All I want to do, is hitTest one BitmapData against another. Thanks in advance.
Let's step outside of Flash for a second. You have 2 images... In the past, you would also have a MASK for each image. The mask is like the image's shadow. There's a part that's solid where the image is opaque, and a part that's white (or black) where the image is transparant... The MASK can facilitate transparancy, but it can also allow quick curved-surface to curved-surface two-dimensional collision detection of sprites. You can also detect which part of each sprite collided with eachother if you're crafty. Suppose you have two white filled circles on black backgrounds... If you take the intersection of their bounding boxes, and then merge their overlap using a raster operation, and then add up the resulting pixels to one resultant value then it will tell if the curved surfaces have collided. The trick is to translate this into a Flash representation... Maybe you could blend the overlapping regions into 1 image, and can you access the underlying data efficiently?
I'll add 1 clarify in case it's not obvious... Let black be 0, and white be 1. Using AND as a raster operation yields: 0 AND 0 = 0 (transparant regions of both masks overlapping at this point) 0 AND 1 = 0 (pixel of one mask overlapping transparant region of the other) 1 AND 0 = 0 (pixel of one mask overlapping transparant region of the other) 1 AND 1 = 1 (The masks have collided!) Usually raster ops are implemented in hardware.. Maybe you can find an analagous alternative in Flash. Good luck.
I'm not looking for workarounds - I'm just curious how to use the BitmapData.hitTest! WizyWig, I am trying to use the BitmapData.hitTest to be able to implement a better MovieClip.hitTest because you can't do a shape hitTest between two movieclips (while BitmapData lets you work at the Pixel level)
How would you even access the BitmapData inside the MovieClip... I created a GIF ball with transparancy, and a curved ramp for it to bounce on. Unfortunately, I can't figure out how to get its BitmapData in order to use that version of hitTest on it. Also, if I *could* get that data, it'll only tell me whether the opaque regions overlap, right? Without knowing the exact point of collision, you couldn't compute proper motion or rotational vectors, whereas with the technique described above, you could do so easily.... I notice how you call it a 'workaround' instead of 'using'.... I call it, 'creating'.... It's much more beneficial to be a creator. Unfortunately, ActionScript is not much of a creator's language. I don't think they (macromedia or adobe) are really serious at that. onClipEvent(enterFrame) { this._y += yvel; this._x += xvel; yvel += yacc; xvel += xacc; var mc:MovieClip = _root["_mcRamp"]; if(mc.hitTest(_x,_y, true)) { trace("Hit!"); } }
Thanks for the links - but I don't *want* the solution, I just want to know how to use the BitmapData.hitTest
Ns, its a little "elitist" of you to say that, but sorry to say, but many times, the way you learn how to do things, or why things work is to "take apart" something that exists already made and rebuilding it while you learn how it works. and this is a case where you have to "see what someone else did" to see why it works the way it does; and learn from that. Did you learn to drive a car by simply just getting in and driving? No right? There isn't much more information you can get on the subject of this because its NEW to Flash 8 and only available in this version. Not many people have bothered to use it, since there are "alternatives" that have been in place for a while, and it TAKES time (and sometimes, over a couple of versions) of the program, before it starts to sink in to "normal" coding. The only resources available are the links I've posted above and the sample file that comes with Flash 8 ( BitMapData.fla). Other than that, yes we are on our own to figure things out.
Ok, fine you win ;) I'll look at it soon (If only MM did a better job on their help files.. if only if...) BTW, did I learn to drive a car by simply justgetting in and driving? Haven't learned yet, but let's hope it is that easy! :)
You should cross refer to my comment in: http://www.macromedia.com/cfusion/webforums/forum/messageview.cfm?catid=288&thre adid=1095288&enterthread=y where I tutorialed how to accomplish what I think you want, without answering what you're asking. It doesn't even use the BitmapData.hitTest function. You're probably used to responses like this by now. The code in it is cool though... a weirdly shaped object bounces and rotates intuitively on a curved surface. It uses the links that WysiWyg provided..... WizyWyg... You could imagine something that doesn't exist yet, then take THAT apart and put it back together. So, you never drove, but driving certainly involves not colliding with anyone or anything. So as long as you got that bit then there's nothing to worry about. That's how I learned how to drive.
Don't see what you're looking for? Try a search.
|