-
Movement
Hey guys, i'm new to flash 8, and i'm working on remaking a flash game called "Penguin Chat" for my website. I've got most of it done, but i need to make the character walk to the mouse click. I have an animation for walking in every angle, but i don't know how to play it and make the character move toward the mouse click. Also, i need to make the character rotate "tracking" the mouse position. And, i have a room with music that plays but i want it to stop when you leave the room. How do i do these things?
Thanks!
-
To face mouse:-
Code:
xdiff = mouseX-penguin.x;
ydiff = mouseY-penguin.y;
penguin.rotation = Math.atan2(ydiff, xdiff)/(Math.PI/180) + 90;
To move towards mouse:
Code:
//On click event
function mclick(e:MouseEvent)
{
destX = mouseX;
destY = mouseY;
}
//Enterframe or any update event
function eframe(e:Event)
{
var dx:Number = this.x - destX;
var dy:Number = this.y - destY;
var dist:Number = dx*dx+dy*dy; //distance to destination
if(Math.abs(dist)>speed)
{
this.x += moveSpeed * Math.cos(this.rotation * (Math.PI/180));
this.y += moveSpeed * Math.sin(this.rotation * (Math.PI/180));
}
}
-
good, but how do i make the character change sprites? When i click i want him to do a walking animation to the click point.
Thanks
-
Quote:
I've got most of it done
really? how much have you "actually" done till now?
if the walking animation is on frame 2, on the timeline place, gotoAndStop(2)
-
about 70%. Also, i get this error when i put in the walking code:
Code:
**Error** Scene=Scene 1, layer=Layer 1, frame=109:Line 2: Statement must appear within on/onClipEvent handler
function mclick(e:MouseEvent)
**Error** Scene=Scene 1, layer=Layer 1, frame=109:Line 9: Statement must appear within on/onClipEvent handler
function eframe(e:Event)
Total ActionScript Errors: 2 Reported Errors: 2
two more question (sorry) how do i start music in one room, and turn it off when you leave?
And: when the penguin contacts a wall how can i get him to either stop or go to another room?
-
Quote:
Originally Posted by
123kirby
about 70%
So if making the character turn, making the character walk to the mouse, checking if character hit a wall, and playing/stopping music is 30%, I wonder, what's the other 70%?