View Full Version : keeping MC centered (scrolling)
danulf
October 14th, 2004, 12:33 PM
How do I do so a MC is centered all the time?
I want the bg to scroll (like a racing track or whatever),
but I have no idea how! If you have like a tute about this i would really appreaciate (is that how it's spelled?) it.
Hope you understand.
leoHEK
October 14th, 2004, 06:27 PM
dude it's easy don't put a moving script on the car but on the land put this.
onClipEvent (load) {
movespeed = 2;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_x-= movespeed;
}
if (Key.isDown(Key.LEFT)) {
_x+= movespeed;
}
if (Key.isDown(Key.UP)) {
_y+= movespeed;
}
if (Key.isDown(Key.DOWN)) {
_y-= movespeed;
}
}
danulf
October 15th, 2004, 04:00 AM
Yeah, I tried that, but then the car doesn't move like a real car.
I have a script so when you press left, the car rotates left and so on.
Thank you anyway man.
Dr Warm
October 15th, 2004, 04:07 AM
is it a topdown view? and u want the ground to spin with the car? and move forward in the direction?
then this might work having under onClipEvent(enterFrame){
this._rotation = car_mc._rotation;
and then the rest of it
danulf
October 15th, 2004, 04:49 PM
I tried it, but it doesn't work the way I want it to.
What I'm looking for is just a script to center the car MC,
so that if it turns left 90 degrees you go to the left (the map doesn't rotate, but the car do, making the map scroll depending on where the car is)...
Hope you understand.
Dr Warm
October 15th, 2004, 07:33 PM
ok i think i get it, but i would have thought the code from leohek would have done that, maybe u should post ur fla, and i'll see what i can do
Please post it in MX format if u can, i've only got like 7 days left of trial for MX 2004!
A7RSTR7K3
October 16th, 2004, 03:58 AM
So are you trying to say that you want the map to scroll depending on which way the car is facing? And the keys control which way it faces? I think I get it. You could use leohek's code, except on the key press, you also need to add in to set the cars rotation to whatever like this...
if (Key.isDown(Key.RIGHT)) {
_x-= movespeed;
_rotation = 90;
}
That should work I think thats what you want.
Note: Double check that your reference point is in the center of the mc.
Dr Warm
October 16th, 2004, 04:13 AM
(the map doesn't rotate, but the car do, making the map scroll depending on where the car is) i don't think he wants the map to rotate
danulf
October 16th, 2004, 06:42 AM
ok, here it is! btw, does anyone know a good ActionScript site?
Cause I wanna learn more about it, I'm just a n00b on that part right now :beam:
Dr Warm
October 16th, 2004, 06:54 AM
well the best way to learn is just to make stuff, like anything, that's what i found anyway, and then when u can't do something post it on here
look in the sticky about game resources for links to actionscript sites, but the main ones are
actionscript.org <-- lots of tutes, lots of downloads in movies
here
flashkit.com <-- tons of movies, tutes but the aren't so many good ones
danulf
October 16th, 2004, 07:55 AM
ok, thanks! I'm gonna check it out right now
Dr Warm
October 16th, 2004, 10:27 AM
hey that games pretty cool, but u were thinking about the scrolling wrong, u don't want the car to move, u want the ground to move! change the code to this:
onClipEvent (enterFrame) {
//This code will advance the car forward.
if (Key.isDown(Key.UP)) {
speed -= 1;
} else {
// This will make the car go backwards
if (Key.isDown(Key.DOWN)) {
speed += 1;
} else {
speed *= 1;
}
}
//The car will start to slow down after the speed of 25
if (Math.abs(speed)>25) {
speed *= .6;
}
// This will change the angle of the car
if (Key.isDown(Key.LEFT)) {
_rotation += speed;
}
if (Key.isDown(Key.RIGHT)) {
_rotation -= speed;
}
// This will make the car move
speed *= .9;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.move.hitTest(_x+x, _y+y, true)) {
_root.ground._x += x;
_root.ground._y += y;
} else {
speed *= -.3;
}
} i didn't change much, change some plus signs to minus, and put _root.ground._x and _y instead of just _x and _y. Much better!
danulf
October 16th, 2004, 10:32 AM
You're my hero! :beer:
Thank you man! You're the greatest problemsolver ever!
Dr Warm
October 16th, 2004, 09:28 PM
You're the greatest problemsolver ever! umm i don't think that i am, only by the fact that i get help of these forums too :D
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.