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.

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

  • 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;

    }

    }

  • 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].

  • 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 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/

  • 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:

  • 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

  • HitTestObject collision detection works not... ish

    Of course, as you can see in this clip of the Hit and Miss is not corresponding to the real event on the stage. Why? It only works if I give the name of the instance of the objects, but does not when you use the name of var. Why?

    Here is the code:

    import flash.events.Event;

    gball var: SmallGreenBall1_T = new SmallGreenBall1_T();

    var bucket: allBuckets = new allBuckets();

    this.addEventListener (Event.ENTER_FRAME, handleCollision)

    function handleCollision(evt: Event): void {}

    If (gball.hitTestObject (bucket)) {}

    output_txt. Text = "HIT."

    } else {}

    output_txt. Text = "MISS."

    }

    }

    Maybe you just need to remove the code.  If you have a gball onstage and a bucket on the stage, use:

    import flash.events.Event;

    this.addEventListener (Event.ENTER_FRAME, handleCollision)

    function handleCollision(evt: Event): void {}

    If (gball.hitTestObject (bucket)) {}

    output_txt. Text = "HIT."

    } else {}

    output_txt. Text = "MISS."

    }

    }

    p.s. If this fails, is interpolated gball schedule?

  • Collision detection / video clip after another

    I'm working on a shooting game space horizontal scrolling, and I hit a snag: the clip of rocket has two nested layers, for the ship itself and the other for a cycle of animation of the flames out by behind.  The ship loses health when it collides with an enemy ship, but given that the two bodies of the ship and the flames are part of the same clip, the ship, of course, also loses health when the flames hit an enemy ship.  What I'm trying to do, is change it so the fire will destroy the enemy ships, but the player loses all health.  My first inclination was to separate the flames in their own clip and simply attach the ship - that is to say, the clip of flames is basically apparent aboard the ship, on a layer below, but is controlled by a separate script as the ship itself.  The flames would be aligned with the ship, and when the ship is moving, the flames are moving.  Pretty simple.  So far, I have found no effective way to do this.  I tried alternatives (masking, etc, etc) nothing works.  I work in Flash 8, AS2.  Each video clip has its own class.  I can view the code if necessary.  Any advice, or simply a point in the right direction would be greatly appreciated.  Thank you!

    use:

    }
    If (this.hitTest (_root.ship.shipBody))
    {
    If (_root. Ship.Shield._visible is false)
    {
    _root. Ship.updateHealth (-20);
    }
    explode();
    }

    If (this.) HitTest (_root. Ship.shipFlames) {/ / assuming shipFlames is correct}

    explode();  Assuming you want the enemy to the discovery of the touch of flame

    }

  • Collision detection - falling through objects

    * EnglishVersion follows after German *.

    Hallo Zusammen,

    ICH habe ein ernsthaftes problem in Flash. Ich bin ganz gut actually in der Materie und programiere just Jump & Run Spiel ein drin.
    However kommt are just dennoch zu einem ernsthaften problem, das ich nicht losen kann.
    Wenn ich in meinem Spiel die Figur bewege, soll sich nicht die Figur, das level therefore does moving. Dabei gibt yesterday are several container, as opponents as Bonus usw items und die.
    Alle haben eine "Gravitation" (im ENTER_FRAME) objects, fallen die dafur sorgt, dass sie nach unten, wenn sie nicht auf einen auftreffen Boden.
    Works das im Prinzip recht einfach, dass nur verschiedener Ebenen durcheinander hindurchfallen objects. Das vielleicht liegt an den (localToGlobal) - Koordinaten oder so something?
    Konkret ist das problem, dass objects additional einer Ebene (bsp. eine "Bonusitem-ebony") durch den Boden (der "Boden-ebony") fell. Objects, die der Ebene wie der Boden sind, das nicht however tun same.

    ICH habe das bad als Helferinelement CS3 sales, so dass ihr euch das problem anschauen könnt.
    Der link pesimos:
    www.Tobias-Reich.de/flashproblem.fla

    Yesterday ist auch noch der once Code:

    function() {return A.apply (null, [this] .concat ($A (arguments)))}

    / * Press the keys for a while see what happens! * /
    addEventListener() event. ( ENTER_FRAME, fall();
    Stadium. addEventListener () KeyboardEvent. ( KEY_DOWN, move();
    ( var ballLayer:MovieClip = new MovieClip()();
    addChild ()ballLayer ();
    / / ball is down-> falling down after a certain time
    var ball:MovieClip = new ball()();
    ball. x = 100;
    ball. y = 150;
    ballLayer. addChild (ball);
    / / ball on the same layer-> it works perfectly fine!
    var ball2:MovieClip = new Ball2()();
    ball2. x = 120;
    ball2. y = 150;
    ball2 addChild ()();
    var field:MovieClip = new Ground()();
    on the ground. x = 100;
    on the ground. y = 200;
    field of addChild ()();
    function ( ()eautumn: event():void { }
    if () ! on the ground. hitTestPoint () ball. x, ball. y, true)){
    ball. y +=5;
    }
    if () ! on the ground. hitTestPoint () ball2. x, ball2. y, true)){
    ball2. y +=5;
    }
    }
    ( function move()e: KeyboardEvent ():void { }
    on the ground. x +=5;
    ballLayer. x +=5;
    ball2. x +=5;
    }

    PS Mir ist klar, dass im Spiel right in own Klassen und nicht naturally in der chronology programmiert wird. DAS nur der yesterday dient der Situation Einfacheit.
    I hope, ihr mein problem being.
    Ich bin ratlos, half mir bitte!

    Alles gute und einen guten Rutsch ins Neue Jahr.

    Tobias

    ----------------------------------------------

    Hello

    I have a serious problem with the Action Script. I'm about to code a new Jump & Run game with a simple gravity engine.


    And that's where I got my problem I can't solve.

    When you move the player through the levels, I want to spend the layers instead of him. If the player remains in a way where it is but the enemies, the Earth, elements... move around - as in most of these games.

    Gravitation is expected to affect every article/enemy (by ENTER_FRAME) and moves each object down until it touches the ground.

    The problem is, somehow objects of different layers do not get the right hitTest to information. So when two objects--the first on the same layer on the ground, moving both, all right. But as soon as I put the object in a container separated as 'itemsContainer:MovieClip' and I suggest that the subject is not getting the right result for hitTestPoints. (Maybe it has something to do with localToGlobal?)

    So, after a certain time when you move the ground and the itemLayer, it does not control its still on the ground and falls "down" - off the stage...

    I kept the code for you in a separate file of CS3. I hope that someone can see this problem and knows a response!

    Tobias-Reich.de/flashproblem.fla

    For those who do not want to download the code:

    ActionScript code:
    / * Press the keys for a while see what happens! */
    addEventListener() event. ( ENTER_FRAME, fall();
    Stadium. addEventListener () KeyboardEvent. ( KEY_DOWN, move();
    ( var ballLayer:MovieClip = new MovieClip()();
    addChild ()ballLayer ();
    ball is down-> falling down after a certain time
    var ball:MovieClip = new ball()();
    ball. x = 100;
    ball. y = 150;
    ballLayer. addChild (ball);
    ball on the same layer-> it works perfectly fine!
    var ball2:MovieClip = new Ball2()();
    ball2. x = 120;
    ball2. y = 150;
    ball2 addChild ()();
    var field:MovieClip = new Ground()();
    on the ground. x = 100;
    on the ground. y = 200;
    field of addChild ()();
    function ( ()eautumn: event():void { }
    if () ! on the ground. hitTestPoint () ball. x, ball. y, true)){
    ball. y +=5;
    }
    if () ! on the ground. hitTestPoint () ball2. x, ball2. y, true)){
    ball2. y +=5;
    }
    }
    ( function move()e: KeyboardEvent ():void { }
    on the ground. x +=5;
    ballLayer. x +=5;
    ball2. x +=5;
    }
    PS of course, I know I'm not supposed to code in the timeline, but I did it for you allows to easily see the point.

    I hope someone could help me with this. I'm quite desperate!

    Have a happy new year to you all!

    There is no rule that says that you cannot use the timeline... feel free to ignore someone who insists it is not.

    The problem arises because your ground is gradually moving to the right, its x property increases, but the ball (ball) is not (ballLayer is).  Thus, when the ground is moving beyond this property of the ball x - 100 (which is inside the ballLayer)...

    If (! ground.hitTestPoint (ball.x, ball.y, true)) {}

    becomes a real condition and the first ball falls.  Given that the other, ball2, is moved, its x property is changing as the terrain changes.  I don't know if what follows will give you the result you expected and after, but it is more in line with what you are doing...

    If (! ground.hitTestPoint (ballLayer.x, ball.y, true)) {}

    .

  • AS3 Collision detection will not work! : S

    Hello

    I'm working on a project and it is animate randomly a few points in the boxes. So I have a box movieclip that contains points (balls) and they run within the limits of the area. First of all, I created an animation of test mimicking one of the boxes and it worked fine but a fitting this code for my film, I start to have problems. Here is my code.

    What I am doing wrong? I'm particularly confused because it works in the test script! Sorry for the long code, I've included the two classes...

    I have solved the problem, it turns out that I was being ridiculous and affecting the circle cordinates x and y position of the movieclip container as opposed to 0,0... so I'm going to mark my post as the answer: D and thanks for those who may have take the time to watch this...

Maybe you are looking for