A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Container system for "falling" game

  1. #1
    Senior Member Draxus's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    123

    Container system for "falling" game

    I'm making a game in which you're falling down a tunnel/hole with various enemies, platforms, etc on the way. I'm somewhat new to flash with only a few games under my belt (and only one actually 100% complete) and I'm comfortable with code, but sometimes don't know the best approach to doing something... so I'm not sure how I should go about doing this.

    Right now I have the player in a static y position and I'm scrolling an array of containers populated with platforms to simulate the player falling. When the bottom container gets is almost totally on the screen the top one is deleted and a new one is spawned at the bottom and populated with stuff. I'm doing it like this because I want the player to be able to/be forced to travel upwards at times. Is there a better way to go about doing this? I don't really like the player always being at the same real y location... it looks crappy in my opinion...but if I allow the player to travel around the screen and scroll the background up or down when he gets to the top and the bottom you can't see what you're coming towards while you're falling. Any thoughts on how you'd approach this? Thanks in advance.

  2. #2
    Senior Member
    Join Date
    Dec 2005
    Posts
    426
    Thats pretty much the way i would do it. you just need to tweak it and make sure that it only moves up then the player moves down etc.

  3. #3
    Senior Member
    Join Date
    Feb 2003
    Posts
    146
    Perhaps you could move the game world (the rising platforms and objects) and the player back to a central location during a fall. In other words, whenever the player is in a free fall, adjust the world and him so that he centers back on the stage. You'll have to put all of your objects into an empty MC, possibly including the player. Then you spawn the objects inside the MC at their usual coordinates, and use the empty MC's _x and _y to follow the character and center him when he falls.

    To put the code into words:

    (assume that player._x is the player's _x coordinate on the stage, not inside the world movieclip. to achieve this you will have to subtract _root.world._x from _root.world.player._x. assuming, of course, that the player MC is inside the world MC... which would be the easiest way)

    If player is falling then
    if player._x > Stage.width/2 (to the right of center stage)
    _root.world._x--;
    else if player._x < Stage.width/2 (to the left of center stage)
    _root.world._x++;


    same goes for _y. you'll need to use a nested if statement. you will also have to make sure you are very precise, or else you might end up with a "shaky" result. if you want it to be really smooth, you could use the distance formula for the center of the world MC to the center of the stage. Then, if that distance is <1 (or any number) then you simply ignore the adjustment code.

    Am I thinking too hard about it?

  4. #4
    Wait- what now? tidenburg's Avatar
    Join Date
    Dec 2005
    Posts
    1,471
    On the line where you make your player fall:
    player._y += player.ymovevariable
    swap it with:
    worldcontainer._y -= player.ymovevariable

    this is assuming all your platforms are inside a container movieclip, if not then add this to each individual tile.
    "I'd only told them the truth. Was that so selfish? Our integrity sells for so little, but it is all we really have. It is the very last inch of us, but within that inch, we are free."

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