ActionScript 2.0 :: Generic HitTest - Detect Collision With One Object
Oct 13, 2005
Right now I'm working on an advanced hitTesting engine, and What I'm trying to do here is create an engine that will detect collision with one object instead of two. That basically means that if any other objects touch this movie clip, the hitTest will return True. Right now the .fla containing the engine has nothing but a circle that can be moved using arrow keys and 8 squares that disappear when touched by the circle. Obviously, I could do something like:
if (circle.hitTest(square1)) {
do so and so
} else if (circle.hitTest(square2)) {
do this and that
} etc...
But that would be too long, since the engine has to be able to contain 100 squares without too much change in the code.
View 3 Replies
Similar Posts:
Dec 12, 2002
Does anyone know how to use hitTest with two movieclips so that it would detectthe collision of the visible part of the MC, not the **** bounding box???
View 2 Replies
Dec 4, 2009
I've found the BitmapData.hitTest() function very handy, but limited for my purposes. I need to figure out at exactly which point the two images collide (in any coords system,really), since their behaviour will change depending on the angle of the surface hit
View 9 Replies
Apr 18, 2012
I'm trying to create an animated 'LED style' display. I want to draw/tween/type shapes or text and have the 'LED dots' detect the animation and turn on the relevant dots.'ve been testing the hittests but it slows down pretty quickly and the problem with the hitTestObject is that it obviously just detects the bounding box, NOT the vectors.
View 3 Replies
Apr 3, 2004
I'm try to make the Collision Detected with hitTest for long time but it doesn't work. I have two objecct one is the Spaceship and rock. When those two hit each other. I want it to show text "Collision DetectedFrame1 script
var rockCount = 0;
var rockTimeGap = 1;
var nextRockTime = 0;
[code].....
View 3 Replies
Aug 26, 2010
I have two png files, a circle and a maze. Basically the maze is a square with some paths carved through it. I want to draw these images, move the circle to the mouse coordinates, and have a text say 'hit' when the circle intersects a wall of the maze and 'miss' when it doesn't. Now I want to do these using the bitmapdata.hittest method. The circle is a 32x32 image and the maze is a 256*256 image. I've gotten everything set up and everything draws on the screen correctly but I can't get the actual collision detection part of it to work, that is it always displays 'miss' rather than 'hit' even when the circle clearly intersects the maze.[code]
View 1 Replies
Apr 3, 2004
I'm try to make the Collision Detected with hitTest for long time but it doesn't work. I have two objecct one is the Spaceship and rock. When those two hit each other. I want it to show text "Collision Detected" This is my script
Frame1 script
var rockCount = 0;
var rockTimeGap = 1;
var nextRockTime = 0;
var startTime = getTimer();
[code]...
View 3 Replies
Apr 4, 2003
I can't seem to get hitTest to work for the plane in my little game. The code I'm using in the plane MC is:
[AS]if (_root.player.hitTest("_root.badguy"))
playerhealth -= 20;
}
[code]....
I want to the badguy plane to hit the player's plane and take a subtraction from the player's heath. I've fiddled around with using "this" instead of the full path of the playerMC - no success. My hitTest is working fine for the bullets!
View 3 Replies
Mar 10, 2006
For some reason my hitTest in the following function is not working. With each onEnterFrame of the mc being "fired", I am checking to see if it is touching one of the "clouds" I have floating by. My traces tell me that I am targeting everything correctly, but for some reason, hitTest never returns true. Even when I see the mcs colliding. The "clouds" are dynamically attached and pushed into an array (cloudsArr) The clouds and the "fire" mcs are on differnent timelines, but should that matter if I am targeting them correctly?
[Code]...
View 5 Replies
Jan 4, 2011
I'm actually working on a multiple collision detection in actionscript 3.0, using pixel collision for a game for my assignment, where an enemy patrols around and searching for the hero. So, i draw a line between the enemy and the hero, to check whether there's some collision happened between those two. if the line colllides with an obstacle such as wall, door, etc. enemy will not be able to see the hero. When i tried a single line collision with a wall (one object only) it works perfectly.
But here's the problem. For the multiple objects collision (several walls and doors included), i added those objects in an arraylist, When i used for loop to check the collision between the line and those objects in the arraylist, none seems to react , except the first object in the arraylist or index 0.
Is there any simpler way to do the multiple collision detection?
View 2 Replies
Jun 14, 2010
Important: ActionScript 2.0Flash CS3I have some knowledge in Java and C++ which makes this easier... Im trying to make a game and the collision *** does not stop the character in its spot... if i set _y to 0 then it would go to the top of the screen... if i set _y to -1 each frame that the hitTest is active then the character goes through the platform and the rises by -1 (1 up) _y .... how can i make it so the character is stopped immediatly when touching (hitTest) the platform?
[CODE].....
View 6 Replies
Nov 12, 2009
I want to detect when a circle collides into a random object. I know this is pretty basic to do with a mouse colliding into a random object but I want to modify this for a circle. I have seen some examples which use circles but they are drawn in script, is it possible to do this with a mc from the library.
View 2 Replies
Feb 10, 2010
im creating a circle dynamically with each click on stage, with the drawCircle function, now, that circle is a shape, not a movieClip, im arranging this circles inside of an array, and i want to check if they collide, so that second circle dont appear if its occupying the same space as the last one, or at least trace if they are colliding so i can do something about it....
i've made tests with movieClips and no problem, the mc1.hitTestObject(mc) works great but not so great with raw shapes, it just ignores collisions
View 4 Replies
Feb 24, 2005
Is there a way to detect what movie clip is in a certain location? For instance, if I enter some random coords, like x=15, y=0, is there a way it will return the name of the movieclip thats occupies that location?
View 1 Replies
Mar 28, 2005
what i am trying to do is to detect a collision between an empty mc and an mc allready in stage.the empty mc is a line, which I draw with the mouse. when this line hits the other mc I want the colission to be detected. so far it doesnt work properly.the colision is being detected even if the line that i draw, doesnt hit the other mc. does it have to do with the properties of the empty mc, or the hittest method has to be changed?Here is the code:
_root.mc.onEnterFrame=function(){
if(_root.mc.hitTest(_root.line)){
thingstohappen;}
View 1 Replies
Jun 25, 2008
Because I want to detect collision between a point and an MC contained within another MC.
View 1 Replies
Jan 4, 2011
Take a look at this scenario, I have two characters, one shoots two bullets on the direction of the other character, the bullets are fired instantly and travel at infinity speed, how to detect a collision? Here's an image to illustrate the problem: The red bullet would clearly miss, but the green bullet would hit, how to perform this kind of collision test?
View 1 Replies
May 17, 2011
My collision detection is solid when I put 2 images against each other but when I put 1 image against another image's child I can't get a collision. Whats the deal? Do I have to add the child independently of its parent?
View 3 Replies
Apr 9, 2011
If you have a group of movie clips stored in an array and the movie cliops are placed on the stage randomly, and use your arrow keys to move a box on top of one of the movie clips - how can you "tell" Flash which movie clip you clicked on?
Right now I've got a for loop going which loops through the array that has stored the movie clip instances, presumably the hitTestObject would eventually get a hit...But this doesn't work, especially inside an event handler where when I press the right arrow on my keyboard.
[Code]...
View 2 Replies
Sep 28, 2011
0 down vote favorite share [fb] share [tw]
I have a silly problem with Flash (Actionscript 2) and that is:
i want to detect hit using hitTest function when the circle hits to the borders! but i could not! :|
Code:
import mx.transitions.Tween;
var myTween:Tween = new Tween(circle, "_x", mx.transitions.easing.None.easeNone,Stage.width/4, Stage.width-50, 50, false);
[Code]...
The Fla and Swf can be downloaded from Here: mediafire.com/?r045d2ehlbwgvsh
i.stack.imgur.com/iA2Mz.png
View 0 Replies
Feb 1, 2008
The current problem is trying to detect a hitTest with the cursor. I use this code very successfully in AS2, when I cannot use an rollover for whatever reason.
This is my AS2 code:
PHP Code:
onEnterFrame = function(){ if(my_mc.hitTest(_root._xmouse, _root._ymouse)) { race("the mouse is positioned over my_mc") }}
This is me trying unsuccessfully to convert it to AS3:
PHP Code:
stage.addEventListener(Event.ENTER_FRAME, intro); function intro(e:Event):void{ my_mc.hitTest(mouseX, mouseY) { trace("the mouse is positioned over my_mc") }}
View 8 Replies
Nov 5, 2008
i have two movie clips mcTrap and mcCharacter.how can i detect collision (character is fully inside) over the trap door?
View 1 Replies
Feb 23, 2010
So in my game, every 'enemy' movieclip creates a textfield that represents the name of the enemy. The problem is, I want my collision detect engine to detect a collision with the enemy itself, not the textfield. This is the code that I have currently have on my collision class for detecting a collision with the enemy:
for(var i = 0;i < _enemies.length; i++)
{
if(CollisionEngine.isColliding(_laser, _enemies[i]._enemyNameTextField, _animation))
[code]......
View 2 Replies
Apr 12, 2011
i am listening contact between dynamic bodies. But cannot listen contact between dynamic and static bodies .
I can handle collision detection on my b2contactListener class with this metod.
public override function BeginContact(contact:b2Contact):void {
// getting the fixtures that collided
var fixtureA:b2Fixture=contact.GetFixtureA();
[Code].....
View 1 Replies
Jan 9, 2010
I don't understand what is structurally different between a Value Object and a Class in ActionScript3. Can any Class be a VO if you decide to call it one?
View 1 Replies
Mar 4, 2011
Is there a way out there to essentially loop through a generic object to find out what parameters/properties are being used and/or what there names are?
ActionScript Code:
var obj:Object = new Object();
obj.foo = "hello";
obj.bar = "world";
//... and on for however many params you need
[Code] .....
I might be trying to do something that is essentially not possible, but I'm just thinking it would be very nice sometimes to access different parts of an object without having to directly know what the param name is...
View 3 Replies
Dec 20, 2010
I am have a enemy with a sword on 1 image and a player character on another.I test to see if the tip of the enemy sword (point) appears in the player image.
It seems to always detect a hit on the image when it doesnt hit it. The player image has a lot of transparent pixels and it looks like it detects a bounding box hit.Not sure what to do here as this test looks faulty. The y values are correct but the x values seem to cause th issue where xVal is the currect image x value.
x=enemy.xVal+el.x ;y=posY(enemy.yVal-el.y) ;
if (myplayer.img.hitTestPoint(x,y,false)==true)
View 8 Replies
Sep 25, 2005
I've got this code on my frame:
if (_root.count <= 20) {
duplicateMovieClip("_root.clip", "clip"+_root.count, _root.count);
_root["clip"+_root.count]._x = random(500)+50;
_root["clip"+_root.count]._y = random(1)+20;
}
And I need to figure out how to have the hitTest see the randomly generated instances of this duplicated mc.
I can get the hitTest to see the first instance (called "clip"), but then it doesn't see all the rest.
Here's the code I have on the hitTestMC:
onClipEvent (enterFrame) {
if (_root.chime1, hitTest(_root.clip)) {
_root.chime1.gotoAndPlay("play1");
}
}
View 1 Replies
Jun 20, 2007
I'm trying to use hitTest to detect if a dragged clip is over any one of 3 different targets - when it is I want that target to blink. And then when I drag off I'd like the blinking to stop. Make sense? I'm struggling a bit with the following code:
Code:
square_mc.onPress = function() {
this.startDrag();
for (z=1; z<4; z++) {
circle = _root["circle"+z+"_mc"];
[code]....
The "eval(circle)" part isn't really working.
View 4 Replies
Jan 10, 2011
I got it working for using the e.target of the mouse but now I need to filter through the array on enter frame and detect whether a collision is detected.[code]
View 4 Replies