-
Scrolling trerrain RPG
How is it possible to make scrolling terrain that will always keep the player MC in the center, meaning if the player accelerates, it will always show him in the center:
if the document size is 500x400 and the player's 40x40
if the player is at _x 700, the player mc will still be in the center.
Look at this:
http://www.newgrounds.com/portal/view/408666
-player is always in the center
-along with the user interface
-the player moves because if not the enemy mc will always be next to it
what ive tried and did not work:
-vcam, only focused on the player, when I place everything in 1 large MC, the player did not move well and the cam did not follow.
-making the _root._x equal to the players, but then i turned, everything turns and if i have a custom registration, it messes it all up
Thanks for reading!
Edit: As2
Last edited by katyperry; 03-09-2009 at 05:38 PM.
-
Professional Air Guitarist
Set _root._x/_y to the additive inverse of the player's coordinates and then subtract half of the stage width/height.
_root._x = -player_x-Stage.width/2;
_root._y = -player_y-Stage.height/2;
Haven't used AS2 in a while so the Stage.width might be the incorrect syntax but you get the idea.
-
It didn't work :<
I think the Stage.width was for the stage, because I did a trace and it gave me the x of the document.
-
Funkalicious
Then just fill in the numbers manually, your stages width and height aren't dynamic.
-
Here is a simple movement (no friction) function with stage focus I use for such games. This will get rid of that jump to the left or right when you first punch down a movement key.
PHP Code:
function movement(player:MovieClip,speed:Number,stagX:Number,stagY:Number):Void { _x = -player._x+stagX/2-mov; _y = -player._y+stagY/2; player._x += mov; if(Key.isDown(68)){ mov = speed;} else if(Key.isDown(65)){ mov = -speed;} else{ mov = 0;} }
onEnterFrame = function() { movement(MC,NUMBER,StageWidth,StageHeight); //err u understand how to run functions... }
You could also add in a key parameter.
Last edited by DeadRiver; 03-10-2009 at 08:00 AM.
-
no luck mate:
code in frame 1
Code:
function movement(player:MovieClip,speed:Number,stagX:Number,stagY:Number):Void
{
_x = -player._x+stagX/2-mov;
_y = -player._y+stagY/2;
player._x += mov;
if(Key.isDown(68)){
mov = speed;}
else if(Key.isDown(65)){
mov = -speed;}
else{
mov = 0;}
}
code in frame 2
Code:
stop();
onEnterFrame = function()
{
movement(player,14,550,400); //err u understand how to run functions...
}
no movement on the movieclip with instance name of player, then i also tried linkage name of player
-
Senior Member
place the player mc in the center of the stage. Make a long terrain mc and put on stage( dosent matter if its longer than stage), just make sure terrain mc's registration point is on its left edge, then,
Code:
if(left is pressed)
{
if((terrainmc._x+4)>=0)
terrainmc._x=0;
else
terrainmc._x+=4;
}
That is pseudo code, don't copy paste it!
When left is pressed, the player dosent move, but the terrain moves towards right, so we are making sure the left edge can move right( >=0 means left side is in stage, else it is outside view) and move it......this is the effect you want.... use similar logic to handle right movement!
-
code in frame 2?
If the function isn't with the function call you probably have to do _root.movement();
Also make sure you use "A" and "D" to move (it can be changed though ofc).
-
Funkalicious
Originally Posted by DeadRiver
If the function isn't with the function call you probably have to do _root.movement();
The function is defined as _root.movement and the call is from _root, so you wouldn't have to.
-
Oh your right. Just tried. Why isn't it working for him then? That code works perfectly. I use it all the time....
EDIT:He probably tried to move with the arrows lol =P.
-
Funkalicious
Nah, the code is just a little worn and torn from all your usage I can't see anything wrong with the code.
btw, is that a division by two and not a multiplication by a half? Shame, shame.
-
meh, I always divide by two, it's a curse =(.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|