A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: [Flash cs4]z position and resizing

  1. #1
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766

    [Flash cs4]z position and resizing

    Basically I am trying to create a parallax effect using the vcam. To do this I have to set the z position of the objects and then rescale them back to their original size. Is there any way to resize the object back, perfectly? Also, are there any better alternatives than this approach?
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  2. #2
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Just run a separate layer for the parallax, using the z buffer is overkill and will cause a cpu hit where Flash has to scale the data.

    With parallax you can usually get away with having wide bitmaps, so just have a couple of those looping, nice and quick and simple.

    Squize.

  3. #3
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    hmm, ok, I guess I will have to do this the manual way! But using z seemed really easy and gave the perfect effect I wanted....sigh
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  4. #4
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    I don't understand, if using the z method was perfect for you, then why look for alternatives ?
    I've not really played with the native 3D methods in Flash, but if you do want to restore it to it's original size then surely,

    sprite.z=0;

    would do it ?

    How I normally do it is if the screen scrolls left and right have 3 bitmaps in the parallax layer, and center the container, eg
    If our bitmaps are named 1,2,3 then 2 would be visible in the middle of the screen, 1 off to the left, 3 to the right.
    Then when you scroll right for example, when bitmap 3 has reached the middle point ( ie global x pos =0, it's fully on screen ) then flip the position back so bitmap 2 is in the center and so on.
    If you're just scrolling in one direction you can just use 2 bitmaps.

    If you're using z to scale it for you, aren't you going to be running full size images, just scaled down for you to create the sense of depth ? That's got to be a waste, both in terms of detail and actually rendering time.
    If you use bitmaps just made for that specific layer then you can fade them away / add a depth of field blur etc. all in your art package and just drop it into the game at not extra cost.

    Squize.

  5. #5
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    you might have to do this yourself to understand what I meant. basically just setting the z doesn't create the parallax effect perfectly, to create the parallax effect, I will need to scale it back manually, so in term of pixels, it is actually bigger than the original.

    So if I have a 100x100 mc, and I set it's z to say 100, then it's pixel width stays 100... but in 3d view it is 84x84, so I manually need to scale it back to 100x100 visually.....but scaling visually isn't really pixel perfect, is it?
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  6. #6
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Ah I see, you're using the z purely in terms of "speed", rather than scale, so your scale is getting messed up where you're moving it further away from the camera.

    Honestly mate, just use bitmaps and forget about z.

    Squize.

  7. #7
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    well, if I use normal method, I still need help calculating the speed properly based on player position. last time I tried giving them constant speeds, that is, when player moved, I did
    layer1.x+= (player.prevX - player.x);
    layer2.x+= (player.prevX - player.x)/2;
    layer3.x+= (player.prevX - player.x)/4;

    but although this caused the parallax effect, the screen movement wasn't pixel perfect. The slide positions would change a bit when you come back to them.....this is really frustrating.


    Take a look at what I have so far:
    http://megaswf.com/view/70fd1b21df95...eb826426b.html

    move with arrow keys. When you start, notice the position of the pavement below the first tree, and the vine. After you have walked a bit, stop, and you will see the view scrolls a bit ahead of you(This is one of the effect I must have, and is also one of the biggest source of problems), then turn back and return to the starting point, and you will see the slides have shifted slightly.


    I have tried almost everything I could think of, if it's possible, can any of you make me a example of the desired effect?
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  8. #8
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Here's a game I did years ago ( 2004 according to the credits, where has the time gone ? )

    http://www.wedonicethings.com/heartattack/index.html

    Rather than calculate the distance moved on the fly like you're doing, I have a speed var, which is the main playFields scrolling speed.

    From that it's just a case of,

    layer1.x+=speed*0.5 //quicker divide by 2
    layer2.x+=speed/4;

    And so on, which isn't a million miles away from how you're doing it.

    You are losing pixels on the foreground scroll somewhere, maybe try rounding up the numbers you're adding to the layers.x so you're not hit with internal rounding errors ?
    To be honest though, I'd say it doesn't really matter. No one is going to ever notice it. Some bugs can be left to live a long life and not do any real harm.

    Squize.

  9. #9
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    well I can't really use speed, cause the player won't always be moving on his own, but can be blown back with blast, or teleported, e.t.c. And I really don't like leaving bugs from the very first stage of development......there must be a better way. Also your game uses continuous scrolling, no limits to the world, I have to use limits.
    Last edited by bluemagica; 06-08-2010 at 08:18 AM.
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

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