Why simple 2d game in unity lag? - unity3d

I created a very very simple 2d game in Unity, but sometimes (every 2-3 seconds) there is a small lag. (on iMac, on iPhone, on iPad, on editor unity)
Information:
All textures reduced and still compressed (5kb - 100 kb) (aprox. 50 tex)
All scripts are optimized (In update I use only one Translate for one object which contains multiple objects(train with 10 railway carriage) with Rigidbody2D(isKinematic) and CapsuleCollision2D,
and small checkers (like if(sound != 1) then sound = 1))
Scene have about 20 objects (images, canvas, panels, 2 particles system (snow) with mobile shader > particles > additive and spawn one in every 1 second).
In Awake I set Screen.SetResolution((int)(Screen.width / 1.7f)), (int)(Screen.height / 1.7f)).
I have already optimized everything, and several times. He raised a lot FPS, reduced weight, increased smoothness, but small lags remained.
TODO: I created new clean project, I added 1 image and created script which translate image from right to left, and THERE ARE ALSO friezes!!!
When I play:

Related

is there a limit to the size of a SKSpriteNode() texture? (4000 x 4000)

I have been adding textures to SKSpriteNode() and also getting the texture from nodes in order to change them.
When adding textures I can't add a texture over 4000 wide or high without it resulting in a black SKSpriteNode() (the texture exists, its just black)
When getting a texture from a node I have to make sure the result is within 4000 width or height by scaling the node before getting the texture otherwise it is blank again.
This is all fine for my game at the moment but I am wondering if there is an inbuilt limit of 4000, just so I can allow for it.
(there is a reason why I am using such large textures...so it is possible that I might go over 4000 width occasionally)
Check out this helpful chart from Apple:
https://developer.apple.com/metal/limits/
It has a lot of information about graphical limitations. If you want to know the maximum texture size for iOS, find the entry for "Maximum 2D texture width and height".
It depends on what operating systems you are targeting. For example, if you want to support iOS 8 and higher you are restricted to the iOS 8 limit for 2D textures of 4096 x 4096 pixels even though later versions of iOS can support larger textures.

Stage FPS raises on preloading

I have separate manifest files for each level of my game. So when user is playing on Level #1, files for Level#2 are being preloaded at the same time using LoadQueue (PreloadJS).
I've noticed some strange behaviour. Stage FPS is set to 24. But FPS raises (it can be noticed visually) while its preloading next files. It comes to normal FPS when files are preloaded..
How do I fix it? FPS raises at least 1.5x times.
EDIT: I'm using Ticker (RAF activated) and its set to 24 frames per second. Also each sprite has its own 'framerate' property. In most cases its set to 24 as well, but sometimes it has 16 (every 3 frame has been cut and hence framerate set to 16).
EDIT2: Here is an example to check the issue. There are 2 manifest files (for Level1 and Level2). Level1 starts while level2 is being loaded in the background. You can notice that the sprite in Level1 played on higher FPS. It gets to normal FPS when Level2 loading is completed.
It's better to download it and test locally, otherwise FPS changes are less noticable when downloading speed is not as high as in local or on WiFi.
Link: http://www.filedropper.com/preloadjsfps

Too many glDrawElements cause for low fps? OpenGL ES1.1 ( iPhone )

I am developing a 2D Tile based game and currently struggling with performance issue as I am getting around 10 - 15 FPS even when running on iPad 3. OpenGL ES Frame capture reveals that I am making call to glDrawElements 689 times per frame! Is that a lot? Could it be the case of low performance?
Should I stack everything in one huge array and perform 1 draw call? will it make any difference?
At this point in time, you are currently limited by your command issue(assuming), if you run opengl performance detective ( it's under xcode (right click, open developer tools) you may have to download it through preferences ).
Your goal is to be limited by fill rate at the end of the day, here are some tips to help you get there
Sort all sprites by
Draw Depth
Blend Mode
Texture ID
Once sorted,
Pack all sprites into one vertex buffer object and an index buffer object.
When ever your draw depth, blend mode, or texture ID change, it's time to make a new draw call and bind those resources.
Also keep in mind that your sprites should have your vertices flatted on the cpu side (pos x mvp ) and you should not be sending over matrices and any other attributes such as color, should be part of the vertex.
Typical vertex
{
float pos[3]
int color
float uv[2]
}

Converting Flash Animation to Cocos2D

Abstract
What I require is a technique, given a single, but layered Flash animation, to export the position and rotation of each key movie clip in every frame as XML.
Code to read in this information into a cocos2d-ready format would save a lot of time but isn't necessary as I know how to achieve this.
Our artists often draw vector using Flash and have wonderful and impressive animations. Our technique in the past to put this art into our games is to export the separate animations as a sequence of pngs, stick them in a sprite sheet, and turn them into CCAnimations.
This technique works well and we can get quite a lot of art into the 20MB over the air download limit thanks to spritesheets and pvrtc. As we grow, however, we are looking to make bigger and better games, and this would mean more art!
What I'd like to achieve now is a mass reduction in the amount of art by using a keyframing technique to mimic Flash behaviour, removing duplicate pieces of art.
i.e. Using the current technique, one character would take:
A walk sequence with 10 frames (say 100 * 300 resolution, 30k pixels) would have
10, full sized humans in each stance. (for a total of 1000 * 300
resolution, 300k pixels for one animation)
Say 5 similar animations for a total of 1.5 million pixels
The desired outcome for the same character:
1 right leg: (40 * 30, 1200 pixels)
1 left leg: (40 * 30, 1200 pixels)
1 torso (50 * 50, 2500 pixels)
1 left arm (40 * 30, 1200 pixels)
1 right arm (40 * 30, 1200 pixels)
1 head (30 * 30, 900 pixels)
Total (8200 pixels) for all animations
And an xml file to explain the transform of each part for each frame.
My knowledge of Flash is limited. I have exported a LOT of art, so that's not a problem, but I don't have much experience in Actionscript or in exporting other information. I have noticed the Export Motion as XML option but it doesn't provide the information I need (It doesn't traverse to the children of movie clips to get their transform).
The Objective-c side of things is less of a problem, I know how to parse XML, though if somebody has already written this too, I'd be very grateful if you'd like to share.
I never did find out about any existing tools and so ended up learning a bit of ActionScript and writing the solution myself.
Unfortunately due to corporate policies I won't be able to share my code but I will outline the steps I needed to take
ActionScript / Flash
Step through each frame
Get the children on the stage on that frame and note their transform
Go through each of their children and note their transform with relation to their parent
Do this recursively until the children have no children or you have reached a DrawingObject
Save the information as XML
Art
Export each symbol you need from the library and add to a sprite sheet. (I did this using JSFL)
Obj-C / Cocos2d
The XML should contain a set of frames with a list of children for each frame and, recursively, each of their children. Each child node contains transform information.
Read in this XML, adding children to frames of an animation as you find them and children to their respective parents. Apply children's transforms.
Hope this helps somebody else.
I assume your question is about the "mass reduction" part. You should definitely have a look at TexturePacker. With TexturePacker you can create texture atlases that contains only a single image of multiple, identical animation frames while retaining your ability to address that frame with its original filenames.
TexturePacker has a cocos2d and flash exporter, and can import from the usual file formats. If there's something not quite as you need it you can contact the author, Andreas Löw. He is very responsive and committed to providing the best texture packing tool possible.
I wrote my own lightweight solution.
A simple library to export and animate Flash symbols in iOS / cocos2d, with included example.
Workflow:
Create your animations in Flash as MovieClips with animated layers containing Graphic symbols.
Export animations as JSON + frame PNGs using included JSFL script.
Convert PNGs into sprite sheets (use your own tools, I use - http://www.codeandweb.com/texturepacker)
Include animation JSON file(s) and sprite sheets in app bundle.
Load textures, run complex multilayer animations on sprites using simple commands.
Check it out on github:
FxAnimation for Cocos2d 2.x
FxAnimation for Cocos2d V3 RC1
This is my first github submission and I'm curious how useful people find it, so let me know.

Cocos2d. Diffuse image (60 fps)

The game was created by support cocos2d 0.99.5 and Box2d.
Iphone SDK 4.3
We have a character. When a character moves quickly, it looks blurred (fuzzy // unfocused). On a simulator and on device (iPhone 3G).
To move a character using mouseJoint (dampingRatio = 0 // frequencyHz = -1).
In the screenshot image clearly. link
The character is focused. The screenshot not transfer problems.
All the time 60 fps.
Tried params:
use kCCDirectorProjection2D // 3D
alies // antialies to texture params
CC_COCOSNODE_RENDER_SUBPIXEL 1 and 0
Video sample: link
How to get a clear image of the character during the move?
I also had a problem like this and fixed it by changing this line in ccConfig.h:
#define CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL 0
to
#define CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL 1
This is the comment for this define, maybe it helps someone.
/** #def CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
If enabled, the texture coordinates will be calculated by using this formula:
- texCoord.left = (rect.origin.x*2+1) / (texture.wide*2);
- texCoord.right = texCoord.left + (rect.size.width*2-2)/(texture.wide*2);
The same for bottom and top.
This formula prevents artifacts by using 99% of the texture.
The "correct" way to prevent artifacts is by using the spritesheet-artifact-fixer.py or a similar tool.
Affected nodes:
- CCSprite / CCSpriteBatchNode and subclasses: CCLabelBMFont, CCTMXTiledMap
- CCLabelAtlas
- CCQuadParticleSystem
- CCTileMap
To enabled set it to 1. Disabled by default.
#since v0.99.5
*/
I am pretty sure that what you are describing is an optical illusion. LCDs, especially lower-quality LCDs, have a finite response time. If this response time is too slow, it can cause ghosting, i.e. the moving object looks smeared. Basically what's happening is the previous frame's (or several frames') pixels take a long time to actually "turn off" and you see fainter versions of your sprite left behind as it moves.
With regards to your comment:
For the experiment, I took a pencil and put it to a sheet of paper
began to move quickly. Eyes see a pencil in focus, then problem is not
an optical effect, a code problems
Looking at a moving object in the real world is not the same as looking at a moving object on the screen, with or without a poor display response time. The real-world object moves continuously, but the screen object moves in discrete steps. Your eye can follow the pencil exactly and keep the image sharp on your retina. If you follow a screen image, however, your eye moves smoothly, while the screen image "jumps" from place to place. This can cause a "juddering" effect for sufficiently fast-moving objects, even at high framerates. If 60fps is still juddery, there is basically no way around this; it is a limitation of current technology.