Corona SDK performance. Animation or Sprite sheet - performance

General Corona SDK question, what would get better performance having a runtime event listener on enterFrame or a sprite sheet. So essentially what i have is:
local function animate(e)
star.rotation = star.rotation +3;
end
Runtime:addEventListener ("enterFrame", animate);
return star;
Would this get better performance than having a sprite sheet that has the automation on loop. Both essentially go in a loop indefinitely (or until an action happens).

It's really a trade off. Your sprite is going to take up more memory, but it's probably faster to flip frames than it is to calculate the new angle and rotate the image. But it's going to be a pretty trivial difference.

Related

How do I pause the app completely when there is no activity?

I use this -
if (timeSinceLastClick > 60)
{
Time.timeScale = 0;
}
But that doesn't freeze either the ar camera/ar tracking or audio. Besides the animation, everything else seems to keep running.
I'd like to pause the app completely so the users can save their batteries and avoid heating
If you want to save battery/avoid heating I'd recommend either cull as much as you can or lower the target framerate.
Settings TimeScale to 0 will affect Rigidbodies and all scripts that multiply their movements by Time.deltaTime (which is highly recommended to achieve framerate-independency). It still computes every frame, as often as possible. So see above.
If you have occlusion culling baked, you could move the camera to an area that doesn't point at any renderable objects. A dynamic cube in front of the cam will probably not work as it's not baked into Occlusion Culling. But you could disable the main Camera and render the pause-menu on a second camera that is UI only for example.

Efficiently rendering tiled map using SpriteKit

As an exercise, I decided to write a SimCity (original) clone in Swift for OSX. I started the project using SpriteKit, originally having each tile as an instance of SKSpriteNode and swapping the texture of each node when that tile changed. This caused terrible performance, so I switched the drawing over to regular Cocoa windows, implementing drawRect to draw NSImages at the correct tile position. This solution worked well until I needed to implement animated tiles which refresh very quickly.
From here, I went back to the first approach, this time using a texture atlas to reduce the amount of draws needed, however, swapping textures of nodes that need to be animated was still very slow and had a huge detrimental effect on frame rate.
I'm attempting to display a 44x44 tile map where each tile is 16x16 pixels. I know here must be an efficient (or perhaps more correct way) to do this. This leads to my question:
Is there an efficient way to support 1500+ nodes in SpriteKit and which are animated through changing their textures? More importantly, am I taking the wrong approach by using SpriteKit and SKSpriteNode for each tile in the map (even if I only redraw the dirty ones)? Would another approach (perhaps, OpenGL?) be better?
Any help would be greatly appreciated. I'd be happy to provide code samples, but I'm not sure how relevant/helpful they would be for this question.
Edit
Here are some links to relevant drawing code and images to demonstrate the issue:
Screenshot:
When the player clicks on the small map, the center position of the large map changes. An event is fired from the small map the central engine powering the game which is then forwarded to listeners. The code that gets executed on the large map the change all of the textures can be found here:
https://github.com/chrisbenincasa/Swiftopolis/blob/drawing-performance/Swiftopolis/GameScene.swift#L489
That code uses tileImages which is a wrapper around a Texture Atlas that is generated at runtime.
https://github.com/chrisbenincasa/Swiftopolis/blob/drawing-performance/Swiftopolis/TileImages.swift
Please excuse the messiness of the code -- I made an alternate branch for this investigation and haven't cleaned up a lot of residual code that has been hanging around from pervious iterations.
I don't know if this will "answer" your question, but may help.
SpriteKit will likely be able to handle what you need but you need to look at different optimizations for SpriteKit and more so your game logic.
SpriteKit. Creating a .atlas is by far one of the best things you can do and will help keep your draw calls down. Also as I learned the hard way keep a pointer to your SKTextures as long as you need them and only generate the ones you needs. For instance don't create textureWithImageNamed#"myImage" every time you need a texture for myImage instead keep reusing a texture and store it in a dictionary. Also skView.ignoresSiblingOrder = YES; helps a bunch but you have to manage your own zPosition on all the sprites.
Game logic. Updating every tile every loop is going to be very expensive. You will want to look at a better way to do that. keeping smaller arrays or maybe doing logic (model) updates on a background thread.
I currently have a project you can look into if you want called Old Frank. I have a map that is 75 x 75 with 32px by 32px tiles that may be stacked 2 tall. I have both Mac and iOS target so you could in theory blow up the scene size and see how the performance holds up. Not saying there isn't optimization work to be done (it is a work in progress), but I feel it might help get you pointed in the right direction at least.
Hope that helps.

How to slow down javafx animation

I'm trying to make the stage.show() slow down. I figured out I might need to set KeyFrame, but am stuck at KeyValue, not understanding T endValue or Interpolator interpolator. Is this the right approach? If so could anyone explain to me what type is T.
Thank you!
You can't slow stage.show() down, if stage is a JavaFX Stage, because this is not an animation.
Controlling Animation Speed
An animation's speed is primarily controlled by its rate. Varying either the rate of playback of the animation or the duration of the animation will probably be all you need to do to get the animation speed you want.
animation.setRate(2) // play the animation at double speed.
animation.setRate(0.5) // play the animation at half speed.
On Interpolation
An interpolator is a mathematical function for calculating intermediate values between points. Here is an article on interpolation.
In JavaFX, the interpolators are used to define easing functions for changing values between keyframes of an animation. Likely, for what you are doing, either a straight linear interpolator or an ease in + ease out interpolator will be fine (those are the two most commonly used interpolators). Most of the time, the default interpolator used by JavaFX suffices and you don't have to change it.
The apparent speed of an animation might also be effected by the interpolated easing function applied to the animation's key values or by the magnitude of a keyvalue change (e.g. number of pixels translated, number of times to scale) divided by the keyframe's duration.
Further reference
If you don't understand what this means, then read the JavaFX animation documentation which will define the terms referenced and provide examples on how to use them.
Additional items in your question
What you want to do ("stage.show() slow down") is ambiguous to me in the context of animations, so I couldn't advise an approach for that - as TheJeed correctly states stage.show() is not an animation, so it makes no sense to try to apply animation to a stage.show() call.
T in the context of a KeyValue is a generic type, which seems to answer the question in your question but not the question in your title.
I agree the question was poorly asked. I didn't have the right approach. Just simply changing thread.sleep() will do the work.
But thank you guys anyway!

Flash animation dynamic speed

i'm wondering is there a possibility in flash to change animation speed dynamicly? For example if i move some slider it increase, or decrease animation speed. I know it could be done if animation would be made in actionscript, but if animation is complex and made in timeline what's then?
For complex animation in flash there can be only one choice, that is to use the Greensock TweenMax library.
You can create complex animations using timeline max, which allows you to sequence tweens, delay tweens etc.
Anything you can dream up can be done using this library.

Practical game animation?

I understand that game development involves a 'game loop', in which the scene is drawn. This game loop either runs as fast as possible (no timer, frame animation) or is called based on a timer (timer animation). I'm curious as to how advanced animation (something beyond just simple geometry) is actually done, considering how many frames might take place in say, a character walking. Obviously the programmer has not hard-coded in the position of the character's foot at every frame of the animation, so I'm wondering how this would actually be done?
If any clarification of the question is necessary, I'll be happy to fill more in.

Resources