Skip to main content
Participant
May 8, 2008
Question

Moving images smothly across the stage

  • May 8, 2008
  • 4 replies
  • 571 views
I am trying to write a script that animates images, moving them smoothly and slowly across the stage. If I load the image in authoring time and embed it on a movie clip, i have no problem incrementing the x position by 0.25 for example. But if a load the image at runtime using a loader the image jumps from pixel to pixel. For some reason it seems that I am not able to turn the pixelSnapping off.

Code is bellow.

Any ideas??????

thanks
This topic has been closed for replies.

4 replies

julio_g1Author
Participant
October 23, 2008
Thanks a lot Rolle, I actually solved the problem scaling the images by 100.1% , I am going to try your solution but I still think this is related to a bug on the player because it is very strange. Any way I got the new Flash CS4 this morning :-D so it will be interesting to see how it works now.
Inspiring
October 23, 2008
Interesting thread..

I'd agree with kglad, that objects will move one by one pixels and not by 0.25, and every time I had such problem I was tweaking the FPS + speed of objects.

But this gives another perspective.. By just scaling with 1.001 the renderer does smoother animation with interpolation...

Because I don't prefer to use directly bitmaps from loaders (because it may cause problems on unloading data later for clearing memory + increased complexity on code) I just appose my example, based on julio_g notice of scaling.

Notice that I don't use: Bitmap(ldr.content).pixelSnapping = PixelSnapping.NEVER;, because by default it's AUTO and is activated with that scale (documentation). Only the Bitmap(ldr.content).smoothing = true; and the scaleX to 1.001 are enough for the effect. cacheAsBitmap is by default 'false' thus is not need to added.

Comparing to Documentation of pixelSnapping, PixelSnapping.NEVER should work with scale=1 (100%). Instead the behaviour is like PixelSnapping.AUTO. Thus I guess too, the pixelSnapping class has somekind of bug...
Participant
October 22, 2008
Hi julio_g

I found your post looking for the solution for this problem.
I couldn't find any solutions on the net, so I have been working on it for a few hours and I fixed the problem

I hope you enjoy it!

Cheers /Rolle
julio_g1Author
Participant
May 8, 2008
If PixelSnapping is turned off the flash graphic engine is able to interpolate the pixels and allows for a slower smoother movement.
For example if you scale the container sprite (in this case testImg) outside the AUTO range from a factor of 99.9% to 100.1%, you will see how the image moves slowly AND smoothly with the increments of less than a pixel. Your solution would work, but unfortunatly I have to use in this application a frame based animation for all the elements and movements.
kglad
Community Expert
Community Expert
May 8, 2008
testImg is only going to move when its x property increments by, at least, one. so testImg will move every 4th loop.

so, using smaller increments is not a way to increase movement smoothness. increasing your loop frequency (and updating the stage) will increase smoothness. ie, use a timer loop and event.updateAfterEvent()