all groups > flash actionscript > april 2005 >
You're in the

flash actionscript

group:

Rotating a Mc



Re: Rotating a Mc David Stiller
4/2/2005 4:56:40 PM
flash actionscript: davidprovost,

[quoted text, click to view]

Okay.

[quoted text, click to view]

You haven't asked a question, so I don't really know what you're looknig
for, or where you're stuck.

Some basics a propos this topic are: the MovieClip class (look for the
_rotation, _x, and _y properties, and the onEnterFrame event handler), the
Key class, and the Math class for your sine and cosine trig functions.

Check out the documentation for these topics, then come back with a
question. ;) For starters, you'll want to change the _rotation, _x, and _y
properties over a series of frames (see onEnterFrame). Experiment a bit and
see how far you get.


David
stiller (at) quip (dot) net

Re: Rotating a Mc David Stiller
4/2/2005 5:19:10 PM
[quoted text, click to view]

That would take care of the rotation. Pretty simple stuff, too. :) Be
careful with the syntax, though. If you're attaching an onEnterFrame
handler to a movie clip, you'll likely want to call the movie clip by name,
so to speak. This is what instance names are for. So ... give that movie
clip an instance name and attach the onEnterFrame handler to *that* -- and
then, once inside the event handler, refer to the movie clip as "this",
since that's who the event handler pertains to.

myClipInstanceName.onEnterFrame = function() {
if (Key.isDown(Key.RIGHT)) {
this._rotation += 5;
}
if (Key.isDown(Key.LEFT)) {
this._rotation -= 5;
}
}

Forward and backward motion are a bit more complicated, since it all
depends on the movie clip's angle (_rotation). I'm not sure what "polar
coordinate" means, but the formula you'll want is ...

clip._x += distance * Math.cos(angle);
clip._y += distance * Math.sin(angle);

.... naturally, you'll want to swap out the words "distance" and "angle" with
numbers, or -- better -- with variables that represent numbers that may
change over time.


David
stiller (at) quip (dot) net

Re: Rotating a Mc David Stiller
4/2/2005 5:35:45 PM
davidprovost,

[quoted text, click to view]

Well, it still leaves me wondering how comfortable you are with
ActionScript. I don't know what you've tried so far, so it's hard to know
how many details to tell you. It would help if I knew a few things, like
are you familiar with the MovieClip class? Are you comfortable assigning
event handlers? Have you experimented with listeners? See where I'm going?

kglad has posted a complete example in another message in this thread.
That example uses setInterval() instead of onEnterFrame, which more or less
amounts to the same thing. You're changing certain movie clip parameters
over time ... and that time is measured either in frames or milliseconds.

Play around with kglad's example and see if that makes any sense to you.
Specific questions have a higher liklihood of finding meaningful answers
than broad questions. The goal you have in mind may not seem complicated,
but you have a number of steps to sort though.

I would recommend either A) going whole hog with kglad's example or B)
start from scratch and experiment with the MovieClip class. See if you can
get a movie clip to trace a simple message -- trace("Hi there!"); -- every
time the movie clip enters a frame. If you can do that, you'll know you're
on the way to meeting your goal. (Either that, or do the same with
setInterval().)


David
stiller (at) quip (dot) net

Re: Rotating a Mc Travis Newbury
4/2/2005 6:05:50 PM
[quoted text, click to view]

Why re-write code? Go to the flash site and download the Movieclip Tween
extension. It is pretty awesome and easy to use.

--
Rotating a Mc davidprovost
4/2/2005 9:49:46 PM
Say I had an mc and i wanted it to rotate whenever the left or right keys are
down, and I wanted the mc to move in the directiong of whatever the mc is
poointing whenever the up key is down, and the opposite way its pointing when
the down key is down.
Re: Rotating a Mc flashmaster52240
4/2/2005 10:02:15 PM
Is the rotation like this?

this.onEnterFrame = function(){

if(Key.isDown(Key.RIGHT))
thismovieclip._rotation += 5;

}

And so on.

To move along the direction the clip is pointing, you could do some polar
coordinate thing...too bad I forgot how that works.
Re: Rotating a Mc kglad
4/2/2005 10:11:58 PM
degtoRad = Math.PI/180;
speed = 5;
moveI = setInterval(moveF, 40, rocketMC);
function moveF(mc) {
if (Key.isDown(Key.LEFT)) {
mc._rotation -= 3;
}
if (Key.isDown(Key.RIGHT)) {
mc._rotation += 3;
}
if (Key.isDown(Key.UP)) {
mc._x += speed*Math.cos(degtoRad*mc._rotation);
mc._y += speed*Math.sin(degtoRad*mc._rotation);
}
if (Key.isDown(Key.DOWN)) {
mc._x -= speed*Math.cos(degtoRad*mc._rotation);
mc._y -= speed*Math.sin(degtoRad*mc._rotation);
}
}
Re: Rotating a Mc davidprovost
4/2/2005 10:12:51 PM
Im trying to make an mc rotate counter clock wise when the left key is down,
and for it to rotate clock wise when the right key is down, and i want the mc
to move in the direction its pointing (wherever it happens to be since it could
have been rotated with the left or right keys) whenever the up key is down.
Does that make any beter since?
AddThis Social Bookmark Button