Accessing sprite atlas from screen that is not an SKScene - ios

I have a SpriteKit game that accesses the sprite atlas images without issue.
However, in some of my menus I am using standard iOS UI components like table views and collection views. For those screens I lay out everything on a standard UIView controller.
However, on these screens I am not able to access the images unless I add those images to a separate folder which is not ideal.
How can I access them from the texture atlas? Thanks

You can't. Add these images separately, whether you also need to add these images to a Sprite Kit atlas depends on whether the game's performance suffers if you don't. There's currently no practical way to extract individual images from a SKTextureAtlas.

Related

Understanding logic of SpriteKit animation with texture atlases

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.

OpenGL ES 2.0 zooming at multiple resolutions

My iOS app draws 2D curves in an opengles view. The scene is very expensive to render (can take up to 1-2 seconds), which means that, AFAIK, I can't change the scale, redraw, and re-render for incremental changes in scale (due to pinch-and-zoom). I currently draw directly on a buffer that is rendered to the screen.
I think one way I can achieve zooming is by rendering to a texture at a given resolution and then render a quad with part of that texture (potentially at a different scale and translated). My guess is that it'll double the memory I'm currently using (if I of course keep the texture at the same resolution as the screen). Can someone confirm that? Is there another way to do zooming without redrawing while not doubling graphical memory usage?
Now, if I want to maintain a decent quality, I'll have to re-render at different resolutions. My initial thinking was to "manually" create a mipmap with e.g. 2 levels (1 texture for 100-150% zooming, and another one for 150-200% zooming). This time, I'll have 1 buffer + 2 textures. I can of course, re-render on panning but I don't think the user experience will be great. Any thoughts on how I can improve that from a user experience and/or memory perspective?
Since you already need that long to draw the scene I would suggest you to create tiling. You could draw the scene in different resolutions at load time and save the output to some images (save the image files into some temporary directory). With this approach you should have minimum memory consumption and the user experience should be great.
If you do this you should also consider if you even want to use openGL to present the scene since you have some very nice methods for presenting a large image on an image view, scroll view. Doing it this way you can actually skip all the GL - UIView bindings and presenting. You can move all the GL work to some separate thread which means if a scene should change you can do that in background allowing the user to work on the current scene uninterrupted. Also if you expect the user to be "swapping" between the scenes you can keep them saved and reuse them without any performance impact at all.

More memory efficient way of displaying images in iOS?

I have a photo collage app that takes a bunch of photos from a user's facebook/instagram/library, and draws a bunch of them onto the UIView. To control the amount, there is a slider tool that calculates density (for example, every 150px wide, add an image). I'm running into memory issues after lots and lots of UIImageViews are being added.
Is there some better, more efficient way of showing images onto the screen?
Why not use a UICollectionView. It's designed to present a group of objects (including images) in a manner similar to UITableVIew. Like a TableView memory is automatically managed by the controller.
See the documentation for more information.
You didn't make it clear in your question exactly how you're using this set of images. An alternative is to draw the images into the graphic context using Core Graphics. This will draw the images into a single view instead of into several views. There's only one bitmap to keep in memory. See Drawing a PNG Image Into a Graphics Context for Blending Mode Manipulation for an example.

Multiple instances of one UIImageView on-screen

I am making a game where bullets are involved. Its a machine gun, so there will be more than one bullet on the screen at the same time. How to I write the code for the properties and actions of one bullet and apply that to all of them, like multiple instances of the one bullet?
The key point to making a game is the concept of sprite, i.e., a light-weight object that has a graphical representation and that you can move around (managing collisions, etc).
You could try to implement sprites on top of CALayers, using Core Animation, or you might decide to use a game framework like Cocos2D.
For the first approach have a look at this short tutorial. This could also help you if you want to implement your sprites using UIImageViews, although you have to keep in mind that CALayer are light-weight, UIView are not, so if you plan to have many of them that could make a difference.
As to the question of replicating the bullet, basically the key suggestion would be using some form of caching, so that you do not end up replicating the same image in memory multiple times. A very basic caching mechanism is available with the UIImage class if you use the convenience constructor imageNamed.
Again, if you plan to make a full fledged game with a good performance (say 40-60 fps), the best suggestion is using Cocos2D, which will offer you all the power of Open GL graphics wrapped in a simple interface.
Have you tried subclassing UIImageView? That way you can have a function createBullet that creates a subclassed UIImageView and adds it to the screen, and in the subclass it can contain functions and properties for animating etc...

Dynamic Tile Map possible with Cocos2D?

I want to be able to load a list or an array of tiles and displayed them on a map.
Cocos2D offers a possibility to load tiles on a map. But for my case, I have to load just a specific part/range of tiles (which I define) and this changes dynamically during the run time. I never want to load the whole map at once. Is this possibile? Maybe an alternative to Cocos2D on iOS? The map details come from a server. It should be done in a quite large multiplayer environment, that's why each player/client should only load his relevant parts of the map.
You can definitely do this, and there are many different ways. For example, swapping scenes or layers during run time, with different tile maps on them, or by creating tile maps your own way with a custom set of methods using CCSprite (for example, it is common to create your own parallax scene instead of using the built-in Parallax scene methods in Cocos2d, and you could do the same with tile maps, if desired). The options are really limited only by creativity.

Resources