Random choppy tweens - actionscript-3

I'm programming a basic game in AS3 and Deploying it through Air. There's a maximum of 7 sprites tweening at one time.
When testing the game the tweens run smoothly 90% of the time, however the other 10% of the time I get choppy tweens where it appears to be dropping frames. I would have thought if it was something in the code chewing up resources that this issue would happen 100% of the time.
Is this a known issue? Any ideas on what could be causing this?

Related

Box2D world.step() delay at first 2 runs

I'm programming a game using ActionScript 3.0 and included Box2D classes for its physics. It's a maze/labyrinth game having a lot of walls and a ball inside.
In my main fla when I call the maze.create(), the maze is created (visually and physically) and it will dispatch an event so I know when it's done working and then I call my frameHandler which calls another function from my maze class every frame and the big delay accrues exactly at world.step() in it. BUT THE THING IS that it lags only the first two times this function runs!!!
The reason I notice this lag, is that I've got another object starting to move according to mouse position in the same frame handler.
The reason I'm sure the world.step() is causing it, is that everything works fine when I dont call it.
I've seen many codes using Box2d, some had more objects than i have and I know that I've created my b2World and all the objects correctly, similar to all the Box2d tutorials and stuff BUT THEY DONT LAG AT ALL. Its just mine lagging and all!!
Do you have any Idea or similar experience?
Do you have any suggestion in general how to deal with heavy functions?
PLEEEEASE +.-
A maze will have a lot of fixtures in close proximity making a very dense dynamic tree (the method Box2D uses to optimize collision checks). There is unlikely to be any way around this. Perhaps you could just call Step a few times after adding the static walls, but before you add the dynamic ball bodies, and consider it part of the loading process. At least the lagging movements will not be visible to the player.

Flash / Adobe 3.4 air fullscreen performance dip issue

I'm creating an HD(1280x800) adobe air 3.4 app for desktop and in the background I'm doing a simple timeline animation that has circles emanating outward. These circles are pngs and I've tried both rendering as bitmap and not, and I tried as flash drawings with a blur on them. The problem I'm running into is that in fullscreen mode, the performance dips significantly. In window mode things run pretty smooth. I've tested this with the animation alone and it always happens. The stage size is the same as monitor res, and I've made sure that the stage isn't scaled, but still the performance problem persists. In the publish settings I have the acceleration set to GPU.
I was under the impression that flash can do all kinds of crazy 3D, so I'm just not understanding why this stupid simple timeline animation is causing so much grief. Can anyone fill me in on some info? Have a solution for the fullscreen performance problem? I have not been able to find a good answer or solution in all my searching.
UPDATE: looks like fullscreeninteractive, and not just full screen is the way to go.
dont use blur on animations. never. ever. that is the reason, people believe Flash is slow. Its not. But the banners are badly constructed, and use tons of filter. Go ahead, and implement blur filter in photoshop to a 3MP image. There will be a progressbar. It will take 1 sec. Blur is slow! If you want blur on your animation, record it, and store as a gif or fla. If you want working blur runtime, implement stage3D, and create an AGAL program that will render it on GPU.

Flash actionscript 3 smoothly moving large sprites

I've got a problem in actionscript3 with moving large DisplayObject-s. When the size of the DisplayObject is quite large (more than screen size) the movement loses smoothness and it looks like the object starts jumping forward and backward, which overall looks very unpleasant.
Does anybody know the way to fix that? I am trying to make a sort of a race game, where I need to move the background sprite to make the illusion of movement.
Try turning on cacheAsBitmap. That may give you some performance improvements, especially if the object is static (doesn't have any animated bits in it). With AS3 and Flash Player 10 or newer you should be able to get smooth movement even with a large sprite. I've got several games that do it.
Have to agree with Laurent - it is probably better to split the background into small pieces and move them

Let system time determine animation speed, not program FPS

I'm writing a card game in ActionScript 3. Each card is represented by an instance of a class extending movieclip exported from Flash CS4 that contains the card graphics and a flip animation. When I want to flip a card I call gotoAndPlay on this movieclip.
When the frame rate slows down all animations take longer to finish. It seems Flash will by default animate movieclips in a way that makes sure all frames in the clip will be drawn. Therefor, when the program frame rate goes below the frame rate of the clip, the animation will be played at a slower pace.
I would like to have an animation always play at the same speed and as a consequence always be shown on the screen for the same amount of time. If the frame rate is too slow to show all frames, frames are dropped. Is is possible to tell Flash to animate in this way? If not, what is the easiest way to program this behavior myself?
The easiest way would be to use a Timer (or a setInterval) triggering every 1000/fps milliseconds, telling your MovieClip to go to its next frame.
If you need something more accurate, you'll have to check the time spent since the last update (stolen from the first comment of this article from Keith Peters' blog, which explains everything pretty well).
It's been a while since I used Flash but from what I understand it's not possible because Flash uses a frame based animation model.
Silverlight however uses a time based animation model and will just draw as many intermediate frames as the frame-rate allows.
The tween class (fl.transitions.Tween) is perfect for this situation. By setting the last argument of the constructor to TRUE then it bases its animations/triggers off of seconds, and as far as I know it compensates for FPS loss/gain.
You can easily use it like the Timer class by passing a new object (Trigger(new Object(), "x") to the constructor and creating a listener for MOTION_FINISH (TweenEvent.MOTION_FINISH) to trigger your event!
I use Tweens for a LOT of things because they're easy, fast, and supported by everything. And like I said, it should solve your FPS/lag issues since it adjusts to FPS changes in real-time (as far as I know!).

ActionScript 3: Smooth programmatic animation

I want to animate MoviveClips/Sprite objects as smootly as possible. However so far the only method that works is placing the movement code into the EnterFrame event handler. There is one problem with this approach: when the framerate on a specific machine is below the desired framerate then the whole game slows down. I want to be able to do this in a time-independent manner.
There are two ways to do programmatic animation within the Flash player. The first you already pointed out by using a onEnterFrame. However, as you might already have noticed, to get a smooth animation you need to increase the overall frame rate of your movie. Doing this will also increase the CPU load for the entire period of time your SWF runs. This is not something you always want.
The other way of doing programmatic animation is by using a timer. Within a timer handler it is possible to call a function named updateAfterEvent which will update the screen independent from the FPS you'd set for your SWF. Therefore, using a timer leaves a gateway to do smooth animation within the Flash player without increasing the overall frame rate of your SWF.
Two years ago or so I set out to create my own tween libraries for Flash (because of my frustrations with the then existing tween libraries available). I released it under the name Coretween and this library lets you, among other things, choose what type of animation you prefer for every individual tween. On the documentation page I give an example of the difference between frame based and time based animation. The example SWF on that page runs at 12 fps but as you can see, the lower circle tweens much smoother because it's controlled by a timer that ticks at 60 fps and updates the screen in-depended from the SWF frame rate. Do keep in mind though that even the timer ticks at 60 fps in reality the Flash Player will never be able to achieve this frame rate. However, it will try to achieve this frame rate which results in a much smoother overall animation.
Unfortunately until now I've not been able to release a 1.0 version of my library but as far as I know it's pretty stable. You're more than welcome to use it in any way you see fit. I've used Coretween in many commercial productions including this one we did for StGeorge bank here in Australia.
Here are a few Actionscript based animation libraries:
TweenMax
Tweener
They both work well, and should help you with what you need.