Hi all ^^
I’m doing a simple game where you move the character using the arrow keys and shoot using the Mouse. The character rotates based on the Mouse angle.
I have two problems: when I move the character, he moves once, then stops then moves again as normal.
My other problem is that when I click over a MovieClip, the bullet goes to the wrong angle.
My moving function:
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
function keyHandler(event:KeyboardEvent):void {
            if (event.keyCode == 37) {
                jog.x=jog.x-pla.speed;
            }
            if (event.keyCode == 39) {
                jog.x=jog.x+pla.speed;
            }
            if (event.keyCode == 38) {
                jog.y=jog.y-pla.speed;
            }
            if (event.keyCode == 40) {
                jog.y=jog.y+pla.speed
            }
}
jog is the Instance Name of my movieclip. I have a class were the speed is inside. It’s instance is pla.
I have a class that makes my bullet move, and a function on my main timeline to put the bullet on the stage.
The function:
stage.addEventListener(MouseEvent.MOUSE_DOWN, atira);
function atira(event:MouseEvent):void {
    var newBullet:Bullet = new Bullet();
    newBullet.x=jog.x;
    newBullet.y=jog.y;
    addChild(newBullet);
    newBullet.trata_Tiro(event);
}
And here is my code to make it move and get the angle:
public function Bullet() {
            addEventListener(Event.ADDED, beginClass);
            
            addEventListener(Event.ENTER_FRAME, eFrame);
        }
        private function beginClass(event:Event):void {
            _root = MovieClip(root);
        }
        private function eFrame(event:Event):void {
                        
            y += speed*Math.sin(_angle)*speed;
            x += speed*Math.cos(_angle)*speed;
                    
        }
        
        public function trata_Tiro(event:Event) {
            _angle = Math.atan2(mouseY-event.target.y, mouseX-event.target.x);
        }
    }
Thanks for all the help =)