A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Rotating background RPG--tough one!

  1. #1
    Member
    Join Date
    Jan 2002
    Posts
    85
    Okay, here's what I'm trying to do: I want a large terrain mc that and rotates and scrolls down in order to give the impression that the character is moving (the camera looks down on the main character from above). However, with a moving and simultaneously rotating background (capable of a full 360) I need the background mc to rotate from an ever-shifting axis or registration point. How can Actionscript calculate and move the background (terrain) mc's registration point so that the terrain is always rotating around the character and not from a central or fixed axis.

    Any help would be greatly appreciated--I'm completely stumped. Thanks.

  2. #2
    Senior Member
    Join Date
    Jul 2000
    Posts
    323
    One quick idea...

    Instead of putting all of your terrain MCs on the main timeline, put them all inside a "Background" MC... Then just rotate and move the background MC...

  3. #3
    Member
    Join Date
    Jan 2002
    Posts
    85
    thats sort of what I have now, but I probably should have said that the main character is completely stationary and locked the the midde of the screen with everything else around him moving. So as the background shifts down say ten pixels (moveSpeed variable) the registration point (axis of rotation) must change by the same 10 pixels. Does that make any sense?

  4. #4
    Senior Member
    Join Date
    Jul 2000
    Posts
    323
    Ah, ok... I see what you mean...

    Well, I don't know how this'll affect speed... But try this...

    Put the entire background inside ANOTHER MC, let's call it "Scene" for example... Call it whatever you want... When the character moves, move Background (Inside Scene)... When the character turns, turn Scene, cause Scene will always be centered on the character.

  5. #5
    Member
    Join Date
    Jan 2002
    Posts
    85
    an inspirational idea to be sure. I'm off to Flashland to give it a go. Thanks for the help, Xentor, i'll try to let you know how things go.

    dreckleburg

  6. #6
    Member
    Join Date
    Jan 2002
    Posts
    85
    an unforseen difficulty has arisen. As i anticipated when you presented the idea, the rotation now works perfectly...thanks; however, now the virtical scrolling is messed up because the new mc that is rotating has its own independent X and Y coordinates with means that when I make my character walk forward and the background terrain has been rotated say 90 degrees the background now scrolls according to that 90 degree rotation, and it looks like my guy is walking sideways.

    I guess the question is: Is there some way to keep the background scrolling according to the main movie Y axis and still exist within another mc. The problem still remains difficult though one problem has been solved. Thanks for the help.

  7. #7
    Senior Member
    Join Date
    Jul 2000
    Posts
    323
    Ohhhh, ok, I see the problem... Tricky... You're going to have to calculate the angle at which it's rotated, and the equations to move the background will be something like y + sin(angle), x - cos(angle)...

  8. #8
    Member
    Join Date
    Jan 2002
    Posts
    85
    I just got in over my head. Do I need to transfer to Newbie land or is there a physics major handy. I'll start looking through tutorials to find something, but if you (or anyone else) has something specific (like a tutorial, fla., or something that he/she used in their own script) to point me in the right direction I'd be greatful. Again thanks.

  9. #9
    Senior Member
    Join Date
    Jul 2000
    Posts
    323
    Problem solved

    I coded and tested this... Works perfectly...
    It's set up with a movie clip called "bg"... Inside that is another MC called "terrain", and inside that is the background image/MCs/whatever...

    ---

    //"angle" specified in degrees, + = clockwise, - = counter-cw
    function turn(angle) {
    curAngle += angle;
    bg._rotation = curAngle;
    }

    //dist is in pixels
    function walk(dist) {
    bg.terrain._x -= Math.cos((curAngle+90) * (Math.PI/180)) * dist;
    bg.terrain._y += Math.sin((curAngle+90) * (Math.PI/180)) * dist;
    }


    ---

    Had to add 90 to the angle, because in trig, the zero-angle is to the right, not up... Math.PI/180 just converts it to radians...

    Give it a shot...

  10. #10
    Gross Pecululatarian Ed Mack's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    2,954
    Are you sure about zero angle? Anyway, correct it easily like this:

    _x += Math.sin(a*(Math.PI/180))*s;
    _y += Math.cos(a*(Math.PI/180))*s*-1;

    I think this is caused by real life using a "y" axis that numbers upwards.
    [Edited by Ed Mack on 04-28-2002 at 05:31 PM]

  11. #11
    Senior Member
    Join Date
    Jul 2000
    Posts
    323
    Yep... In flash, rotated 0 degrees = vertical... With the basic math functions (Remember highschool trig?), the zero-angle is to the right...

    Trust me, I coded and tested that before I posted it

    Trig and geometry... So useful... Great for ballistics...

  12. #12
    Member
    Join Date
    Jan 2002
    Posts
    85
    I'll get right on it. This is new territory for me, but I see the general concept. I'll let you know. Thanks for the time and work that you've put into this.

    dreckleburg

  13. #13
    Member
    Join Date
    Jan 2002
    Posts
    85
    Thanks, Xentor and Ed Mack. It works perfectly. When I finish the game I'll remember to let you know so that you can see the engine you helped me build at work. All the effort is greatly appreciated. Until next time.

    Thanks,

    dreckleburg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center