Understanding logic of SpriteKit animation with texture atlases - ios

I just don't get it. For example: I'm making a game with enemies. I made some pics and put it into atlas. I want an enemy to stand still before he will collide with hero and then implement an animation. Should I add first pic from atlas to represent an enemy at first and then somehow add all atlas to that pic to animate it? Also, if I want to make the size of an enemy as twice the hero size: do I need to code it only for the first sprite (if I need to add it first) or for every sprite one after another or even the whole atlas itself? I can't understand how to interact with them!
Also, I'm trying to make game universal, is that correct to name sprites like enemy001#1x.png; enemy001(at)2x.png; enemy001(at)3x.png and put it in one atlas? I'll appreciate any help with this, thanks!
I'm coding it with swift if that matters.

Your question is too confusing in what your are specifically asking.
"I can't understand how to interact with them!"
is not a good question. You need to be more precise and break it down into several questions if need be. However, below are some pointers which might clarify some issues for you.
You typically preload a texture atlas to avoid delays during your game play.
When you init a SKSpriteNode you can either use a texture (preferred when using an atlas) or an image.
To animate a sprite you run a sequence of images. There are several ways of accomplishing that. For example: -(SKAction *)animateWithTextures:(NSArray *)textures timePerFrame:(NSTimeInterval)sec would run an animation sequence of images placed into the NSArray.
Sizing for different screen sizes has been asked numerous times on StackOverflow. Do a search and see what comes up.

Related

Deflod rendering issue

I am going to make simple 2D game in Defold game engine and I am new in this area. My question is, I have 2 game objects every object has sprites in it. A sprite in the first game object must be background for sprites of second object. I have designed it well but when I run (or render, I don't know how to call properly) it sometimes sprites of second game object are invisible and some times everything is OK.
The same issue if I set main backgruon image for the game. Please share your experiences with me. Thanks beforehand.
You posted the same question on the official Defold forum so I'm going to replicate the answer you got there here on SO as well. The solution is to make sure that the depth of two game objects that overlap isn't the same. If two objects have the same depth and overlap you might sometimes see one in front of the other and sometimes vice versa. The default render script allows a z-range of -1 to 1 (you can use fractional z-values to get fine grained control), but you can copy it from builtins and increase the range if you want to. Something like -10 to 10 is usually a good enough value.

How do I reorderChild sprites without a texture atlas?

For memory reasons I decided to not use texture atlas anymore, I want to load few sprites from file when I use them.
using batchnode, there was a very handy method which is reorderChild that automatically set sprites to front or back depending the axis they are
Is there any feature like that for free sprites? I'm not asking for the algorithm to do that.. just confirming if there is nothing similar to reorderChild out there before get my hands dirty.
Yes, I searched a lot before coming here,
thanks all

collision detection and creation in xcode class

I'm working on making a new app in xcode and have run into two problems that always seem to be a problem when I program large projects.
Basically, I want the user of this app to be able to input specifics like size, position, color, and possibly speed and/or direction.
These inputs will create a square of specific size, position, and color which will move around the screen and interact with other squares the user has created.
Now here are my problems:
First: I have absolutely no idea how to create something in code. I know I almost certainly have to do this in a class, but I've never figured out how to do this in a single programming language.
Second: Interaction between the squares. How do I detect collisions between the possibly dozens or hundreds of squares the user creates.
I'd really like to figure out how to do this, especially because I'm sure it'll be helpful in not only this, but many other future projects.
Thanks
I would recommend using sprite kit for the collision detection and creation of the squares. You'll probably want to subclass SKSpriteNode to define the properties for your squares.
https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Introduction/Introduction.html

How to optimize my memory usage with sprites...between SpriteFrameCache and SpriteBatchNode

I have seen the usage of plist and png atlasses for the game i am developing. However I've notice a slight performance swiftness(speed up) keeping the 60 fps, and for a side note my app has not crash at the moment.
The thing is I noticed I have used SpriteFrameCache with plist to do CCactions and animations for my characters(sprites). However some of the characters ive been using SpriteBatchnode, but it was on accident, since I am relatively new to deep development of a game, I didnt notice this difference before, they both work, but I feel like both are the same, its just that one has an easier way of implementation than the other, i was thinking that perhaps it was developed in an earlier version....
so my question is. is there a difference between the two? will my game benefit for using SpriteFrameCache over SpriteBatchNode?
Thanks for the help.
FYI: this doesnt slow down my developing, its just a question because I know at the end when my game is finished maybe i would want to optimize performance for my game.
Batch nodes draw all child sprites in one draw call.
Sprite frames hold a reference to a texture and define a region in the texture to draw from. The cache allows you to access sprite frames by name.
Both are different concepts, they are not replacements for each other. You can use sprite frames to create sprites or sprite frame animations. In addition to that sprite batching enables you to speed up rendering of two or more sprites using the same texture.
Note that if you use a batch node with only a single child sprite this will not be any different from rendering the sprite without the batch node, since both create a single draw call so there is no positive effect in using the batch node.

Animating a character in Cocos2d

I am creating an app that represents the pages of a book with animation and interactive areas. There is one character who is constant throughout but each page has them represented in a different look so I cannot re-use the frames very easily. This character has wings, legs and eyes which all need to move differently. What I am wondering is what is the best way to take them from the PSD into the app? The two approaches I can think of is either:
Create a separate png for each frame of the animation and then cycle through them (this would be combined into a single sprite atlas)
Split the character into their parts and then position, rotate, scale and move them in the app manually.
The main reason I am considering point 2 is that if I do point 1 then I will need to create a lot of frames of animation for each page and also create them all twice to cater for normal and retina displays.
Please let me know what the correct approach for this may be and if there is anything I should keep in mind.
Thanks
Option 1 sounds much more feasible. 300 frames is a bit too much, but you dont have to load all of them in the memory at the same time. Divide your frames into multiple spritesheets of 1024*1024 and make sure all the frames of the same animation are on a single spritesheet. So, at any given moment, only a single texture would be loaded in the memory, which I guess is the minimum anyway.
You can also do a bit more optimization maybe, by creating separate animations for things that behave the same in different poses. For example, if the eyes are blinking exactly the same in different poses, you can stop creating separate frames for each pose just for blinking. Just take out the eyes (ouch!), create a separate animation for them, and place it over your character's animation node.
Going with option 2 would create un-necessary complications, both for you and the poor device.

Resources