Hittest Multiple MC's
Hi
I think I'm doing something wrong here and hopefully somebody can help me.
I have a movieclip called "roller" in that movieclip I created another movieclip called "dup". I duplicated that "dup" mc 7 times. On the parent movieclip i put the script
onClipEvent (enterframe){ for (i=1; i<=7; i++){ if (this.hittest(_root.roller["dup" add i])){ _root.dragmovie = this; _roothitmovie = _root.roller["dup" add i]; } } }
So now I can check in the dynamic textfields with the variables _root.dragmovie and _root.hitmovie which movieclip I drag and which one I hit.
this works all fine with the first movieclip. _root.dragmovie is then _root.roller.dup1 _root.hitmovie is then f.ex _root.roller.dup3 (depending on which one I hit.
Now when I take _root.roller.dup2 as the one to drag _root.dragmovie stays _root.roller.dup1 (no matter if I first took that one to drag) and _root.hitmovie remains also the same and doesn't change if i hit others.
Help me here please. I know it's something little to change but I can't just find the stupid mistake.
Thx
Tom
FlashKit > Flash Help > Flash ActionScript
Posted on: 06-18-2002, 09:47 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
HitTest For Multiple MCs
hi All,
this is for a multiple MCs hitTest.
part of my code is:
if{!this.hitTest(_root.bu1) && Key.isDown(key.DOWN)} etc.
This works fine with MC bu1. Now i have quite a lot of these 'bu' MCs. bu1, bu2, bu3, bu4 etc, How can i check them all at once? i tried a 'for' loop but i don't exactly know what i'm doing. I guess i want to be able to say if{this.!hitTest("_root.bu" + count) but i have no clue on how to get there. Any help appreciated!
gparis
Multiple Hittest
I want to perform multiple hittesting on the following code.
This code works properly for the first section of hittests.
onClipEvent(keyDown) {
k = Key.getcode();
face2y=getProperty(_root.face2,_y);
face2x=getProperty(_root.face2,_x);
if (k == Key.LEFT)
{_root.pt1l=this.hitTest(_root.game2.part1l);
if (_root.pt1l==false)
{setProperty(_root.face2,_x,face2x-11);}
else{}
}
if (k == Key.UP)
{_root.pt1u=this.hitTest(_root.game2.part1u);
if (_root.pt1u ==false)
{setProperty(_root.face2,_y,face2y-11);}
else{}
}
if (k == Key.RIGHT)
{_root.pt1r=this.hitTest(_root.game2.part1r);
if (_root.pt1r ==false)
{setProperty(_root.face2,_x,face2x+11);}
else{}
}
if (k == Key.DOWN)
{_root.pt1d=this.hitTest(_root.game2.part1d);
if (_root.pt1d ==false)
{setProperty (_root.face2,_y,face2y+11);}
else{}
}
}
Now I want to add hittests for other sections so a keypress would look something like:
if (k == Key.DOWN)
{_root.pt1d=this.hitTest(_root.game2.part1d);
//add this hittest
_root.pt2d=this.hitTest(_root.game2.part2d);
if (_root.pt1d ==false)
{setProperty (_root.face2,_y,face2y+11);}
else
//add this part for second hittest
if (_root.pt2d ==false)
{setProperty (_root.face2,_y,face2y+11);}
else{}
With various manipulations, I can get the first one or the second one to work, but I can't get both to work. I've searched the forum and can't find anything on multiples. Can anyone help me with the proper structure for multiple hittests/if statements? It's probably some stupid little thing that I'm missing, but I've wasted a whole day with different configurations, so help please!
pkw
HitTest With Multiple MC's
I'm working on a little game. I have a little player that moves around. Then I put in mc's (that represent solid objects) and gave the MC's a hitTest to the player that moves around. Only problem is, that the hitTest only works in one of the MC's that represent solid objects.
Thnx
Multiple HitTest........
Hi all,
There r 3 movieclips..... moving, the condition is only if all the 3 moving movieclips pass hittest to each other the clips should stop.
If the following script is used for detecting hittest with other clip. How can i detect hittest for the 3rd clip at the same time
onClipEvent (enterFrame) {
if (this.hitTest(_root.a)) {
}
}
Pls help me...
Kaustubh
Hittest, Multiple Mc's On Top Of Each Other
okay,
here's a tough one for me
i'm doing a hittest on several movieclips. problem is, many of the movieclips are on top of each other. so it's affecting more movieclips that i'd like it to.
suggestions?
code:
if(crayon.mc_hit.hittest(wetlands["mc_"+t])){
brandNewColor = new Color(wetlands["mc_"+t]);
brandNewColor.setRGB(theColorPerm);
}
Multiple HitTest
Can someone help me?
I can't quite sus out how to do multiple hit tests - I would like to have right answers and wrong answers.
Do I need another testObjectArray? I have tried writing another "if this.hitTest" section for the same MC but it does not work...
Have attached the .fla file
Cheers
[F8] Multiple HitTest
Hi, I have a need to detect whether the mouse is hitting multiple movieclips. For the sake of this thread, I am just showing two movie clips.
Eventually, I will write an array to allow the code to be condensed and applied to each instance, but for the moment, I cannot get my head around why this simplistic test isn't working.
My test code is as follows
myMC1.onEnterFrame = function() {
if (myMC1.hitTest(_root._xmouse, _root._ymouse, true)) {
message.text = "hit";
} else {
message.text = "";
}
};
myMC2.onEnterFrame = function() {
if (myMC2.hitTest(_root._xmouse, _root._ymouse, true)) {
message.text = "hit2";
} else {
message.text = "";
}
};
Why can I not have multiple hit tests, all that happens is that myMC1 works but myMC2 doesn't .....
Cannot get my head around why not. Any ideas are more than welcome and any help is v.appreciated.
Regards,
motorpilot
[F8] Multiple HitTest Help
I am tiring to create a simple game for a class assignment. In it a character searches for an object, kinda like a maze. My problem is that when I use hitTest it will only works for one instance of a movie clip (In this case a free standing wall). I've tried many different things with no luck. I will attach a simplified version of my problem - flash8. Thanks for any help.
code placed in hero mc, wall is a1
onClipEvent (enterFrame) {
if (this.hitTest(_root.a1)) {
this.speed = 1;
} else {
this.speed =10;
}
}
[F8] Hittest On Multiple Mc's
Morning all!
Need some help with a problem that I am having with the hittest function.
What I have is a stage with multiple mc's with instance names tile1/tile2/tile3 etc... at present when any of these mc's get hit by another mc with the instance name ball - what I hope do is add a hittest function to the tiles that will tell another group of mc's - instance names shad1/shad2/shad3 etc... to goto and stop on frame 2 when the ball hits the tile mc.
So if tile1 is hit by the mc ball - the tile1 mc disappears and the mc shad1 goes to and stop on frame 2. Does that make sense?!
on all of the tile mc's I have this code to centre the mc's to the stage. This is the AS on the clips;
PHP Code:
onClipEvent(load){startX = this._x;startY = this._y;}
and this is what it looks like when I add what I thought was the right hittest script
PHP Code:
onClipEvent(load){startX = this._x;startY = this._y;}onClipEvent (load) { if (this.hitTest(ball)) { shad1.gotoAndPlay(2); }}
...that code doesn't seem to work though - in fact it doesn't even seem to recognise it!
All of the mc's (ball/tiles/shads) are placed on the main timeline so it shouldn't need any ref to _root. or to _parent. should it?
Anyone put me right???
...please?
Hittest On Multiple MCs
If I have multiple copies of the same MC, each named wellHole1_mc, wellHole2_mc, etc. and then I have another MC called driller_mc, how do I run a hittest on all of those wellHole_mc's? I want the wellHole_mc to react when the driller is moved over it, but I need to know which of the wellHole_mc the driller is over.
Should I be using the hittest function? Or is there some other way to do this?
Attached is the .fla file I have so far.
thanks
david
Multiple HitTest
When you hittest something it returns true if the two objects are connected, right? but when I want to have say 3 of the same instances (Y), and i want hittest to tell me if X touching one of those three Ys, is it possible? When I tried it it only worked for one of them...
Multiple HitTest
I have a scenario where the user drags an item and places it on the corresponding answer in the movie.
What I want to happen is that when the user drops the dragged object, it snaps to the position of the object over which they dropped it. This may not be the correct position. I then want the user to click a button which will check the answers and return to their original position, any answers which are incorrect, leaving behind those items that are in the correct position.
My problem is how to get the object to stick to the item that it is dropped on.
All the target items are called "target" followed by a number.
Any help would be great.
Thanks
Phil
HitTest() With Multiple Objects
If I have a say, 50 boxes and I want them to explode when they hit eachother, what would be the best way to script it? Is there a way for me to name them something like box01, box02, box03 etc.. and then have the hitTest work with every object containing the word "box" in the name?
HitTest() With Multiple Objects
I posted this in the General Help forum, but I think I might have better luck here...
If I have a say, 50 boxes and I want them to explode when they hit eachother, what would be the best way to script it? Is there a way for me to name them something like box01, box02, box03 etc.. and then have the hitTest() work with every object containing the word "box" in the name?
HitTest Playing Multiple Mc
Hi, I've searched through the forum and found this script by oldnewbie which is just what i wanted :
code: onClipEvent (enterFrame) {
// if the mouse IS over the button ...
if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
// play the appropriate clip...
if (_root.menu2._currentframe<_root.menu2._totalframe s) {
// go to the next frame of the menu opening sequence
_root.menu2.nextFrame();
}
// if the mouse is NOT over the button
} else {
// reverse play the clip...
if (_root.menu2._currentframe>1) {
// play the previous frame of the clip
_root.menu2.prevFrame();
}
}
}
but what if I wanted to trigger 2 clip at once? Please help.
Multiple Conditions With HitTest?
I'm trying to create a script using multiple conditions and the hit test. Essentialy I have 6 hit areas and 6 plops so I need a condition to say if hitTest(1) and hitTest(2) and hitTest(3) and so on are in their hit areas go to and play. So this is the code I've come up with and it's not working.
Code:
if (_parent.step1.hitTest() &&
_parent.step2.hitTest() &&
_parent.step3.hitTest() &&
_parent.step4.hitTest() &&
_parent.step5.hitTest() &&
_parent.step6.hitTest()){
_root.play();
}
I'm sure I'm off on how I have the first part but know that I need to use the && to make the multiple conditions. Thanks
HitTest On Multiple Targets
Hey Guys,
I’m trying to setup a MC that has a hitTest that is triggered by multiple targets. Like how do you game developers do this. Like in a shooting game, the bullet will not hit only one target every time. It’s different all the time. So how would you know on a wide range of targets?
Thanks,
Najam D.
UPDATE++++++++++++++++++++++++++++++++++++++++++++ ++++++++
Best Work Around
Quote:
Originally Posted by HeraldofWoe
I think that this will get you on the right track.
(And it specifically addresses your problem Pitchdog)
++++++++++++++++++++++++++++++++++++++++++++++++++ ++
HitTest Multiple Objects
Hi,
I am currently creating a small game, and I want to do the following:
There is one main character. Whenever the character hits a mc (for instance: block001 or block002 or block003 etc.) then it must gotoAndPlay("dead");
My current script is:
Code:
onClipEvent(enterFrame) {
if(this.hitTest(_root.block001)) {
this.gotoAndPlay("dead");
}
if(this.hitTest(_root.block002)) {
this.gotoAndPlay("dead");
}
if(this.hitTest(_root.block003)) {
this.gotoAndPlay("dead");
}
}
And I could go on for some time (because there are many blocks)...
Isn't there an easier way to do this. I thought of something using the var i. and then with something like i++.
But then it only checks one block (either block001 or block002, etc.) per frame. I want it to check all the hits for every frame. Is this possible with a shorter script then writing out every hitTest for every block?
Thanks,
Death
[MX] Multiple Objects HitTest
Hi,
I'm trying to break bubbles by shooting bullets, both generated by duplicateMovieClip(). Everytime I create a bubble, I push it into an array, then on my bullets level, I go through the array, see if I hit anything in there. Here's what I have now:
Code:
onClipEvent (enterFrame) {
var b = _root.bubbles.length;
for (i = 0; i < b; i++)
{
var bubble = _root.bubbles[i];
// We've hit the bubble
if (_root.bubble.hitTest(this))
{
trace("touched: " + bubble);
_root.score_txt.text += _root.scoreplus;
}
}
}
bubbles[] is my array containing the name of all my bubbles (bubbles0, bubbles1, bubbles2..) but for some reason my if condition is never true. On my 'actions' layer, frame 1, I have the following:
Code:
bubbles.push("circle0");
for (i = 1; i < tmi; i++)
{
circle0.duplicateMovieClip("circle" + i, i);
bubbles.push("circle" + i);
}
'tmi' is a variable that changes depending on how many bubbles I want for this level.
Anyone sees what's wrong with this? Other than the fact that it's probably not the best wat of doing it? time is a bit limited and I'm far from being a pro, and this is all I could come up with.
Thanks a lot!
EDIT: Might as well post it here. I have another little problem. When a bubble hits the character, I want to go to the scene called 'Dead', so on my main circle I have the following code:
Code:
onEnterFrame = function () {
if (_root.char_mc.hitTest(this)) {
trace("You die.");
gotoAndStop("Dead", 1);
}
};
The trace works, but the gotoAndStop() doesn't. I'm sure the scene exists, and I have the exact same code on my first scene (Intro -> Game -> Dead)
[CS3] Multiple Hittest Using Arrays
Hello,
I am creating a game where a shopper moves horizontally in a store and runs into different items. When the shopper "hits' an item, he/she displays a speech bubble identifying the item (produce, milk, shopping bag, etc..). I realize that I need to utilize a multiple hittest between the shopper (shopper_mc) and the many items in the store (shopping_bag_mc, produce_mc, milk_mc, etc..).
Here is my current code which resides on a layer in a movie clip called background_mc. The current code does not work.
/////// code begins //////
function hit(){
if (_root.shopper_mc.keyFlag==false){
if (_root.shopper_mc.hitTest(info_desk_mc)){
_root.shopper_mc.attachMovie("speech_produce_mc" , "instance1", 1, {_x:-28, _y:-235});
}
if (_root.shopper_mc.hitTest(shopping_bag_mc)){
//_root.shopper_mc.attachMovie("speech_shopping_bag_ mc", "instance1", 1, {_x:-28, _y:-235});
}
if (_root.shopper_mc.hitTest(milk_mc)){
//_root.shopper_mc.attachMovie("speech_milk_mc", "instance1", 1, {_x:-28, _y:-235});
}
} else {
_root.shopper_mc.createEmptyMovieClip("empty_mc", 1);
}
}
setInterval(hit,4);
///////// code ends ////////
The shopper_mc is at the root level of the movie and all of the product movie clips reside in the movie clip background_mc. I hope this is clear.
Thank you for your time
HitTest With Multiple Objects
heres my fla, I want the hitTest to detect a collision with each wall, but it only works on the first wall, the one below the ball, Is this possible? I know its possible with a for loop and naming each wall wall1, wall2... but Is it possible with just one name?
BTW why doesn't an actionscript based forum allow you to upload .fla files???
HitTest With Multiple Instances
I have attached my .fla. I would like to know how/is it possible to have multiple instances of one mc to use hitTest. If you open the fla, and run it, the trace only works if you hit the block all the way to the left (the first one created), but I want it to work on all of them, is this posible without naming each wall differently and going throught them with a for...loop?
Multiple HitTest Problem
I am having a problem with a hitTest changing a variable on the root timeline. When i move the ball the variable doesn't change when the ball hits the first wall, but does when it hits the second. Any ideas? Here is my code:
Attach Code
onClipEvent (enterFrame) {
for(i=1;i<3;i++){
if(this.hitTest(_root["wall"+i])){
_root.thing = true;
}
else _root.thing = false;
}
if (Key.isDown(Key.RIGHT)) {
this._x+=10;
}
if (Key.isDown(Key.LEFT)) {
this._x-=10;
}
}
Multiple HitTest Questions
Hi, this is a multiple part question, and hopefully if answered, will be able to help several people with multiple problems in the category of Collision Detection.
My first objective is to have the ability to go from frame 1 to frame 2 when an object controlled with arrow keys makes contact with another object (movie clip OR button, preferably both for different reasons). This seems simple but the hitTest help file only talks about coordinates or "on Release" drag-drop versions, and the tutorials don't appear to favor two moving movie clips colliding.
second, I have sliding floors for a jumping ball/character, but the character when landing on the sliding floor remains stationary, so I need some kind of friction to go with the gravity.
Third, If my jumping ball, or bouncing ball is using a greater than 1.0 restitution (trampoline effect) how do I make a ceiling to collide into?
Finally, is there a way to make gravity go sideways or upside-down to simulate wind, and if possible, can both down gravity and x-axis gravity be used together (aka flight/gliding sim)?
[MX] HitTest With Multiple Clips
Hello
For example, say I have 3 movie clips... I want the easiest way to do a hitTest with them... The easiest way I thought of was this but it doesn't work
ActionScript Code:
onClipEvent (load) { mouse.hide(); walls = _root.one or _root.two or _root.three;}onClipEvent (enterFrame) { this._x = _root._xmouse; this._y = _root._ymouse; if (this, hitTest(walls)) { this._x = 10; this._y = 10; }}
It's just a quick example of what im trying to do. one, two, and three are movieclips. Is the way I am trying possible? Or is there some easier way I could go about doing this besides writing it out for each movie clip?
Multiple Instance HitTest
Hi,
Ive got an MC that, when you click, it fires a shot at your mouse, this is what ive got
Code:
onClipEvent (load) {
_root.shot._visible = false;
shotCounter = 0;
maxshots = 1;
depthCounter = 1;
}
onClipEvent (mouseDown) {
if ((shotCounter<=maxshots)) {
shotCounter++;
_root.shot.duplicateMovieClip("shot"+depthCounter,depthCounter);
_root["shot"+depthCounter]._visible = true;
depthCounter++;
}
}
I want my shot to remove itself when it hits another MC, but this MC reproduces itself
(this is the frame code for this MC)
Code:
x++;
score=1+x;
duplicateMovieClip(rock, "rock"+x, x);
It would be great to get some help for the hitTest here! Thanks!
[MX] Multiple HitTest Detection
Basically, I have a game with simple hitTests with a 2d 8-way moving system. I have multiple things that I want to do the same kind of hit detection for, water, trees, etc. Problem is, I can't figure out how to do it. Since you can't set the same instance name for mulitiple objects, I have no idea what to try next. Can anyone help?
[MX] HitTest With Multiple Clips
Hello
For example, say I have 3 movie clips... I want the easiest way to do a hitTest with them... The easiest way I thought of was this but it doesn't work
ActionScript Code:
onClipEvent (load) { mouse.hide(); walls = _root.one or _root.two or _root.three;}onClipEvent (enterFrame) { this._x = _root._xmouse; this._y = _root._ymouse; if (this, hitTest(walls)) { this._x = 10; this._y = 10; }}
It's just a quick example of what im trying to do. one, two, and three are movieclips. Is the way I am trying possible? Or is there some easier way I could go about doing this besides writing it out for each movie clip?
HitTest Multiple Object
Hi,
Need help with this one i'm trying to hitTest mutltiple duplicate object but it dose not work at all.
Thanks
reset = 0;
//
sentence = "THIS IS MY TEXT";
//
for (i=0; i<sentence.length; i++) {
// prevent spaces from being created
if (sentence.charAt(i) != " ") {
// create a movie clip for each symbol
attachMovie("letter", "letter"+i, i);
// set the letter in each movie clip
this["letter"+i].label = sentence.charAt(i);
// set the number of the movie clip
this["letter"+i].number = i;
// set the original x and y to the center
this["letter"+i]._x = 605;
this["letter"+i]._y = 450;
}
if (this.hitTest(this["letter"+i])) {
this["letter"+i].b.gotoAndStop(2);
} else {
this["letter"+i].b.gotoAndStop(1);
}
}
//
Targetting Multiple Instances With HitTest. HELP ME
I am new to Actionscript. I have created multiple instances of a movie clip with the duplicate.moviClip action and they have the names "poll" + i, with i being a number from 0 to 249. I have another script in the movie that I want to be triggered by any of the 250 instances by using if(hitTest(_root.poll*), it works if I put a specific number where the asterisk is but this means it is only triggered by one of the instances.
Is there a way I can target all of them?
Is there a character in Actionscript that can be used as a wildcard such as *.* in MS Dos?
Help me Obi-one Kenobi your my only hope.
Drag N Drop / Multiple Hittest - Help
Hi guys,
I doing this drag n drop system. I have five objects which can be
dropped on three different areas.
When one area is occupied you can't drag anything on top of it.
I want the object to snap to the area when the area are hit and
snap back in its original position when released outside of area or on a occupied one.
Okay, here is my problem when i leave out the "else" code
everything works out great, but when included, the objects snap back in place no matter where i drop them.
"hit" are my hitareas
"name" are the names of my objects
Hope you can help me out, i feel i'm pretty close but something
stinks...
Here are the code on my buttons:
code:-------------------------------------------------------
on (press) {
startDrag(this);
}
on (release) {
_root.drop(this,380,100);
}
------------------------------------------------------------
and here is the code on my first frame:
code:-------------------------------------------------------
var hitArray = new Array();
hitArray = [false, false, false];
function drop(name, xpos, ypos) {
for (i=0; i<3; i++) {
if (name.hitTest(_root["hit"+i]) && hitArray[i] == false) {
name._x = _root["hit"+i]._x;
name._y = _root["hit"+i]._y;
hitArray[i] = true;
stopDrag();
}
}
}
------------------------------------------------------------
Targeting Multiple Instances For Hittest
hello! I'm using hitTest to detect collision of an mc with 31 other MCs... named butmenu1 to butmenu31.
I've got as far as detecting collisions with one MC using this...
'OnClipEvent (enterFrame) {
if(this.hitTest(_root.butmenu.menubut0))
this.gotoAndPlay ("death");
}
and it all works..
Question is how can I expand the above to include collisions with instances menubut2 to menubut31 without writing an if statement for each one??
cheers..
NIk
Detecting Hittest On Multiple Targets
okay here's another bummer, a question about a game application:
so i have this 1 player character, who holds a machine gun. and of course, there are dozens upon dozens of enemies. now i want a bullet to damage anyone of these enemies when it hits them (duh), so what do i do? here's how i tackled the problem...
i create an array of enemy movieclips, let's call it enemyArray.
each bullet is a movieclip unto itself, and has a script that runs every enterFrame that detects if it is intersecting anyone of the enemies in the enemyArray. if it detects that it is within an enemy movie clip, it destroys itself and calls a hit() function that is standard in every enemy MC (which in turn removes a hitpoint from said enemy).
now, i've got a feeling that i've been doing this the hard way, since having to traverse an array over and over and over again for EACH bullet is kind of... overdone. is there some function within Flash that can tell me that if a bullet is intersecting something, and return a reference of that said something? so i can do something like:
Code:
bullet.enterFrame = function(){
var victim = this.getIntersectingMC();//this of course is fictitous
victim.hit();
}
thanks to anyone who can help!
J.
Troubles With HitTest On Multiple Frames...
Hello! I joined this forum just recently in hopes of resolving the many inane bugs that've troubled me during my short foray into Flash MX. I'll just start off with the most recent one, though. I couldn't find this covered anywhere on these forums or anywhere else, so my apologies if it already has been.
Anyways, I'm making this game where you can manipulate a little guy by pressing the arrow keys. He's placed atop another movieclip ('screen') which contains all the blocks and doors that he interacts with. In the first frame of this screen, everything works perfectly; I have two blocks that are labeled 'b1' and 'b2', which both block him successfully. I also have a door ('d2') that takes 'screen' to the second frame, thereby changing the layout of the blocks/doors. However, once he's in this second frame, none of the blocks I've placed in it function; in fact, it doesn't even detect him colliding with them. They're all properly labeled, too. Oddly, though, the door in the second frame works fine and takes him back to frame 1, where everything works perfectly.
Anyone have any idea what's going on? I've managed to do this fine in another flash thing I made. Here's a link to that:
http://s16.photobucket.com/albums/b3...gAnch=imgAnch1
(Just ignore the inane messages during the game, if you could call it that. You can get to the other side by going far enough offscreen, by the way.)
The different frames interact perfectly with the character above it... I can't figure out why it won't in this other flash file. I'll post some code/the file I'm working on if need be. Thanks muchly for your help, and my apologies for the lengthy post.
EDIT: (I'm using a Mac, by the way.)
[MX04] Hittest Multiple Badguys
Hi there, this isnt so much a problem.as i need help tidying up
I have a little game with 10 badguys at places on screen, everytime you jump on one the player bounces off, I have this code
onClipEvent (enterFrame) {
if(_root.CHAR.hittest(_root.TACK) ){
_root.TACK.gotoAndPlay("SINK");
}}
i was wondering how i could change this to include the other 9 badguys (TACK1-9)
without having to copy this all the way down my page but just changing TACK to TACK1 and so on...
Thanks for any help!
[F8] HitTest For Multiple Instances Of Squares?
What is the best way to create tens of squares that each can detect collisions with each other? Luckily I'm working with squares, so even I have created a hitTest that gets the desired movement in one direction (per collision).
But so far my code is only for two squares, and I'm working toward a grid of maybe 24-35 squares. Most of the squares disappear when a category is chosen, but 7-10 squares remain that grow to fit their now roomier surroundings. Each one would detect collisions with the others and react accordingly.
Searching, I've only found a reference to associative arrays, though it didn't elaborate. I will pursue it further if people think it's the way to go. What is the best format for this?
Here's my work so far within the hitTest. Mostly I'm looking to iterate this to create may of them. But please tell me if you know a better way to do hitTests or see somewhere I'm not using good practices, etc.
var difX = this._x - _root.block2._x;
var difY = this._y - _root.block2._y;
// are the squares more side-to-side than above-and-below?
if(Math.abs(difX) > Math.abs(difY)) {
if (this._x < _root.block2._x)this._x = this._x -_root.BUMPSPEED;
else this._x = this._x + _root.BUMPSPEED;
}
// if objects are more side-to-side
// if this one's left go more left
// else go right.
else{
if (this._y < _root.block2._y) this._y = this._y - _root.BUMPSPEED;
elsethis._y = this._y + _root.BUMPSPEED;
}
// otherwise go up or down
[MX04] Multiple Bullet HitTest
(download .fla ) ok so you see the gun and when you shoot a bullet at the wall it moved to the left right? well wen i shoot more than one bullet only the last 1 hits the wall can someone help?
[MX04] Help With Multiple Duplicated MCs HitTest
Okay so I have a game where the"enemys" follow you and you try to run away from them and every around 3 seconds more come, when they hit you you lose health, the problem is that only the first duplicate lowers your health the others follow but when they hit you it does nothing,
the code i'm useing for duplicating it is
code: setInterval(addy,3000);
function addy(){
enemynum = 5
for (var i =0; i<enemynum; i++) {
_root.enemy.duplicateMovieClip("enemy"+i,getNextHi ghestDepth(),{_x:0,_y:0});
}
}
If anyone can help me I would apreciate it.
[MX04] Hittest With Attaching Multiple MCs
I'm making a little game that you make "tanks" when you click on a button,
when you click the button it sets an interval that after about 4 seconds it uses the spawn function which spawns the tank. the trouble is that I can't figure out how to get hitTest or anything to work with the created tanks. Here is the code
for the button
PHP Code:
on(release){
if(gold>49){
spawntanks01 = setInterval(spawntank01,4000);
gold -= 50;
}
}
that seems to work then here is the code for my function
PHP Code:
function spawntank01(){
attachMovie("Tank_01","tank01_"+_root.getNextHighestDepth(),getNextHighestDepth(),{_x:0,_y:435});
_root.clearInterval(spawntanks01);
}
I don't think that I'm using the best way to do this and can't figure out how to do hitTest and whatnot with it.
I'd love some help or suggestions, if you need more info on it I could give you whatever or just attach the FLA
HitTest With Multiple Attached Movies
I'm working on a chain reaction. I want to drop a car on a series of other cars that are in the scene as attached movies. How do I detect the hitTest not only from the first car, but all the other cars hitting all the other cars.
Can I do something like :
_root.car.hitTest(anything)
return the name of the thing that I hit?
MX: Switch Display Multiple MCs Using A Hittest?
I want to display a crowd of people... I have a tiny MC that looks like 3 people standing together- the thing is, I don't want to duplicate them because then they'd be ontop of everything else and they're not supposed to be.
I have a predefined area on which those people will appear and I was thinking to just do the following:
prepare the area with instances of the 3-people-MC for the "maximum amount of people" case (covering the whole area).
have a shape in their midst, filled with a transparent fill (or have it be invisible, if that would still work with a hittest).
resize the shape mentioned in "2." according to how many people I really want displayed (change width and height).
have a function nested in each 3-people-MC that checks whether or not that MC is hit by the shape from "2.".
make the 3-people-MC visible or invisible according to "4.".
Is that doable? how would you write that? Before, I was just working with a mask- but I am having trouble checking if the mask hits the people MCs or not
How would you trigger this test just once when the whole fla is started (and not on every "enterFrame" or such)?
Thanks in advance for your time and effort
~Marcel
IF (multiple Conditions) Hittest And Placement
Hi
I am trying to make an animation with two MC's going through a loop, and when they are both at the loop at the same time, only one, call it mc_a, is allowed through, and the other stays still, mc_b
so, i thought i could use if/then on theMC to stay still, with the IF being a combo of HitTest on the ring, and having an equal X coordinate with mc_a., preferably with a range +/- some level of precision......
but i cant figure out how to make more than one condition in the IF, or if that is even the smartest way of doing it.....
thanks in advance
andrew
Hittest - Setting Visibility Of Multiple MC Instances
I'm trying to create a mini "Scratch-Off" instant win ticket by using a hittest of a coinMC change the visibility of a blockMC.
I can change the visibility of a specific blockMC, by the code below, but how do I change the visibility of multiple instances of the blockMC? (I'm basically placing many blockMC's next to one another to give the illusion of a covered surface that gets scratched away when the coin rolls over the blockMC's).
This is the code for the coinMC:
onClipEvent (enterFrame) {
if (_root.coinMC, hitTest(_root.blockMC)) {
setProperty (_root.blockMC, _visible, false);
}
}
Help please! Pretty please?
HitTest Against Multiple Instance With Similar/same Names
Hi all,
I am quite new to Flash and I am experimenting a bit with making a simple game. I have a bit of a problem.
I made a function to test collisions against walls, this is what it looks like:
code:
function CollisionTest()
{
if (_root.player.hitTest(_root.NorthWall))
{
_y += speed;
}
if (_root.player.hitTest(_root.SouthWall))
{
_y -= speed;
}
if (_root.player.hitTest(_root.WestWall))
{
_x += speed;
}
if (_root.player.hitTest(_root.EastWall))
{
_x -= speed;
}
}
It works perfectly fine if I add one movieclip instance of each wall type. However as I add for example two instances named "SouthWall" then it only works against the one I placed first. How can I make it so that it prevents movement through all instances named "SouthWall" or perhaps "SouthWall1", "SouthWall2" etc?
[F8] Multiple Hittest Twin Loop Problem
Hi,
I've read through these forums for a few years now, and could usually find what I'm looking for with a quick search, but this time I'm well and truly stuck.
I'm creating a flash, with multiple hitttests against multiple movieclips.
The problem is, that each movieclip can be dragged and dropped, which can than hit and move other movieclips, which in turn, hit and move other movieclips.
(Like a dominos effect.)
The problem I'm having is I can't find a solution to satisfy every possible collision based on whether the movieclips are jumbled up.
I have two loops setup, but the movieclips only shift based on increments.
For example(1 -> 2 -> 4 ->8) can shift find,
but,
(1 -> 3 -> 2 -> 6 -> 4) cannot, because they are jumbled instance numbers.
I've attached the .fla to better demonstrate.
I'd appreciate any help, tutorials, or anything similiar because I'm running out of ideas.
Thanks.
HitTest On Multiple Objects In Nested For Loop
HTML Code:
Hi I'm a relatively inexperienced actionscripter and wondered if anyone can help me understand why the code pastd below isn't working?
I'm trying to create a drag and drop activity and the idea is that my any of my draggable movieclips can be dropped on any of the drop movie clips. The problem is I can get any number of the draggable clicks to drop on one specific drop area. But when I insert a nested for loop which I had hoped would allow my drags to drop to any of the available drops it doesn't work. Here's a snippet of my code, I'll attach the whole thing at the bottom. Any help most welcome!
Code:
//STOP DRAG
for (var i = 0; i<numDrags; i++) {
this["drag"+i].onRelease = this["drag"+i].onReleaseOutside=function () {
this.stopDrag();
checkPosition();
};
}
//CHECK POSITION
function checkPosition() {
for (var i = 0; i<numDrags; i++) {
for (var j = 0; j<numDrags; j++) {
if (this["drag"+i].hitTest(this["drop"+j])) {
this["drag"+i]._x = this["drop"+j]._x;
this["drag"+i]._y = this["drop"+j]._y;
} else {
this["drag"+i]._x = this["drag"+i].origX;
this["drag"+i]._y = this["drag"+i].origY;
}
}
}
}
Duplicating Multiple Movie Instances At The Same Time From A HitTest
hey i've been working on this stupid thing for like 2 weeks. I've looked at like every forum and tutorial on the internet and i still can't do it. so... i have this interactive game thing where u can drag around this little movie clip. you start with one and then u can put it in this "duplication machine" and hit the duplicate button and it makes a copy of the movie in the other part of the machine. then you can drag that MC around too. but i cant manage to figure out how to make copies of copies and duplicate like several things at a time. like if i have 5 instances of the same movie in the machine and hit duplicate i want it to make 5 copies of those instances and each copy will go to the current frame of the instance it was copied from. ok hopefully thats not too confusing.. please help if you can!
HitTest On Multiple Objects (duplicated Movie Clips)
i'm making a game, have duplicated movie clips as bullets, i want to know how i can make my enemy die if it is hit by any of the duplicated movie clips
i have tried numerous things
ActionScript Code:
onClipEvent (enterFrame) {if (_parent.hitTest (root.bullet1)) {_parent.gotoAndStop(3)}}
is generally what i want, but i want the "bullet1" to include everything from bullet1-bullet99999999999
is there anything that can act as a wildcard or something
any help would be appreciated
thanks
Duplicating Multiple Movie Instances At The Same Time From A HitTest
hey i've been working on this stupid thing for like 2 weeks. I've looked at like every forum and tutorial on the internet and i still can't do it. so... i have this interactive game thing where u can drag around this little movie clip. you start with one and then u can put it in this "duplication machine" and hit the duplicate button and it makes a copy of the movie in the other part of the machine. then you can drag that MC around too. but i cant manage to figure out how to make copies of copies and duplicate like several things at a time. like if i have 5 instances of the same movie in the machine and hit duplicate i want it to make 5 copies of those instances and each copy will go to the current frame of the instance it was copied from. ok hopefully thats not too confusing.. please help if you can!
|