Flash :: Collision Testing With Multiple Objects On Stage?
Nov 27, 2011
I'm trying to create a sort of tree diagram such that, if you click on one of the circles, its child circles spread outward with some degree of randomness from the original circle, connected by lines. I have this working, but now what I want to do is make sure that none of the circles collide with each other and none of the lines criss cross. You can see the screenshot for what is currently happening. My code is below. How do I change this code so that it checks for collisions and avoids them? I've read up on flash's hitTestObject command, but that only works in the context one object to another. I want to test for one object contacting any display object.
import com.greensock.TweenMax;
var sw = stage.stageWidth;
var sh = stage.stageHeight;
[Code].....
View 2 Replies
Similar Posts:
Feb 28, 2009
so I have a function on the Main Timeline that creates an instance of the class Ball once every 60 frames (1 second). In the class code for Ball I have this:
Code:
package {
import flash.display.MovieClip;
import flash.events.*;
[Code].....
As you can see, I am trying to make it so that if two instances of the class Ball collide, then it should output "STOP". But it isn't working.
View 7 Replies
Dec 3, 2009
I'm having a problem with a hitTest that I'm not sure how to correct. Long story short, I have a box that is added to the stage and beings to tween down to the bottom. If the user presses the left arrow to catch the object before it leaves the stage, they get 1 point (hooray!).The issue that I'm having is this...multiple instances of the same MC are supposed to be added to the stage by a timer but because of how I've set it up, they all have the same instance name. That leaves me with one of 2 options. I can get the hit test to work, but only 1 instance ever actually shows up or a bunch show up, but the hitTest fails. How can i add multiple instances of the same object, but still be able to determine if one of them is overlapping the box when the user hits the arrow key?[code]
View 3 Replies
Jun 13, 2010
I want to detect collision for several different objects, but want to keep the code as short as possible. whether I can use an array to hold the different movieclips and then detect collision with the entire array, or if I have to create a class and do it that way.
View 1 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 20, 2011
a way, to manage a multiple collision detection with pixel level detection, for objects, not necessarily circles, irregular objects.
View 5 Replies
Jun 7, 2010
I would like to drag and drop multiple objects and on collision activate/play a video clip.
View 3 Replies
Aug 12, 2009
I got a hitTestObject() problem. I wonder if anyone know if there is a way of testing collission between two movieClip where the transparent part of the movieClip is not to be tested for collission. For example two balls colliding and not wanting the collission to be detected before the balls itself collide (as in the second picture) and not when the squares collide(as in the first).
View 2 Replies
Aug 14, 2009
I'm trying to test clipping on two canvases. Both canvases are 100px wide. They're 20px apart. I've placed a label inside one and made it 200px wide. Scroll bars will show up on the canvas. When I don't have the label inside and use hitTestObject it returns false. When I place the label inside it returns true. Is there any way to alter the canvas with the label inside so that it doesn't expand to the width of the label?
[Code]...
View 1 Replies
Nov 24, 2011
I am making a simulation that involves particles dynamically added to the stage (lots of circles). When these circles collide (which are actually movieclips) they need to rebound (momentum switched). I have no problem with the physics but do not know how to efficiently check for collisions. It boils down to being able to 1) Check if a particle is colliding and 2) Getting which other particle (object) is involved in the collision?
I would ideally like particles to be able to check for their own collisions and adjust their own momentum, not just some meaty Render() function running on every frame. How could this be done?
View 3 Replies
Jan 24, 2011
I have a new flash with several objects(classes) created in as3.They are called Ball1,Ball2,Ball3 and are of type Ball.I wish to be able to insert them into an array and have the array loop test them all against each other like eg. array[i].interact(array[i+1]) and so forthAdditional things I'ld like are:Making sure an object isnt tested against itself,removing objects from an array.sorting the array(if neccessary).adding new objects to the array
View 10 Replies
Mar 16, 2010
I am having a problem with my collision game. When I try to make collision between 2 objects, this occurs: TypeError: Error #1009: Cannot access a property or method of a null object reference. at Level$iinit().
Here is my PHP Code:
package {
import flash.display.*;
import flash.events.Event;
import flash.geom.Point;
import flash.events.Event;
import flash.events.MouseEvent;
public class Level1 extends MovieClip {
[Code] .....
My flash file is at [URL].
View 1 Replies
Oct 28, 2009
Does one normally use some sort of wrapper object to do so?
For example, if I have an array with 10 elements (for example, images that are gonna be linked), I can loop through the array and add them to stage with:
myArray[i].x = i * myArrayElement.width;
What if I wanted to position all of the elements yet keep them in the same positions relative to each other.
Can you do so with an array, I gather the answer is no. So if that's right, do people throw an Array into another object and the use that objects x property?
View 1 Replies
Feb 26, 2010
I'm using Flashcs3 in AS2.[code]My character gets stuck in walls and slows down trying to get out, also, hes about 10x faster now. any suggestions? Im working on a flash overhead shooter, multiplayer only. and I need the script to work so there can still be a bullet collision on each wall and not to be able to walk through it.
View 6 Replies
Nov 25, 2011
I'm having a serious problem with looping through an array. I'm trying to hitTestObject every MC in an array against every other MC in that array.The issue is that in my hitTestObject statement, if obviously looks at only 2 elements at a time.When 2 MC's touch, I set a property called "Touching" to true.The problem is these are moving MCs and at any given time only 2 out of 3 are touching.So what's happening is:The loop runs once testing Array[0] and Array[1].Say those are touching.It sets their "Touching" properties to true(thats what I want).THEN, it runs again testing Array[1] and Array[2], and finds that they are NOT overlapping.It this process it sets both of their "Touching" properties to false, EVEN THOUGH one of them may be overlapping a different array object.I want to individual set the "Touching" property for each array object.Right now these properties are getting overwritten even though 2 out of 3 objects are actually overlapping.[code]
View 4 Replies
May 12, 2010
Is there a method for testing when a shared object has finished loading?because as you can see i have a considerable amount of variables to load, and they don't always load in time.causing many glitches.
ActionScript Code:
wep=saves.data.wep;
backupwep=saves.data.backupwep;
[code]......
View 0 Replies
Oct 14, 2006
I'm writing a general physics engine and I've come across the problem I've always had with flash. So far all my hittests in my physics engine have been calculated by using x/y coordinates and the 2 objects dimensions. This has worked fine for the objects so far because they have been very square-ish and do not rotated. How ever now I am trying to detect if 2 rotated objects are hitting. How can I do this ? I would really like to avoid using any .hitTest() functions.
View 5 Replies
Sep 14, 2009
I was wondering if any of you can spot the error in my code? I got a bunch of objects called 'jelly' that are gonna bounce around my screen but the problem I got is they don't bounce at all! they just run straight off. And yeah I'm very new to actionscript, can anyone see what I'm doing wrong here?
[Code]...
View 4 Replies
Sep 20, 2010
I currently have an over, out and click event for 8 different objects. The over and out events are identical for each (tween expands object and then shrinks it back for the out state).I have previously asked for an easy way to declare those events, and now I was looking for an easier way to handle them.
Here's my code:
//-----------GARAGE
function growGarage(e:MouseEvent):void{
scaleTweenX = new Tween(map_garage, "scaleX", Elastic.easeOut, 0.648, 1, 0.5, true);
[code]....
I've tried using a single function and then using "this" as the object of the tween but that expanded the entire stage.
View 1 Replies
May 20, 2010
I use this pattern to test for undefined and null values in ActionScript/Flex :
if(obj) {
execute()
}
Unfortunately, a ReferenceError is always thrown when I use the pattern to test for child objects :
if(obj.child) {
execute()
}
ReferenceError: Error #1069: Property child not found on obj and there is no default value.Why does testing for child objects with if statements throw a ReferenceError?
View 3 Replies
Jan 16, 2012
I'm having a little problem with collision detection. I'm currently with very simple game, where the only thing that is off is the collision.I tried with hittestobject and (as I found) it checks for the outer layer (my objects are a circle, and a weird star), so this method was of no use to me. Then I tried with hittestpoint, and I found that it checks for the center of the objects, so game over happens only where the center of an enemy touch the center of my character.I know that I must have something missing and I found a lot of guides but all of them were with squares or with static objects
View 3 Replies
Sep 16, 2009
I have Object "A" that moves around and collides with other objects. There are hundreds of other different objects it can collide with. The only way (I found) to test for collision is to loop through every other object. That seems rather inefficient considering I don't even know how many objects exists. Other objects are constantly created and deleted. So this loop would be rather complicated.Is there a way for object A to receive what other object it collided with so that I can then do some code on that other object. Any way to avoid looping? I later need to find out how to detect what objects are near (within x pixels or so) of object A to decide with which one to interact. Maybe that could also be used now to limit the test of collision? Or maybe it gives someone an idea of what to try?
View 4 Replies
Sep 15, 2010
I'm starting with actionscript 2 and I can't figure out how I set a collision mask for enemies and characters. I've got birds that flap their wings but I only want the player to collide with the body, not with the wings, as they take up too much space and it would be unfair.
I tried mc.setMask and other things I found online, but somehow it didn't work, ie: did nothing. I think I don't get the way this works. I thought you'd need like an invisible rectangle that it checks collisions against instead of the actual animation.
View 11 Replies
Dec 27, 2010
[Code]...
I have a serious problem with Action Script. I'm about to code a new Jump&Run game with a simple gravitation Engine. And this is where I got my problem I can not solve! When moving the player through the levels, I want to move the layers instead of him. So the player stays somehow where he is but the enemies, ground, items ... move around - as in most of these games. The gravitation is intendet to affect every item/enemy (by ENTER_FRAME) and moves every object downwards until it hits the ground.
The problem is, objects of different Layers somehow don't get the right hitTest information. So when having two objects - the first on the same layer as the ground, moving both, everything is fine. But as soon as I put the object into a separate container like "itemsContainer:MovieClip" and I move that, the object doesn't get the right result for hitTestPoints. (Maybe it has something to do with localToGlobal??)
[Code]...
View 1 Replies
May 10, 2011
I am creating a scheduling application that shows projects (wrapped within a canvas) on a 2 week calendar timeline.If the user decides to move a project over by a day, i need to check and see if the moving project would then overlap with any other existing projects. If it does, one of the two projects would need to move down the screen along the y axis until the two projects no longer overlap.I've created a function that loops through a repeater item which is used to create the projects... the end result of this function is an arrayCollection that holds:
0. the id number within the repeater
1. the project title
2. x coordinate
3. y coordinate
4. the width of the project
5. the height of the project
I have also created a function that takes the two objects within the array collection and determines if they're overlapping.I can not, however, figure out a working loop that goes through the array collection, compares each item within it, checks to see if they overlap, moves the project if they do overlap, and then continues onto the next project.
Also, I need to make sure that moving one project will not make it overlap with another.I ended up having to reset each elements y value to 0 each time any project is moved and then re-evaluating whether or not they collide.
View 1 Replies
Dec 29, 2011
I have been trying to fix my collision handling for hours now, but it seems like I am running in circles. To be blunt, my collision handling sucks. It is easy to break, and hardly works on complex objects(like water in my case, see the test at megaswf . com / serve / 1577272)
For collision detection I am using the collision detection kit, or CDK.My level is made up of different large MCs, such as a "wall" MC containing all of the smaller walls, such as water, a tree, or a wall. CDK allows me to hittest the single walls by hittesting the large one, and not each one individually, making it easier for myself.My code has a lot of repetition(8 directional movement), so I will put a "//..." to simplify.
Main.as:
ActionScript Code:
public class Main extends MovieClip[code]......
I have literally been working on this all day, and only feel like I'm making it worse every time I change something. You don't have to spoon-feed me code, the idea should be enough...
View 0 Replies
May 8, 2006
I'm making (or rather trying to make) a collision detection demonstration for my Media Studies coursework using a game as an example. However, I use FOR and duplicateMovieClip to create both a) the enemies and b) the bullets. how to register collisions with these objects.
Also, if anyone has any tips for using an array instead of the endlessly repeated "else if (x<num) {" lines, that'd be great to know!
For some reason I can't upload the ZIP file with the Flash in it on this Mac, but I'll upload it back on my own PC soonish. I'm not letting all this stuff I've typed out go to waste!
View 1 Replies
Nov 13, 2009
a little while ago I saw something on this website:[URL]...I decided I wanted to recreate something like it.
They're using javascript, I'm using ActionScript, anyway.I'm trying to create collision detection for an array of movieclips inside a for loop. Right now I have it that upon holding down the mouse, the same movie clip will fall onto a ground object (and bounce up occasionally,) I'm trying to make it to so each ball could stand on top of each other. I've used collision detection before for separate objects, but never for instances of the same object inside a for loop.
View 0 Replies
Jan 16, 2011
I'm running a HitTestPoint to detect when two of my mc's collide, but I don't want them to be able to go right through each other. Someone suggested I find the x,y coords of the moving object when the collision occurs, then update that mc's coords to this x,y each time a collision occurs. I've been Googling but came up empty. Below is my code
private function __checkHit($evt:Event):void {
if (this.coin_mc.hitTestObject(target)) {
if (!hitting) {[code].....
View 2 Replies
Dec 7, 2009
I added a bit of Action Script 3.0 code into a premade flash file that came with my website template.I wanted to link a navigation button to an external url, heres the code:
stop();
home_btn.addEventListener(MouseEvent.CLICK, gotoURL);function gotoURL(event:MouseEvent):void{navigateToURL(new URLRequest("http://www.knirv.com"));}
[code].....
View 3 Replies