Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm making a simple game. The character is movable with the arrow keys. The enemies are moving around the screen with a (classic) tween.

I want to detect collision between the character and the enemies. At first I thought it was working properly, but it also seems to detect a collision on the starting position from the enemies. So even if the enemies are already moving/tweening away from their start position, there's a collision detected between the character and these starting positions. (please ask questions if you don't quite get what I mean)

First method:

addEventListener(Event.ENTER_FRAME, checkIfHitTest);
function checkIfHitTest(Event)



This didn't work properly because it seems to detect the collition even if the enemy moved away from the starting point. (Probably because the ENTER_FRAME but correct me if i'm wrong)

My question to you: What's causing the detection and what is the best way to detect collision between a tweening movieclip and a movieclip wich is movable with the arrowkeys?

share|improve this question
The tweens are made on stage so not dynamicly in code and I'm programming on the timeline (actions) Thanks in advance! – Opoe Apr 25 '12 at 14:37
Hum I guess your tweens are inside one "enemy" movie-clip and this movie-clip is used to represent all enemies on your stage at different places, you do not tweens each enemy one by one, right ? – Valkea Apr 25 '12 at 18:03
@Valkea Yes you're right! I called it enemies, but it's just one movieclip. Sorry for the confusion :) – Opoe Apr 25 '12 at 18:12
up vote 2 down vote accepted

From what you describe, your problem is probably relative to the movie-clip you are targeting to test collisions with.

To be more precise, I think you are testing your collisions against the movie-clip containing the enemy animation and the enemy graphics. But indeed this movie-clip doesn't move at all... it's fixed and only its content is moving (well at least it seems to be fixed from what I can read).

To solve this problem, you need to test against the movie-clip you animate inside the movie-clip containing the animation. So give a name to this movie-clip (e.g. enemyShape) inside the animation move-clip and try to test collision using this one (take care to give the name on each key-frame of the tween animation).

Basically you will have to test against "enemyClipXXX.enemyShape" with XXX being any method you are using to name your enemies movie-clips.

share|improve this answer
Thank you for your clear explanation! Very helpful. – Opoe Apr 26 '12 at 9:23
thanks for your excellent answer Valkea, if you know this I will be amazed, I have been stuck for a while now... Same situation but applying the hitTest to a MovieClip inside a movieclip that is being dynamically added to stage through as3. I have tried your way and it works perfectly if I place the MC on the stage manually, but through AS3 it says enemyClipXXX.enemyShape undefined property "enemyShape" Help if you can, thanks very much – user16237 May 14 '12 at 11:21
@user16237 if you are sure you loaded through AS3 the same MC (with an "enemyShape" MC defined into it) you placed manually, then the only issue I can see with those informations is probably an incorrect path to find the "enemyShape" sub-MC. To test this, define a temp variable on each levels involved. Say var temp:int = 0; on first frame of the MC you try to load you enemy clips, 1 on the first frame of your "enemyClipXXX" and 2 on the first frame of the "enemyShape". Then before your hitTest trace the temp variable of the involved MCs... this way you could spot the problem and fix it. – Valkea May 14 '12 at 18:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.