So i got this bulletContainer class that shoots all these bullets it works & shoots perfectly fine when i put the class in a moveiclip to add to the stage. I can't have it in a movie clip because when i call the bulletClass's function it will shoot me an error saying it dosent exist. Now, my problem is when i addChild(bulletClass) onto the stage it will work exactly how its programmed to except for the movement/animation. The bullet moves fine, except when i shoot it shoot the opposite way, and not JUST shoots the opposite way it shoots a little to the left (if im pointing straight up a little to the left), then if i point completely right it will rotate to shoot right with me. So its basically bass-akwards In every way like I said and its only when i addChild() with a class(that extends Movieclip). I don't know why im giving you my code as it will just confuse you more that everything checks out; I think theres a conversion somewhere, like maybe classes that extends Movieclip are orientated differently then Library MovieClips?
This code is in the bulletAdder() function its the only place bullets are created in the bulletContainer
var localPlayer = Object(root).localSurvivor;
//Select what movieclip should go into the bullet
var newBullet;
newBullet = new bullet1;
//Create a local movieclip for this
var newBulletMC:MovieClip = new MovieClip;
newBulletMC.addChild(newBullet);
newBulletMC.x = setX;
newBulletMC.y = setY;
//trace(localPlayer.rotation);
//Create the newBullet class for movement
var localPlayerRotation = Object(root).localSurvivor.rotation;
trace(localPlayerRotation);
var newBulletClass:bulletClass = new bulletClass(localPlayerRotation, bulletLifetime);
//Add bulletMC to the bulletClass
newBulletClass.addChild(newBulletMC);
//Add to array
bulletArray.push(newBulletClass);
//Add to stage
localStage.addChild(newBulletClass);
This is the bulletClass, the bullets that move on screen
package com{
import flash.display.*
import flash.utils.*
public class bulletClass extends MovieClip{
public var lifetime = 0;
public var dir = 0;
var animationInt;
public function bulletClass(playerRotation, bLifetime:Number = 1){
dir = playerRotation
//Start life
animationInt = setInterval(animateBullet, 40);
}
private function animateBullet(){
this.x += 10 * Math.sin(dir * (Math.PI / 180));
this.y += 10 * Math.cos(dir * (Math.PI / 180));
}
}
}
Looks like you got it sorted, then?
One thing I will suggest - when you're doing stuff like this it doesn't always make sense to use the display list. If you have a lot of stuff happening on the stage it's going to slow down and performance is going to get sketchy fast.
If you're building a game, I strongly recommend at least checking out one or two of the big Flash Game Frameworks. They do a LOT of optimizations for you behind the scenes, and even much of the game logic gets abstracted out for you. Check out Flixel, for instance - super easy to get up and running quickly, and lots of tutorials out there.
Just my two cents, hope it helps!