Detecting Collisions

Hi
I need to detect wether a movie clip collide to other.. but
the other movieclip has a "blank" space wich hasnt to be
considered... its oval... MovieClip.hitTest detects collision even
in this empty area inside the rectangle
How do I solve it?
I thought of detectiong the color of a single pixel of the
oval movieclip and compating its alpha.. if the alpha is 0 so the
pixel is empty and the collision shall not be detected..
Although I dont know how to get pixel color from a
MovieClip.. is this way the right? is there any other solutions?
thank you all in advance

you can use the bitmapdata hittest or use a ready-made class that uses the bitmapdata hittest like g skinner's collisiondetection class.

Similar Messages

  • Cannot detect collision? Why?

    In the class CharacterClass wich extends Sprite there are 2 member variable that hold current x and y position of the sprite and another two to hold the last x and last y position of sprite before it changes it's position.
    The idea is, if the sprite collides with the TiledLayer, the sprite should return to it's last valid position...
    But, instead of that, the sprite cross the screen and walk through the TiledLayer without detect any collision.
    Any tips, sugestions, advices, will be apreciate...
    Thanks...
    Here's the CharacterClass:
    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.game.*;
    public class CharacterClass extends Sprite {
       private int posx, posy;   // To hold current position of sprite.
       private int lastx, lasty;   // To hold the last x and y positions.
       private int frameWidth, frameHeight;   // To hold size of sprite frame or frames.
       private int lives = 3;
       public CharacterClass(Image image, int frameWidth, int frameHeight) throws Exception {
          super(image, frameWidth, frameHeight);
          this.frameWidth = frameWidth;
          this.frameHeight = frameHeight;
       public int getLives() {
          return lives;   
       public void setLives(int lives) {
          this.lives = lives;
       public void startPosition() {
          posx = 16;
          posy = 16;
          lastx = posx;
          lasty = posy;
          this.setPosition(posx, posy);
       public void moveRight() {
          lastx = posx;  
          posx++;
          this.setPosition(posx, posy);  
       public void moveLeft() {
          lastx = posx;
          posx--;
          this.setPosition(posx, posy);
       public void moveUp() {
          lasty = posy;
          posy--;
          this.setPosition(posx, posy);  
       public void moveDown() {
          lasty = posy;
          posy++;
          this.setPosition(posx, posy);
       public void setLastPosition() {
          this.setPosition(lastx, lasty);
       public void paintSprite(Graphics g) {
          this.paint(g);   
    }And the GameCanvas class, but only the code wich should be fixed:
    public class GameCanvasClass extends GameCanvas implements Runnable {
       public GameCanvasClass() throws Exception {
       player = new CharacterClass(image, 16, 16);
       player.startPosition();
       thread.start();
        while(playing == true) {
             drawGameScreen(g);
             checkInput();
             checkCollision();
             try {
                Thread.sleep(15);
             catch(InterruptedException ie) {
       tiledCenary = TiledLayerClass.buildTiledCenary(gameLevel);
       private void checkInput() {
          int keyState = getKeyStates();
             if( (keyState & UP_PRESSED) != 0)
                player.moveUp();
             if( (keyState & DOWN_PRESSED) != 0)
                player.moveDown();
             if( (keyState & RIGHT_PRESSED) != 0)
                player.moveRight();
             if( (keyState & LEFT_PRESSED) != 0)
                player.moveLeft();
       private void checkCollision() {
          if(player.collidesWith(tiledCenary, false) == true) {   // I've tried with true also in .collidesWith(tiledCenary, true)
             System.out.println("Collision!");
             player.setLastPosition();   // Should return to it's last valid position if there's a collision with cenary...
      player.paintSprite(g);
    }

    Hi:
      I do connect to the device, but not receive anything. I am using serial vis!
      The code is attached!
      THx.
    Attachments:
    HSPFinal.vi ‏92 KB

  • Collision Detection with Tiled Map

    I have a 32*32 tile map size and also 32*32 size image character. I am having difficulty in having the character avoiding walking through the wall. It keeps moving through the wall. Has anyone ever done any similar things as I am? Just need a simple logic method to detect collision with the wall. Thanks

    I usually use simple math against the coordinates of the image to the border of whatever construct is in the way.
    My character objects are usually always aware of their specific coordinate values at corners so before a MOVE, I check to see if the coordinates AFTER the move would fall outside of a specified rectangle area of allowable movement.
    If my condition checking deems it a legal move then I proceed to move the character( Image, Rectangle, etc...)

  • KeyPressed / collision detection

    I have a tile based platformer I am making and am having some trouble with the collision detection. I have it so that the game detects a collision before it actually occurs so that it wont happen in the game. However, it only appears to works right if i tap the arrow key into the wall, and if i hold the arrow key down i fly right through the tile until i let go (if i let go inside a block the hero gets stuck because it detects a collision anywhere i try to move after that). At this time i had the new coordinate to detect collision based on which direction i was moving gotten from keyPressed. Since this didnt work (assumed it was because the game loop and keyPressed dont take turns performing their actions) I made the new coordinate collision be detected from a method called in the main game loop and the result was that if I held down the key and flew into a wall, it doesnt stop exactly at the right spot (but I cant go through an entire row of tiles) but when I go the opposite direction from the collision (open space should work fine) it works fine until a point where in mid air it acts like a collision occured.
    I have tried very hard to find the error in my code concerning the collision detection and need to make sure these problems arent a result of limitations of keyPressed or something, but rather just the code i've written

    ok well I now have it set up so that before the hero moves it checks to see if the move is valid from each pixel starting at the hero to the length the hero moves in 1 directional press (using a rectangle that is the size of the hero, then has width 1 pixel larger etc until reaches the length of a move). The collision detection method returns true if there is a collision at any point, false otherwise. I tried to put the method in both the keyPressed method (for each case of a directional key pressed) as well as in the main game loop (not both at the same time) and neither worked perfectly and both worked about the same. Now the problem is that as long as the hero approaches the tile from a far away distance it works perfectly (a tile is 40 pixels in width and hero is 30), it appears that if the hero approaches from around 40 pixels out it will work but anything less and it will go through the tile as far from the 40 pixel mark it started (ie if hero starts at 37 pixels from tile and moves, it will go through the tile 3 pixels) then it can only travel back to the position it started even if there is no collision detected. Again, it appears that the hero must be about 40 pixels out (not sure if this is coincidence or it is exactly the length of the tile for a reason). Really can't figure this out, dont think there is a problem with the code i have written but probably i'm approaching the solution wrong

  • Good collision detection?

    I have been looking into quadtrees since it is a way to detect collisions. Is there another better way to do this? My game also has a system of sorting sprites in an array based on there relative locations on the map. ie: my character can appear in front of a tree or behind it. I have a complex system to do this which tests polygons however I was wondering if there is an expert way to do this.

    well my tank game has two levels of collision detection. Well, I guess in a way it handles all the items in 3 levels.
    First level, I have a Vector storing the items on the screen. They're only evaluated in any way if they're in the Vector. I refresh that vector every 10 frames by testing all the objects in the game to see if they're in a rectangle that surrounds the screen.
    After that, to check collisions I have a simple distance formula check that finds the distance between the centers of two objects (ie. bullet and tank) and compares them to the sum of the largest dimensions (width for both) to see if they're close enough to collide.
    If that check returns true, it calls a third level of collision checking. This check intersects the areas I've created from polygons that outline my objects. This way even if they're rotated in any way, the check only returns true if there's an honest to goodness real accurate collision. This check takes much longer than the previous one, but since it has the first check behind it, this check isn't called very often.

  • Collisions detection in 3D environments

    Hi, all.
    Has anyone worked with collisions detection in 3D environments?
    I want to create an application in LabView for detecting collisions between 3D objects. I'm working with VRML models and the 3D Picture Control, but I'm open to other posibilities, if they are possible to be integrated into Labview.
    Thanks in advance.
    Regards,
    Francisco

    You may want to check out the new digital
    prototyping tools that just released. It is called the NI SoftMotion Module for SolidWorks and works with SolidWorks 2009 Service Pack 2.1 or higher and LabVIEW 2009 or higher. These tools connect accurate
    mechanical/physics simulation capabilities in SolidWorks with
    industrial-grade motion control software in LabVIEW. There are two ways you can perform collision detection using the tools:
    1. After the your motion control application is finished running, switch the scan engine to configuration mode. (To do this, right-click on My Computer >Utilities>Scan Engine Mode.) Then, in the SolidWorks motion study Motion Manager Toolbar, right-click on the top item in the tree (which has the same name as your assembly) and select Check Interference. Then click on the parts you want to check for collisions on, and select Find Now. If collisions occured, SolidWorks will tell you the time of the collisions and the volume of overlap.
    or 
    2. You can use a distance sensor to detect collisions. In this case, LabVIEW can monitor the sensor while the motion simulation is running and take action (such as stopping the move and alerting you) if the sensor value changes.  This also enables to to detect a "near miss" where the parts came too close for comfort but didn't actually collide. To include
    proximity sensor feedback in your LabVIEW control applications, add a
    dimension to your SolidWorks assembly and connecting it to a Measurement sensor in SolidWorks with an Alert configured
    (for example, alert if the distance is less than 5 mm). Then in
    LabVIEW, right-click on the SolidWorks assembly item in the LabVIEW
    project and select Map Sensors. For an example, launch the LabVIEW Example Finder (Help>Find Examples) and try running the shipping example called "Basic SolidWorks Sensors.lvproj".
    Here's some background information...
    NI
    SoftMotion for SolidWorks enables mechanical, electrical and control
    engineers to collaborate by creating a digital prototype of the motion
    control system that integrates mechanical simulation, motion control
    software, and sensor feedback. As soon as you have a CAD drawing, you
    can begin prototyping the machine design long before you incur the
    expense of building a physical machine. The new tools enable you to do
    thinks like:
    visualize realistic machine operation
    validate and iterate on the mechanical, control and electrical aspects of your design
    estimate the cycle time performance
    check for collisions or other programming mistakes
    calculate force/torque loads for stress analysis 
    select and size motor and mechanical transmission components
    improve communication between the engineers on your team and with customers
    deploy the validated motion control application to NI CompactRIO for use on the physical machine
    The following software versions are required:
    • LabVIEW 2009 (32-bit) or later
    • LabVIEW NI SoftMotion Module Standard or Premium
    • SolidWorks 2009 Service Pack 2.1 or later and SolidWorks Motion Simulation with the Motion Simulation add-in enabled from the Tools menu
    in SolidWorks. This is included with SolidWorks Premium, Simulation
    Premium, or Simulation Professional. When you enable the Motion
    Simulation add-in from the Add-Ins dialog box in SolidWorks,
    place a checkmark in both the left and right checkboxes so you don’t
    have to reenable the add-in each time you use NI SoftMotion for
    SolidWorks.
    For more information, visit this site:
    http://www.ni.com/digitalprototyping/
    Here's a few other resources to get you started. 
    LabVIEW-SolidWorks Digital Prototyping Training (see the topic called "Motion Control Timing and Sequencing")
    Getting Started Guide for NI SoftMotion for SolidWorks
    Here are links to the evaluation versions of LabVIEW and the NI SoftMotion Module for SolidWorks:
    LabVIEW 2009
    NI SoftMotion Module (includes a 30 day evaluation license for NI SoftMotion for SolidWorks)
    Contact your local SolidWorks reseller to purchase SolidWorks, upgrade your existing SolidWorks installation to SolidWorks Premium (which includes the required SolidWorks Motion Simulation capability), or to request an evaluation version of SolidWorks:
    http://www.solidworks.com/sw/contact.htm
    For information on deploying your motion control application to the NI CompactRIO programmable automation controller (PAC) platform, see this site:
    http://www.ni.com/motion/

  • Arming collision detection

    Hi,
    I don't understand how to use the arming arguments in the WakeupOnCollisionEntry class constructers.
    Assume that I have two visual objects, each constructed by hanging a group of Shape3D objects from a BranchGroup node. Suppose I want to detect when these two objects first collide. The WakeupOnCollisionEntry constructors take a Bounds, Node, or SceneGraphPath arming argument. What Bounds, Node, or SceneGraphPath objects do I use here?
    All suggestions will be appreciated.
    Regards,
    Joe

    perhaps you just need to get the branch group of the
    objects you want to detect collisions withYour example works for me. I thought that somehow I would need to specify *2* branch groups and my criterion would wake up when these two collided but it appears that the basic mechanism is that collisions are detected between the specified branch group and everything else. Anyway, thanks for getting me unstuck. The collision criteria are triggering and I can now fool around with the associated methods and sort out how to fine tune the behavior. You might be seeing more questions from me down the line.
    Best regards,
    Joe

  • Round collision detection

    Hi again!
    I have a new problem with collision detection: round areas.
    I have implemented the Rectangle class so far, but I need to detect collision in round areas, like circles, ovals or curves.
    What can I use?
    Thank you so muck

    You could make a few small rectangles around the edges of the curve area which works fine for me.
    http://img460.imageshack.us/img460/8168/collisionqr5.png
    ^Image I made to give you an idea
    Of course, I don't think that's very efficient considering there could be a lot of boxes and it's not perfectly curved.
    You could also figure out how to check the x and y coordinate of whatever you want to collide and compare it's coodinates to the curved object coordinates using
    y = ax^2 + bx + c (parabola)
    ((y - center)^2)/height^2 + ((x - center)^2)/width^2 = r^2 (ovals)
    Not 100% if those formulas are correct and I don't think they would work if you just put them in, but I'm sure you can poke at them and find something. o.O
    I think Google is way overused as a answer in SDN. Google is all right sometimes, but not always. Looking at your link, I saw nothing related to actual collision with curves and even when I added the keyword Java at the end of it I didn't see any clear answer. I thought forums were used for discussion, not as a reminder that Google has taken over the world. <_<

  • I'm trying to make an android game and I want that when a collision with another object change of sc

    I'm trying to make an android game and I want that when a collision with another object change of scene
    how i can do this

    here is the doc on htiTestObject for detecting collisions.
    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayOb ject.html#hitTestObject()
    for scene change use the second parameter in gotoandplay() to define scene name doc below
    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/MovieClip .html#gotoAndPlay()

  • Checking entire array for collision? How? AS 2.0

    Hi!
    I am doing a flash game with Actionscript 2.0 and have encountered a problem.
    I have this statement _root.bulletArray = [] that is storing all my movieclips that have been created with attachMovieClip. I was able to store all bullets in the array because when I say for it to trace the array I get the following:
    _level0.bulletCopy39
    _level0.bulletCopy39,_level0.bulletCopy43
    _level0.bulletCopy39,_level0.bulletCopy43,_level0.bulletCopy47
    _level0.bulletCopy39,_level0.bulletCopy43,_level0.bulletCopy47,_level0.bulletCopy51
    _level0.bulletCopy39,_level0.bulletCopy43,_level0.bulletCopy47,_level0.bulletCopy51,_level 0.bulletCopy55
    _level0.bulletCopy39,_level0.bulletCopy43,_level0.bulletCopy47,_level0.bulletCopy51,_level 0.bulletCopy55,_level0.bulletCopy59
    _level0.bulletCopy39,_level0.bulletCopy43,_level0.bulletCopy47,_level0.bulletCopy51,_level 0.bulletCopy55,_level0.bulletCopy59,_level0.bulletCopy63
    and etc...
    But how do I detect collision with ALL the bullets?
    I have a movieclip that has the instance name: enemy
    I have written the following:
    if(_root.bulletArray.hitTest(_root.enemy))
    trace("hit")
    It dosent work, notihing is traced in the command thing.
    But if I do the follwing:
    if(_root.bulletArray[1].hitTest(_root.enemy))
    trace("hit")
    then it will detect the collision, but only of that bullet, not of the entire array of bullets.
    Any help is highly appreciated! =D
    ----NOTE-----
    I have also tried the followign without sucess:
    if(_root.bulletArray[1,2,3,4,5,6,7,8,9,10].hitTest(_root.enemy))
    trace("hit")

    You need to use a loop to go thru the entire array one element at a time...
    for(i=; i<bulletArray.length; i++){
         if(_root.bulletArray[i].hitTest(_root.enemy))
              trace("hit")

  • PathTransition Object Collision

    Hi,
    I am making a game where a space shooter shoots asteroids.
    I have a space shooter that shoots bullets which are simply small 3x3px rectangles. The bullets move due to a timeline keyframe calling an update function every 50ms which alters the coordinates of the bullets causing them to move across the screen.
    I also have asteroids. When each asteroid (a simple grey circle) is created so is a PathTransition which moves this asteroid along a specified path starting at the time the asteroid is created.
    I want to detect if a bullet has collided with an asteroid in my update function but I don't know how to tell the coordinates of my asteroid when it is moving along the path. I realise this is probably a REALLY stupid question but I just can't work it out.
    Please help

    Maybe you can use the Ellipse's intersects function. It should work well against a Rectangle bullet.
    To answer the generic question (eg. if you want to detect collision of more complex shapes), you can get the position of the shape with its boundsInLocal variable.

  • Detecting color in Flash

    Hi,
    a quick question, well I hope it is..........I wanted to know
    if it was possible to have collision detected in flash by using
    colors rather then shapes (movie clips, graphic etc...), I mean is
    it possible for example to have a range of random colors being
    detected when they come in contact with another particular
    color.......lets say for example I have a black and white checkered
    background and when a particular color (red, blue, yellow) comes in
    contact with this background a sound/animation starts off. The
    sound or animation being played depends on what background color
    (black/white) was in collision with the other color (red, blue
    etc…)………..Hope to get some help thanks.

    Hi Peter,
    Thanks for the reply, however I had looked at this tutorial
    before and it does not detect color only the two movieclips
    overlapping....may be I didn’t explain myself clearly, so
    I‘ll explain what I’m working on and hopefully it will
    clear what is intend to do
    A: I am capturing live motion through a webcam; I have
    managed to separate the user movement from other objects, which
    works fine.
    B: There are animations being played on the screen (bouncing
    balls etc…), these are just general movieclip animations not
    complex at, which work fine as well.
    now I need to create a collision detection so that if the
    user moves in front of an animation the animation moves
    away/disappears etc…currently the webcam image is shown in
    two colors, color1 detects motionless objects while color2 detects
    user movement (motion), so what I need to know is how could I use
    this webcam motion color (color2) to detect collision with the
    animations.
    I have looked at HitTest with flash however this would not
    work as far as I know, as this checks for the registration point of
    two movieclips and not individual differences between
    them……if I have misunderstood HitTest function then let
    me know…thanks
    Hope this explains what I need help with, if further
    explanation is required then let me know……thank you in
    advance.

  • HitTestObject checking collision with pattern

    I've got an enter frame event that checks collision between mouse cursor and objects on the screen. The problem. Every object has a name, however I want to detect collisions between the cursor and objects with a pattern name.
    For example, on the screen there are five objects called
    XObj1
    AObj2
    XObj3
    XObj4
    AObj5
    I want to check collision only between mouse cursor and every object that starts with X or A.
    The solution I had doesn't work out the way I expected because it runs a loop and returns array with an index of these objects. I would like to have a straightforward approach like
    MouseCursor.hitTestObject(stage.getChildByName(Pattern));
    But I don't know if it's possible.
    Thanks in advance

    It seems tough though.
    So, is it possible to have more than one object with the same name?
    A sprite object in an array
    Objects_Array[0].name = Omega;
    Objects_Array[1].name = Omega;
    Objects_Array[2].name = Omega;
    Objects_Array[3].name = Omega;
    So I would check collision among many objects easily.

  • Help with collisions please

    Hi,
    I�m making the final project of my studies. I�m working with a robot maked in vrml. It is a librarian robot an must move around the library maked with vrml too. I have an interface maked with java and I can move the robot manually but I can�t implement the collisions of the robot with the objects of the library.
    I try to use collisionEntry of java but it doesn�t work. How can I detect collisions of the robot with other object? They are implemented with VRML!!aggghhh!!!
    Xema, Spain

    Exactly I have a *.wrl file and I extract from it some TransformGroups, one is the robot. Well, in java collisions need a shape3d for send it to wakeupOnCollisionEntry() in all the examples that I can see. How can I use this transformGroups with the collisions? that is my problem, with the TransformGroups() it doesn�tworks.
    All the components of the wrl file are charged at a BranchGroup object and you can access to it using a hashtable.
    Xema.

  • Detecting intersections between rectangles and circles

    Hello,
    I'm experimenting with collision detection for a game I plan to make. I'm looking into the Rectangle class because it has an intersects() method that would be great for detecting collisions. But now I'm wondering a couple things:
    1) Searching through the swing and awt APIs, I have not found an equivalent class for circles. Is there one or something like it?
    2) The intersects() method for the Rectangle class seems to require another Rectangle (or rectangular coordinates and dimensions). There isn't anything equivalent to testing for intersection with a circle is there?

    Note: This thread was originally posted in the Abstract Window Toolkit (AWT) forum, but moved to this forum for closer topic alignment.Thanks for moving it. I was torn between this forum and the AWT one. Now I know that questions about the Rectangle, Ellipse2D, Shape, etc. classes belong here.
    Check out java.awt.geom.Areadb>
    Anything that derives from the Shape interface will likely work, including Ellipse2D, the class you're likely looking for.Interface Shape
    Class Ellipse2D
    Class Ellipse2D.Double
    >
    These are great classes to know about. Thanks.
    So I can created a bounding "box" for a circular entity using Ellipse2D and it has the method intersects(double x, double y, double w, double h) which tells me whether the specified rectangle intersects this ellipse.
    However, I'm not finding a counterpart for this for Rectangles (i.e. something like Rectangle.intersects(Ellipse)).
    On the other hand, I'm wondering if this will work instead (and if it does, it should work for detecting intersections of any shape with any shape):
    1) Create two Area objects from my Rectangle and my Ellipse2D.
    2) call Area1.intersect(Area2)
    Area1 will now be the intersection between it's previous state and that of Area2. Therefore, if they did indeed intersect, the new area should be non-zero; otherwise, zero. Therefore...
    3) call Area1.isEmpty();
    If original Areas did intersect, this should return false; true otherwsie.
    The only thing I'm not sure about is whether this is in fact what Area.isEmpty() computes. The description in the API doc is not all that clear:
    Tests whether this Area object encloses any area.which sounds like it returns true is the enclosed area is zero, which would be the case if the original Areas didn't intersect.
    Am I on the right track?
    Edited by: gib65 on Jul 5, 2010 9:01 AM

Maybe you are looking for

  • Adobe kann meine Kreditkarte nicht belasten

    Hi, bekam eben eine Mail von Adobe das meine hinterlegte Zahlungsmittel (Prepaid Kreditkarte) nicht belastet werden kann. Die Karte verfügt aber über genügend Guthaben und eine Transaktion steht auch auf der Adobe Seite wenn ich unter meinem Abo nach

  • Open PO's for GR

    Hi , I have a query, Vendor is set for deletion .Blocked in Source list. I have open PO for the Vednor. Is it possible to create GR for Open PO's? Thanks

  • Cannot add songs to iTunes or iPod

    I have restarted my computer many times. Have checked to make sure that all software is up to date. Have gone through all of the "5 R's" except restoring my iPod b/c I do not want to erase the music from my iPod as I have it categorized for work. Doe

  • Picking status/putaway status & Status of warehouse management activities

    Hi experts. I have a question but first let me explain the process. 1) I have a Delivery document and its corresponding transfer order (TO) and the TO is not confirmed and the following status at level item into the delivery are Picking status/puaway

  • Why can you refund me AT&T mistake?

    Charging $40 reconnect fee means they have suspended service, I assume for non payment. So what about this $500 charge for the phone? Why is it in dispute? Have you disputed your bill in writing? You have a limited time to dispute a charge in writing