View Full Version : simple hittest shooter
Hansol
February 5th, 2007, 06:19 PM
im trying to build a simple shooting game but for some reason it wont remove the movie clip when you click on it, here is a little bit of the code.. ill put up the FLA if needed
onRelease = function () {
if (_root.scopemask2.aim.hitTest(_root.target1)) {
removeMovieClip(_root.target1);
}
};
SacrificialLamb
February 5th, 2007, 08:06 PM
have you attached/duplicated the movie clip you can only remove MC that have been added my script.
Have you tried the syntax
_root.target1.removeMovieClip();
Try testing the x/y of both MC's if one is a mask I would expect it might have odd properties
Hansol
February 5th, 2007, 08:54 PM
have you attached/duplicated the movie clip you can only remove MC that have been added my script.
Have you tried the syntax
_root.target1.removeMovieClip();
Try testing the x/y of both MC's if one is a mask I would expect it might have odd properties
Thats the file. the layers are all masked but the action scripts on one layer and yah i didnt add it by script, ill try that.
* umm could anyone please remind me on how to duplicate/add the movie clip so that it can be removed... ive tried everything and it is still not loading, im trying it on my actions script layer it looks like
duplicateMovieClip(loadtarget, testtarget, 1);
load target is the linkage identifer cause its not on the main timeline, and testtarget is what i didnt really get so i put anything.
SacrificialLamb
February 5th, 2007, 10:49 PM
Make one of the MC to duplicate named "targ" and move it out of sight. Then replace all your code with this
this.score = 0;
this.scopemask1.onEnterFrame = function() {
Mouse.hide();
this._x = _root._xmouse;
this._y = _root._ymouse;
updateAfterEvent;
};
this.scopemask2.onEnterFrame = function() {
Mouse.hide();
this._x = _root._xmouse;
this._y = _root._ymouse;
updateAfterEvent;
};
onMouseUp = function () {
fire()
};
//targets with hight x y
var targets:Array = [{w:50.5, h:89.1, x:161.8, y:165.6}, {w:38.5, h:67.8, x:342.4, y:130}];
for (i=0; i<(targets.length); i++) {
temp = _root.targ.duplicateMovieClip("target"+i, 100+i);
temp._width = targets[i].w;
temp._height = targets[i].h;
temp._x = targets[i].x;
temp._y = targets[i].y;
//add target name to ob array
targets[i].name = temp
}
//loop names for hit
function fire() {
for (i=0; i<targets.length; i++) {
if (_root.scopemask2.aim.hitTest( targets[i].name)) {
removeMovieClip( targets[i].name);
}
}
}
What is did was make a object array with the width, height and x/y of 2 of the targets (you can do the others) then looped that to place them (I would normally use attachMovieClip but it's about that same) I think you may have done what I did and looked at the flash Lite 1.x AS help first so I fixed the syntax. I also changed the onRelease (that has to be on an MC) to onMouseUp (dose about the same this) so now that works but you needed to loop the MC names you can’t just name them all the same thing so that is what fire() dose
Hansol
February 5th, 2007, 10:57 PM
thanks alot i finally get it :D
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.