Skip to main content
Known Participant
July 22, 2010
Question

Platform Game Question

  • July 22, 2010
  • 1 reply
  • 448 views

Helllo,

I'm kind of new to as3 and programming, anyway, my problem is I have a hero character in a platform game and 3 enemies that shoot at him. When they shoot however, their bullets scroll with the movement of the hero character, when he moves they move with him. I want the enemies bullets to stay with the background that they are on and not scroll with the hero. If anyone has any idea how to help me that would be great. Here's the code that moves the enemies bullets:

//MOVE ENEMY BULLETS

public function moveEnemyBullet(k,timeDiff:uint) {

for(var i:int=enemyBullets.length-1;i>=0;i--) {

enemyBullets.x += bulletSpeed*timeDiff;

enemyBullets.y = gamelevel.y + gamelevel["enemy"+(k+1)].y-30;///-----I ADDED THIS TO TRY TO MAKE THE BULLETS STAY WITH THE ENEMY BUT IT DID NOT WORK

if ((enemyBullets.x < 0) || (enemyBullets.x > 550) || (enemyBullets.y < 0) || (enemyBullets.y > 400)) {

removeChild(enemyBullets);

delete enemyBullets;

enemyBullets.splice(i,1);

}

}

for(var j:int=enemyLeftBullets.length-1;j>=0;j--) {

enemyLeftBullets.x -= bulletSpeed*timeDiff;

enemyLeftBullets.y = gamelevel.y + gamelevel["enemy"+(k+1)].y-30;///------SAME HERE

if ((enemyLeftBullets.x < 0) || (enemyLeftBullets.x > 550) || (enemyLeftBullets.y < 0) || (enemyLeftBullets.y > 400)) {

removeChild(enemyLeftBullets);

delete enemyLeftBullets;

enemyLeftBullets.splice(j,1);

}

}

}

If you need to see more code let me know. Thanks

This topic has been closed for replies.

1 reply

funkysoul
Inspiring
July 22, 2010

where's your enterframe attached, does it only run when the "hero" is moved?

As well when does the moveEnemyBullet get called? and more importantly how many times. in the code you posted you only show the function.

Known Participant
July 23, 2010

thanks but I think it's too complicated for me. I'm going to wait till I learn more I think. But thanks