Table element collision detection

Hello!

This is part of my code:

var boxArray:Array = [];
//...
function init():void {
    stage.addEventListener(Event.ENTER_FRAME, loop);
}

function loop(e:Event):void {
//...

if(boxArray.length == 0){
        var totalX:int=9;
        var totalY:int=8;
        var spacing:Number = 10;
        var box_mc:MovieClip;

        for(var i:int = 0; i < totalX; i++){
            for(var j:int = 0; j < totalY; j++){
                box_mc = new Box();
                boxArray[i] = box_mc;
                box_mc.instanceName = "box"+i+j;
                trace (box_mc.instanceName)

                box_mc.x = 80 + i*(box_mc.width+spacing);
                box_mc.y = 70 + j*(box_mc.height+spacing);
                addChild(box_mc);

                trace (boxArray.length)
                //---------------------------------------------it works:)
            }
        }
    }
//there i need to add collision detection for array elements with "ball". Ball is a movie clip on stage.
//need something like that i think:

function collision(){
        var target = one of array element:)

        if(boxArray[target].visible==true){
            if (boxArray[target].hitTestObject(ball)==true) {
                ballSpeedY*=-1;
                score=score+100;
                trace ('Score= ' + score);
                boxArray[target].visible=false;

            }
        }
    }

   collision();



//...
}//end loop

If anyone can help me I will be grateful

Greetings and sry for my English :)

In your collisionDetector function you want to set up two loops as you did when you created them to be able to go through all.  If you were to store in a single dimension table, it would be a loop less to deal with.  If you want / can do depends on if you need to retain the knowledge where the boxes are compared to the i / j clues when it comes to the "/ / do something ' is part of the treatment.

In order to store in a single dimension table just use the push() method of the array class instead of their assignment with the brackets [i] [j].

Tags: Adobe Animate

Similar Questions

  • Management change of HPSMH Collision detection

    Hello world

    We want to just implement collision detection mechanism in the management of change HPSMH. That means that if a CR was raised with a service assigned within a specific date range (say from 2nd to 4th month) .then if any new CR is triggered with the same affected service in the same amount of time then it will show a validation that the services concerned has already been used in a few other CR in the same amount of time.

    Hello and welcome to the HP support community!

    You have posted this question in the section the Community Forum of HP Android tablets.

    According to me, that's not the right area for your question.

    Myself, I have absolutely no idea what you're talking about!   :/

    WyreNut

  • Catalog cannot be displayed in a table element? Is it possible to do them in a format similar to an unordered products list unordered list?

    Hello to the BC community,

    As indicated above, catalog cannot be displayed in a table element? Is it possible to do them in a format similar to an unordered products list unordered list? Overall, I'm looking to create a sensitive site and I like what the general store looks like, I just want to set the flow of catalogue items as I can with products. List items would be great for a catalog item, but I can't seem to locate it in the documentation that comes with BC. I could be completely missing it and if I did, I'm sorry! Thanks in advance for any help I can get with this topic!

    You just need to change the options of the tags - the Developer Reference
    This is the last parameter of the tag.

  • In ActionScript 2 simple Collision detection?

    I'm doing a simple maze game, but the collision detection doesn't work. I have the player moving with the arrow keys, and I'm doing so that when the player collides with the wall, it goes to a certain range. I have this code in the wall clip:

    onClipEvent (enterFrame) {}

    If (_root.player.hitTest (this))

    {

    gotoAndStop ("death");

    }

    }

    Name of the instance of the player's 'player' and the wall instance name is "walls1". When the player hits the wall, the player goes right through it. I'm sure it's something with the collision, not the 'gotoAndStop ("death")"; because I've tested it with "gotoAndStop (5);" and the player is still through the wall.

    If someone could help me, I would really appreciate it. Thanks in advance!

    What object expect you goto frame 5 ("death")?

    You should move your code to the main timeline and target objects.

  • Collision detection changes the location of the MovieClip at random?

    Hello

    I was woundering how I had to code a program in AS3 on collision detection, it would change one of the objects collide at a random X & Y location?

    something like that, but works...?

    ship.addEventListener (Event.ENTER_FRAME, enter_frame);

    function enter_frame(event:Event):void {}

    {if (Ship.hitTestObject (target)}

    Target._x = random (1000)

    Target._y = random (1000) ;}

    }

    Found how do, but it does not work

    It is an AS2 implementation using the random method in your event handler function.  For AS3, use the Math.Random () as a multiplier and the properties of AS3 position (x / y, not _x/FLF).

    ship.addEventListener (Event.ENTER_FRAME, enter_frame);

    function enter_frame(event:Event):void {}

    {if (Ship.hitTestObject (target)}

    Target.x = Math.random () * 1000;

    Target.y = Math.random () * 1000;

    }

    }

  • Slider &amp; amp; Collision detection issue

    I couldn't find anything to help solve my problem thanks to my various research and turned to the publication. First - I am strictly a fan and try to create a timeline of the biography of a genealogy site that I am building.
    I have a scroll bar with a graph like the dredger pocket watch. What I hope to achieve, is that when the Watch has crept along the timeline and is is arrested on a marker (shown as a year), I'd like to pop up the relevant text on this date in time.

    My cursor is a movieclip and markers of the year are buttons. Through my research, it seems that I need to use both the collision detection and a certain type of load a script attached to it. It is quite possible that I am too far from my skill level, but I wanted to tender hand in case there may be help for me.

    I don't really have any code to show that I am very uncertain as to what would be the code appropriate to begin with. You can see an example of what I'm trying to accomplish here-> my scroll bar

    I currently have the text attached to the "over" frame in the button for example.

    Thank you in advance,
    Randy

    Hello

    A quick solution to a situation that involves no collison detection must follow the x position of your clock instead, Minesweeper movieclip. You can use collision detection if you want, but by the way you set up your movie, it will involve a lot of targeting and recovery of the property. This track requires that you only add a few lines to a code you already have.

    Follow these steps

    (1) from the main stage, double-click your mc with the clock and the line in. Create a new layer and put 2 on that dynamic text boxes. Give the first instance of 'xpos' name text box and the other an instance name of "marker". XPos position near the bottom right of the scene and the marker on the opposite side. We will use these boxes for testing.

    2) click on the Actions layer and look for the line that says:

    ratio = Math.round (this._x);

    This guy below

    XPos.Text = report;

    Test your movie and you should see your x on the lower post update when you drag the clock. By working? Well, that's what we want.

    (3) according to the type of line last in what follows

    space var = 3;

    If (ratio > 36 - space & ratio)<>
    Marker.Text = "1900";
    } else
    If (ratio > 172 - space & ratio)<>
    Marker.Text = "1915";
    } else
    If (ratio > 399 - space & ratio)<>
    Marker.Text = "1945";
    }

    OK - explanation - what is happening here is to check if the clock is on one of the markers and we send the right text to the other created textbox marker information previously. If you test your animation and drag toward the center of the 1900 marker you will see its position x is about 36. The space variable adds or subtracts 3 on this position so that we have a good size "struck the area. In other words, if the x position is between 33 and 39 while we are on the marker of 1900. 1915 marker is the same with the other two - between 169 and 175, between 396 and 402 is marker of 1945.

    You can now replace the marker.text = "1900" line with what you want. You can make the box marker text a movieclip and it melted or slide in with the information you want.

    If it helps, then remember to delete the xpos off stage text box and delete the line of script that uses it. It was just to test.

    Here's the complete code

  • Collision detection - then click on next picture

    Hello
    I just took the collision detection works on my classes, but I was not able to get the movie to go to another frame on the collision. What's my problem - I can't use go to 'Film1' in the handle on me, Manager of collisionData. For some reason, it won't let me SO I tried to call another Manager to the statement, moviejump = true. It also did not work - pointers please? Thanks for any help!

    Just set a variable in your collision Manager (a global variable would be easier), which means a frame break. for example:

    on ' t handle me, collisionData
    frameJump = true
    end

    Then, during your exitFrame script, check if this variable has been set:

    on exitFrame me
    If frameJump then
    go to section 3
    end if
    end

    -Ben

  • collision detection: custom class and table

    so I do a shooter from top to bottom for the pleasure, but have been struggling as I am new to programming.

    I have

    var player: player = new Player();

    enemy var: Array = new Array();

    now I searched on the net, but that's what I tried to work with.

    public void checkCollisionWithShip(): void {}

    for (var e = Enemies.length - 1; e > = 0; e-) {}

    If (Enemies [e] .hitTestObject (player)) {}

    trace ([e] Enemies);

    Life = 1;

    updateUI();

    trace ("ship collision!");

    }

    }

    }

    However, whenever my (player) ship hits an enemy, nothing ever happens.

    looking forward to your answers.

    Thank you very much for your time.

    Unfortunately the code that you decide should be shown is not code that needs to be shown.  Which calls the function where the collision is detected?  I don't see anything for this.

  • Collision detection

    Hi, so I applied a few detections of collision on walls using a table. Now I'm stuck when he tries with a single clip (see code). I get an error of syntax of 1084.

    below is what I got so far:

    import flash.display.Stage;

    import flash.display.MovieClip;

    import flash.events.KeyboardEvent;

    import flash.utils.Timer;

    import flash.events.TimerEvent;

    Variables

    var player: Player = MovieClip;

    var pDir:String = new String();

    var pStepSize:int = 5;

    var wallArray:Array = new Array (wall1, wall2, wall3, wall4, wall5, sidewall1, sidewall2, sidewall3, sidewall4);

    var purse: MovieClip = hands;

    var gameTimer:Timer = new Timer (0);

    Identical to gameTimer but then using an ENTER_FRAME (a loop with your framerate speed);

    stage.addEventListener (Event.ENTER_FRAME, __ontick__);

    Init

    Player.Stop ();

    IRDP = "NONE";

    gameTimer.delay = 25

    gameTimer.repeatCount = 0;

    gameTimer.start ();

    Events

    stage.addEventListener (KeyboardEvent.KEY_DOWN, keyPressedDown);

    stage.addEventListener (KeyboardEvent.KEY_UP, keyPressedUp);

    gameTimer.addEventListener (TimerEvent.TIMER, __ontick__);

    Functions

    function onTick(e:TimerEvent):void

    {

    movePlayer();

    rotatePlayer();

    collisionDetectPlayer();

    }

    function __ontick__ when using an ENTER_FRAME event

    /*

    function onTick(e:Event) {}

    movePlayer();

    rotatePlayer();

    collisionDetectPlayer();

    }

    */

    function keyPressedDown(e:KeyboardEvent) {}

    var: key: uint = e.keyCode;

    if(Key == Keyboard.Left) {}

    IRDP = 'LEFT ';

    Player.Play ();

    }

    if(Key == Keyboard.Right) {}

    IRDP = 'RIGHT ';

    Player.Play ();

    }

    if(Key == Keyboard.up) {}

    IRDP = "UP";

    Player.Play ();

    }

    if(Key == Keyboard.Down) {}

    IRDP = "DOWN".

    Player.Play ();

    }

    }

    function keyPressedUp(e:KeyboardEvent) {}

    var: key: uint = e.keyCode;

    If (key == Keyboard.LEFT |)

    key == Keyboard.RIGHT |

    key == Keyboard.UP |

    key == Keyboard.DOWN) {}

    IRDP = "NONE";

    Player.Stop ();

    }

    }

    function movePlayer() {}

    If (IRDP == 'LEFT') {}

    Player.x = pStepSize;

    }

    If (IRDP == 'RIGHT') {}

    Player.x += pStepSize;

    }

    If (IRDP == 'UP') {}

    Player.y = pStepSize;

    }

    If (IRDP == 'DOWN') {}

    Player.y += pStepSize;

    }

    }

    function rotatePlayer() {}

    If (IRDP == 'LEFT') {}

    Player.rotation = - 180;

    }

    If (IRDP == 'RIGHT') {}

    Player.rotation = 0;

    }

    If (IRDP == 'UP') {}

    Player.Rotation = - 90;

    }

    If (IRDP == 'DOWN') {}

    Player.rotation = - 270;

    }

    }

    function movePlayerBack() {}

    If (IRDP == 'LEFT') {}

    Player.x += pStepSize;

    }

    If (IRDP == 'RIGHT') {}

    Player.x = pStepSize;

    }

    If (IRDP == 'UP') {}

    Player.y += pStepSize;

    }

    If (IRDP == 'DOWN') {}

    Player.y = pStepSize;

    }

    }

    function collisionDetectPlayer() {}

    for (var i: uint = 0; i < wallArray.length; i ++) {}

    var wallTemp:MovieClip = wallArray [i];

    {if (Player.hitTestObject (wallTemp))}

    movePlayerBack();

    }

    }

    function collisionDetectMoneybag() {}

    If (player.hitTestObject (moneyBag) == true) {}

    If (dir == 'LEFT') {}

    Move the drive

    Player.x += 1;

    }

    If (dir == 'RIGHT') {}

    Player.x-= 1;

    }

    If (dir == 'UP') {}

    Player.y += 1;

    }

    If (dir == 'DOWN') {}

    Player.y-= 1;

    }

    }

    }

    What Miss me? Help is very appreciated!
    Matt

    If you read the error message is indicating a syntax error... He said that a final brace is missing.

  • Collision detection problem

    Hey guys,.

    I practice so the creation of a platform game. I have a movement system works, but when you try to add collision with platforms I have a problem.

    I did add each platform in a table and then check for the collision between the player and each platform, since I have just a bunch of instances without the platform symbol name on my stage. The problem with this is that my jumping code, I use a Boolean "onGround" value, which determines whether or not the player is "on the ground". And since my loop "foreach" across ALL platforms, even if the player is on a platform of some, there are other, it won't, and if it returns the onGround Boolean false.

    It's a problem with my code of jumping in general, I wonder where I get out of here. If I need to change my code from jumping, or change the collision, or what. Any ideas would be great. Here is my code:

    package  
    {
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.events.KeyboardEvent;
        import flash.display.DisplayObject;
    
        public class Main extends MovieClip
        {
    
            var arrowUp:Boolean = false;
            var arrowDown:Boolean = false;
            var arrowLeft:Boolean = false;
            var arrowRight:Boolean = false;
    
            var arrowUpReleased:Boolean = true;
            var arrowDownReleased:Boolean = true;
            var arrowLeftReleased:Boolean = true;
            var arrowRightReleased:Boolean = true;
    
            var onGround:Boolean = undefined;
            var isJumping:Boolean = undefined;
    
            var vx:Number = 0;
            var vy:Number = 0;
            var acceleration:Number = 1;
            var gravity:Number = 0.3;
            var jumpForce:Number = 7;
    
            var speedLimit:uint = 6;
    
            var platformArray:Array = new Array();
            var platformNumber:uint = 0;
    
            var thePlatform:MovieClip;
    
            public function Main() 
            {
                stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
                stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
                stage.addEventListener(Event.ENTER_FRAME, update);
    
                for (var i:uint = 0; i < numChildren; i++)
                     {
                         if(getChildAt(i) is Platform)
                         {
                             platformArray.push(getChildAt(i));
                         }
                     }
                for each (var platform:DisplayObject in platformArray)
                {
                    if (platform.hitTestPoint(player.x, player.y + 20, true))
                        {
                            vy = 0;
                            onGround = true;
                        }
                }
            }
    
            function keyPressed(event:KeyboardEvent):void
            {
                if (event.keyCode == 37)
                {
                    arrowLeft = true;
                    arrowLeftReleased = false;
                }
                if (event.keyCode == 38)
                {
                    arrowUp = true;
                    arrowUpReleased = false;
                    isJumping = true;
                }
                if (event.keyCode == 39)
                {
                    arrowRight = true;
                    arrowRightReleased = false;
                }
                if (event.keyCode == 40)
                {
                    arrowDown = true;
                    arrowDownReleased = false;
                }
    
            }
    
            function keyReleased(event:KeyboardEvent):void
            {
                if (event.keyCode == 37)
                {
                    arrowLeft = false;
                    arrowLeftReleased = true;
                }
                if (event.keyCode == 38)
                {
                    arrowUp = false;
                    arrowUpReleased = true;
                    isJumping = false;
                }
                if (event.keyCode == 39)
                {
                    arrowRight = false;
                    arrowRightReleased = true;
                }
                if (event.keyCode == 40)
                {
                    arrowDown = false;
                    arrowDownReleased = true;
                }
    
            }
    
            function update (event:Event):void
            {
    
                //ACCELERATION
                if (arrowLeft)
                {
                    if (vx > 0)
                    {
                        vx = 0;
                    }
                    if ((Math.abs(vx)) < speedLimit)
                    {
                        vx -= acceleration/2;
                        player.x += vx;
                    }
                    else
                    {
                        player.x += vx;
                    }
                }
                if (arrowRight)
                {
                    if (vx < 0)
                    {
                        vx = 0;
                    }
                    if (vx < speedLimit)
                    {
                        vx += acceleration/2;
                        player.x += vx;
                    }
                    else
                    {
                        player.x += vx;
                    }
                }
                if (arrowUp && onGround)
                {
                    vy = -jumpForce;
                }
    
                //DECELERATION
                if (arrowLeftReleased)
                {
                    if (vx < 0)
                    {
                        vx += acceleration;
                        player.x += vx;
                    }
                }
                if (arrowRightReleased)
                {
                    if (vx > 0)
                    {
                        vx -= acceleration;
                        player.x += vx;
                    }
                }
    
    
                //GRAVITY
    
                player.y += vy;
    
                if (!onGround)
                {
                    vy += gravity;
                }
                if (onGround && !isJumping)
                {
                    vy = 0;
                }
                if (vy > 0)
                {
                    onGround = false;
                }
                else
                {
                    onGround = true;
                }
    
                //COLLISION
    
                for each (var platform:MovieClip in platformArray)
                {
                    if (platform.hitTestPoint(player.x, player.y + 20, true))
                    {
                        vy = 0;
                        onGround = true;
                    }
                    else
                    {
                        onGround = false;
                    }
                }
    
                trace (onGround);
            }
    
        }
    
    }
    

    Thank you

    PS what is happening right now with that code is that the player hit the platform and stops, but onGround rest false

    Probably, there is too much code for anyone to really go. However, from what you said on your loop for:

    for each {(var plate-forme: DisplayObject dans platformArray)}

    If (platform.hitTestPoint (player.x, player.y + 20, true)) {}

    Vy = 0;

    onGround = true;

    }

    }

    I think what you want is to put a break; in there right after onGround = true; -C' is to say stop the treatment when you find a ground plan.

    Also, there are a couple of collision of good systems out there that might make this a little easier and more robust. Take a look at the Kit of detection of Collision (CDK):

    https://code.Google.com/p/collisiondetectionkit/

  • Placement test / collision detection and HAVE

    Hello
    I am trying to find a way to perform a hit test on an object on the stage. The object makes its appearance through actionscript (block)
    and the object that it is player.
    This will work once I put the block on the scene not manually and not through actionscript, but I want the code allows to call the block because I called several blocks.
    See attached code...
    Could someone please tell me what I'm doing wrong?
    is it not possible that way?

    Thank you!

    Dear adamlewen
    If you want to remove each hittest movieclip, you must do it in a loop "for". so you can detect the hit test and make the corresponding visual effect.
    Here is a sample file: take a peek...
    you have some problem with naming movieclips that I think...
    you duplicated in your table, the elements that cause conflicts

    http://www.parspake.com/Majid/Flash/adamlewen.fla

    good luck and feel free to contact me if you have another problem
    concerning
    MajiD

  • the interference of tiles collision detection

    Hi, I have a bunch of tiles, I try to use as walls for the avatar (maze in place) and I encountered a problem with the detection of collision between two bricks and an avatar, as well as several instances of the same brick. Code attached.

    the_wall is a string. to help the flash to convert this string into a table to use object notation:

  • Calculation for table element, then replace in same table

    I have a 2D, c [j, i] table, and I want to perform calculations on each element of this array, c [j, I] = c [j, I] + d * one update [i], so that the same table with the new values.  I installed the structure using a loop and got back each new c [j, I] that I'm supposed to do, but I can't seem to get these new values into the table.  I tried to use the node 'Replace table subset' but I can't seem to connect the output to the same HP. array [j, I] table.

    Any help is greatly appreciated!

    Hi cmersit,

    Why do you need that for? You have not said before...

    Well, create a local to c [j, I], move it to the for loop and connect with the release of ReplaceArraySubset. It's going to hurt needs memory and processing speed and doesn't help here. Replace [result] with a local of c [j, I] for this example. Otherwise use a shift register in the outer loop!

  • Obtaining of row and column of a table element

    Hello

    I have a table of 24 rows and column 24 giving me a total of 576 items. How can I get the row and column of a particular element in a table in LabView. For example if I write to item 127 How can I get the column and line item 127 is located.

    Kind regards

    Bastien

    Hi Marion,.

    Maybe just need to find the right "address" element in your 2D table?

    Use something like this:

    Maybe you have to out of line & column according to your numbering scheme...

  • problem by removing table elements

    I want to remove some specific instruments in the table (receives program beginning with loop and end element) for which I use table 1 d search for clues then usign remove table, but is not remove all items, or the output is coming as planned.

    The vi which I use to delete items from table is attached.

    saved for 2011

Maybe you are looking for

  • HP Deskjet 3520 interface - cannot access the intercface/printer control program

    I have an old aio by one year of the HP Deskjet 3520 printer (a little over a year old). Recently, my computer (Dell) crashed (about 2.5 years). I have now purchased another HP Pavilion (8.1 64-bit-with 'apps' instead of programs) and when I now clic

  • the SDK help

  • ThinkPad Serial ATA Hard Drive Bay fit III 43N3412 for T61

    Anyone know if this adapter works for T61? So far I couldn't find this "40Y8725 ThinkPad Serial ATA Hard Drive Bay Adapter" on the site that says work for T61.  But I thought Ultrabay options are supposed to be interchangeable? I hope that this is th

  • Why are my DVD is blurry when I burn in CS6 again?

    I'm new to Adobe and whenever I have to burn a DVD through recall, the video is very fuzzy. I am shooting HD video and convert to SD. I know that the video will look not as good, but I don't think that is fuzzy. I tried export and convert the video i

  • Microsoft NLB blocking after upgrade ESX 5.0

    Hi all, I'm new to vmwareWe improve all our ESX 4.1 to 5.0 in February, after that, a lot of multicast NLB Microsoft hangs before upgrade, we used about 2 years with no problems.After upgrade, we have 3 fixed NLB or conflict for 3 months.Any idea? in