You must have added playerDartContainer to the player sprite during your setup, or to another display list container that also holds the player sprite, thus you're moving them both. In that case, the playerDartContainer will always have it's local coordinates as (0,0) as you mentioned -- in terms of it's direct parent, it is not actually moving.
Follow up If you place your player in the middle of the screen, and you place your dart container in the middle of the screen and don't move it, that's where the container's going to stay -- thus the darts will look relative to the player, because their container always stays in the same screen pos as the player. You have to move your background and your darts container, relative to the player. The player's the only thing that should never move (i.e. remain centred). In fact, you have this:
- document/application class (eg. "YourGameName" or "Main")
-
- background sprite (presumably moves relative to player)
-
- player sprite (stays in middle of screen)
-
- dartContainer sprite (yours stays in middle of screen with player, but should move relative to player)
-
-
- dart 1 (moves relative to container -- which is in same place as player!)
-
-
-
- dart 2 (moves relative to container -- which is in same place as player!)
-
-
-
- etc.
-
I would just have this:
- document/application class (eg. "YourGameName" or "Main")
-
- background sprite (moves relative to player)
-
- player sprite (mid screen)
-
- dart 1 (moves relative to player)
-
- dart 2 (moves relative to player)
-
- etc.
That's your choice though. As long as you make sure the container moves in the same way your background does (if you have a scrolling background?), it will work.
public function movePlayerDarts():void {
//shift the container screen pos relative to the player, since they have
//different world positions and screen pos is a derived from world pos.
playerDartContainer.x = (stage.stageWidth / 2) - player.x;
playerDartContainer.y = (stage.stageHeight / 2) - player.y;
for (var pdIns:int = 0; pdIns < playerDartContainer.numChildren; pdIns++) {
// Set the Player Dart 'instance' variable to equal the current PlayerDart
playerDartIns = PlayerDart(playerDartContainer.getChildAt(pdIns));
// Move the current dart in the direction it was shot. The dart's 'x-scale'
// factor is multiplied by its speed (5) to move the dart in its correct
// direction. If the 'x-scale' factor is -1, the dart is pointing left (as
// seen in the 'createDart()' function. (-1 * 5 = -5), so the dart will go
// to left at a rate of 5. The opposite is true for the right-ward facing
// darts
playerDartIns.x += playerDartIns.scaleX * 1;
// Make gravity work on the dart
playerDartIns.y += 0.7;
//playerDartIns.y += 1;
// What if the dart hits the ground?
if (HitTest.intersects(playerDartIns, floor, this)) {
playerDartContainer.removeChild(playerDartIns);
}
//trace("Dart x: " + playerDartIns.x);
trace("Dart y: " + playerDartIns.y);
}
}