View Full Version : attaching hittest to the movieclip not just a frame
npgames
October 16th, 2006, 10:48 PM
iv looked through tons of tuturials, and they all add the bitmaphittest onto the frames, and i want to know if there is a bitmap hittest code that can be put into the the actual instance, it must be possible, since you can put simple hittest onto the instance,
if there is a tuturial that has this already ill take that to.
Odysseus
October 17th, 2006, 10:29 AM
Are you sure you had a close look at this one (http://www.kirupa.com/forum/showpost.php?p=1922772&postcount=4)?
It also explains how to do bitmap hittesting in Flash8.:egg:
Joppe
October 17th, 2006, 10:58 AM
or you could just learn how to do frame programming...
npgames
October 17th, 2006, 06:15 PM
im a noob to flash and dont get functions and stuff, my main code goes in on,and onclipevents that i insert to the instances, and ill be using this hittest on tons of enemys,
so having a million lines of code in one spot for each collision would be a big mess,
thats why i would perfer to put it all into the individual objects, so eachone has its own code ,i do it for all my normal hittests and wouldnt expect it to be anydifferent for this kind ,altho i wouldnt know.
SacrificialLamb
October 18th, 2006, 02:21 AM
you will get problems if you put hittest on too much. it slows down flash a lot. if you put the code in a for loop you can all the unit's at once in the _root frame ,this will not solve the problem but using for loop's can be very useful in games
npgames
October 18th, 2006, 06:41 PM
i know too many hittests will lag out but i still need a way to put a bitmap hittest onto an instance instead of the frame, ill worry about lag when it hits
SacrificialLamb
October 18th, 2006, 11:20 PM
do you have frame code to change. i thought Odysseus had answered that (did not check the link).
I have not used “bitmap hittest” before but just looking at it why don’t you just add MC’s with the code in one of there frames
npgames
October 18th, 2006, 11:48 PM
import flash.geom.Point;
import flash.display.BitmapData;
this.onEnterFrame = function():Void {
if (red.pixelHitTest(blue)) {
this.red._alpha = this.blue._alpha = 50;
} else {
this.red._alpha = this.blue._alpha = 100;
}
}
this.red.onPress = this.blue.onPress = startDrag;
this.red.onRelease = this.blue.onRelease = stopDrag;
MovieClip.prototype.pixelHitTest = function(mc:MovieClip, threshold:Number):Boolean {
threshold = threshold ? treshold : 1;
var thisBitmap:BitmapData = new BitmapData(this._width, this._height, true, 0);
thisBitmap.draw(this);
var mcBitmap:BitmapData = new BitmapData(mc._width, mc._height, true, 0);
mcBitmap.draw(mc);
if(thisBitmap.hitTest(new Point(this._x, this._y), threshold, mcBitmap, new Point(mc._x, mc._y), threshold)) {
return true;
}
return false;
}
its from the tuturial Odysseus said to look at, and it works great, but i would like it in the actual instance or in the objects frame, because when i try to make another hittest with it, it comes up with errors. i feel im just asking for the impossibe ,am i?
SacrificialLamb
October 19th, 2006, 04:01 AM
took me longer than i thought but here;
(mane time line for revised linked tutorial )
_root.red.onPress = _root.blue.onPress=startDrag;
_root.red.onRelease = _root.blue.onRelease=stopDrag;
import flash.display.BitmapData;
import flash.geom.Point;
MovieClip.prototype.pixelHitTest = function(mc:MovieClip, threshold:Number):Boolean {
threshold = threshold ? treshold : 1;
var thisBitmap:BitmapData = new BitmapData(this._width, this._height, true, 0);
thisBitmap.draw(this);
var mcBitmap:BitmapData = new BitmapData(mc._width, mc._height, true, 0);
mcBitmap.draw(mc);
if (thisBitmap.hitTest(new Point(this._x, this._y), threshold, mcBitmap, new Point(mc._x, mc._y), threshold)) {
return true;
}
return false;
};
on testing MC (this I put on the blue mc)
onClipEvent (enterFrame) {
///..one MC name_____other MC name this time _root.blue
//_root.red.pixelHitTest(this)
if (_root.red.pixelHitTest(this)) {
trace("hit");
_root.red._alpha = this._alpha=50;
} else {
_root.red._alpha = this._alpha=100;
}
}
npgames
October 19th, 2006, 06:00 PM
UR A GENIOUS i cant believe it worked, u made my day man, thx all, never thought ppl would just help noobs like me just for kicks lol
npgames
October 20th, 2006, 09:57 PM
GAME WONT WORK RIGHT GRRR
http://www.freewebs.com/nickpearcegames/sneakin spies 1.4.fla (http://www.freewebs.com/nickpearcegames/sneakin spies 1.4.fla)
this is the game im making, the code you guys gave me worked great with the shape from the tuturial, but now its like a hittest with shapeflag, i shuld have tryed puting the code into the game befor being all happy, i dont understand why it doesnt work
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.