A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: [disc / help] best way to do a scrolling background and centered hero...

Hybrid View

  1. #1
    ...dishing dimes on an .fla! pointguard's Avatar
    Join Date
    Dec 2001
    Location
    Cambridgeshire, England
    Posts
    1,017

    [disc / help] best way to do a scrolling background and centered hero...

    I've searched through various tutes on here, and other sites.
    I know how to make a background scroll, but wondered what your best / most efficient way of creating one is...?

    briefly, I'm using this
    code:

    bgd._y - vy;


    where vy velocity of the backround scroll...

    I know its not much harder than that really, but what's the best way to keep your hero centered as well, without lumping your hero and background in one 'world' clip?

  2. #2
    Style Through Simplicity alillm's Avatar
    Join Date
    Mar 2004
    Location
    Wales
    Posts
    1,988
    Well there are a few methods of scrolling:

    1) You can just do what your doing. Scroll the whole background in the opposit direction to the direction you want the character to appear to move in.

    2) You can use a gotoAndStop engine if your game is tile based, however this can be quite cpu intensive and perhaps a little tricky to set up

    3) Use bitmap data with flash 8. What I like to do is build one big bitmap out of a tile set bitmap, and then just display the part that the player is currently on. Of course you don’t have to use tiles, you can do the same thing with a pre made bitmap image. I think this is probably the fastest method although I could be wrong (I’ve never done any tests)

    I'm not sure what you mean about keeping the character centred... if you don't move the character then he is always going to be in the centre.

    Ali

  3. #3
    ...dishing dimes on an .fla! pointguard's Avatar
    Join Date
    Dec 2001
    Location
    Cambridgeshire, England
    Posts
    1,017
    Quote Originally Posted by alillm
    Well there are a few methods of scrolling:

    1) You can just do what your doing. Scroll the whole background in the opposit direction to the direction you want the character to appear to move in.

    I'm not sure what you mean about keeping the character centred... if you don't move the character then he is always going to be in the centre.

    Ali
    Think I'm gonna stick with the method I'm using...


    ...I was actually being stupid and trying to move both the character and the background at the same time, but realised I don't need too!

  4. #4
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    whats wrong with the world setup. It makes the most sense and is the easiest to use. When every thing shares the same coordinate space headaches are minimum
    lather yourself up with soap - soap arcade

  5. #5
    Truimagz.com everfornever's Avatar
    Join Date
    Sep 2006
    Location
    St. Louis
    Posts
    1,306
    yes, it does help when you start trying to do things like have enemies chase you, if your player is not inside the world, I bet your enemies are, and then your x/y is on a different plane than theres, among other problems soon to come.

  6. #6
    ...dishing dimes on an .fla! pointguard's Avatar
    Join Date
    Dec 2001
    Location
    Cambridgeshire, England
    Posts
    1,017
    Here's my basic engine so far...
    http://www.rocketchicken.flashwizard...ot engine.html

    basically at the moment I have my "world" Mc, with a "bgd" clip nested inside it, along with my "hero" clip.

    I had a previous version of this engine with just a huge great lonnnnnggg bgd tile / image. However I would like to be able to attach random tiles to the right of the bgd tile as the bgd scrolls along. Random tiles being so that the game isn't the same each time you play it.

    How do you add tiles to the right of your bgd, within your world MC, as the game scrolls along?

    I was reading up on tonypa's tutes but got confused half way through and am now stuck in a rut.

  7. #7
    ...dishing dimes on an .fla! pointguard's Avatar
    Join Date
    Dec 2001
    Location
    Cambridgeshire, England
    Posts
    1,017
    you will have to ignore the fact that if you fire at full power the background image will be lost on the way up and down....wait until the power is at least half way gone before firing...

  8. #8
    ...dishing dimes on an .fla! pointguard's Avatar
    Join Date
    Dec 2001
    Location
    Cambridgeshire, England
    Posts
    1,017
    *bump!

  9. #9
    ...dishing dimes on an .fla! pointguard's Avatar
    Join Date
    Dec 2001
    Location
    Cambridgeshire, England
    Posts
    1,017
    *bump!

    any help would be appreciated...
    cheers...
    Jeff

  10. #10
    Truimagz.com everfornever's Avatar
    Join Date
    Sep 2006
    Location
    St. Louis
    Posts
    1,306
    are you looking for a scrolling background engine with a centered hero>?

    http://www.truimagz.com/forum/viewtopic.php?t=18

    I posted this tut in a thread, but maybie you missed it, or maybie it didnt help, I dont know the ansewr to either, so Im offering.

  11. #11
    ...dishing dimes on an .fla! pointguard's Avatar
    Join Date
    Dec 2001
    Location
    Cambridgeshire, England
    Posts
    1,017
    Hi...

    not exactly...I've moved on from centering the hero, just didn't want to create a new thread for my question...I've got my engine working...
    http://www.rocketchicken.flashwizard...hotengine.html

    I just want to be able to add random MC's to the right hand side of the bgd as it scrolls along...
    I thought the way to do it was by using tiles, but I maybe wrong???

  12. #12
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    link didn't work. But...

    if your world simply moves on the x axis:

    var depth = world.getNextHighestDepth()
    var enemy = world.attachMovie("enemy", "enemy"+depth, depth)

    enemy._x = -world._x + Stage.width + enemyWidth / 2;
    enemy._y = Stage.height;
    lather yourself up with soap - soap arcade

  13. #13
    ...dishing dimes on an .fla! pointguard's Avatar
    Join Date
    Dec 2001
    Location
    Cambridgeshire, England
    Posts
    1,017
    the link works...just tried it again...

  14. #14
    ...dishing dimes on an .fla! pointguard's Avatar
    Join Date
    Dec 2001
    Location
    Cambridgeshire, England
    Posts
    1,017
    this is the code I'm using to attach my tile as the world moves off the stage...
    code:

    //check to see if background is off screen, if yes, add new tiles...
    //-----------
    if(world.bgd._x >= -686){
    world.bgd.attachMovie ("tile", "tile", world.bgd.getNextHighestDepth(),{_x:world._x + Stage.width, _y:Stage.height});
    }
    //-----------


    however, as you can see if you play the game, (please release the character at half power), the tile doesn't attach itself in the right sort of position. I know it's something to do with the registration point of the tile perhaps?...you can see the green tile is not being attached on the stage correctly.
    ...can anyone help?
    Last edited by pointguard; 02-19-2007 at 09:53 AM.

  15. #15
    ...dishing dimes on an .fla! pointguard's Avatar
    Join Date
    Dec 2001
    Location
    Cambridgeshire, England
    Posts
    1,017
    having a real trouble to get this thing sorted...
    code:

    //check to see if background is off screen, if yes, add new tiles...
    //-----------
    if(world.bgd._x >= -686){
    world.bgd.attachMovie ("tile3", "tile3", world.bgd.getNextHighestDepth(),{_x:world._width-1, _y:Stage.height});
    }
    //-----------



    please help or let me know where I'm going wrong...pulling my hair out trying to get it done...

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