3 Replies Latest reply on Jan 9, 2008 9:24 AM by Newsgroup_User

    Moving 2 objects in sync

    Level 7
      Seems like it should be simple, but it doesn't work out that way. I've got
      two objects that I'm using to give the appearance of water filling a scene.
      One is a standard Rectangle shape, the top of which rises at a set rate
      every frame. (This rate is a floating point, ranging from 0.0 to 1.0. Any
      higher and it moves much too fast.) The second sprite is a PNG, the exact
      color of the rectangle, 900x10 pixels, with the shape of waves. It's
      designed to have one more exactly wave than will fit on the screen, and it
      is set to rest perfectly on top of the rectangle, and slide to the left to
      simulate waves flowing. When it's moved the distance of one wave, it jumps
      back to the right. (This gives the illusion of seamless waves, as the jump
      is imperceptible to the eye.) Both sprites are using Copy ink at 50%,
      though the PNG has alpha (necessarily).

      Here's the tricky part. While at any given single frame, if you stop it,
      the two sprites appear perfectly lined up, and no line is visible between
      them, when they're moving, you can clearly see a line between them, like the
      movie can't redraw the shapes fast enough to keep them in sync. The lines
      of code that move the two sprites were placed as close to eachother as
      possible, to minimize the amount of calculation that happens between the two
      moves. The stage should not be updating until both have moved, but it seems
      that it just can't keep up. The relevant code is below: (I tried changing
      exitFrame to enterFrame, no noticeable difference. stepFrame doesn't work
      at all, since the playhead stays on one frame all the time.)

      property waterLevel, flowRate
      on exitFrame me
      if waterLevel < 615 then waterLevel = waterLevel + flowRate
      sprite(me.spriteNum).top = 615 - waterLevel
      sprite(me.spriteNum+1).loc = point(sprite(me.spriteNum+1).locH -
      1,sprite(me.spriteNum).top - 5.0)
      if sprite(me.spriteNum+1).locH <= 350 then sprite(me.spriteNum+1).locH =

      Now the problem only occurs when the sprites move vertically. If I keep the
      flowRate at 0.0, the horizontal sliding motion works perfectly. But evrey
      time the sprites move up (or down), there's a little glitch that shows up on
      the seam between them. Is there a better way to do this? Can you maybe
      force no stage redraw until both sprites have moved? Would that even make a

      The only other possiblity I can think of would be to make a *huge* PNG file
      with the shape of the waves on top, the height of the whole screen, and one
      wavelength wider than it. That way I'm moving only 1 sprite, but I imagine
      I'd pay for that in other ways. (The redraw-lag caused by moving a
      screen-sized image every frame probably wouldn't be very fun.)