Is it possible to use SceneKit for GPU accelerated graphics within a cocoa Application?
I'm looking for a way to do 2D animations in a PowerPoint like application, and not sure which direction to take to have GPU accelerated animations.
Picked up xCode about a week ago and went straight into swift with no Objective-C background. Didn't find any information on the topic, hoping to get this answered here.
Your screenshot depicts the template selection in the project creator. What template you use has no impact on what features is possible in your application. It is perfectly possible to create a Cocoa app and simply drag and drop a SCNView and set it to run a SceneKit scene.
That being said, SceneKit or SpriteKit is definitely overkill just for doing "2D animations like in PowerPoint". You should look into Core Animation:
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreAnimation_guide/Introduction/Introduction.html
Related
I need to integrate animations to an iOS SpriteKit game. The artist provides them in Spine format. Such animation consists of a set of images, a .spine file describing the animations and a .json file describing the metadata.
I see two possible ways to solve this problem:
Find (or make) a module allowing to add nodes and related animations from Spine files to a SpriteKit scene.
Convert the animation to a different format which can be imported to SpriteKit easily.
Please, share your experience. Any help is welcomed!
There is a library that allows you to do exactly that. Installing & usage examples are in the description of the library.
https://github.com/maxgribov/Spine
I'm planing on making an utility app that could help people create table plans for sitting guests.
The thing is, the only way I see this is by letting users create first their own room, with the correct number of tables and sits, then populate the room with the guest list.
But to do that, I was thinking on using the Sprite Kit technology, because it seems to be an quick and easy way to make 2D schemes, use sprites and rely on coordinates.
Here comes the questions :
Is it possible to make an utility app with a "game" core ? Would Apple allow me to do so ?
If Sprite Kit is not an option, and regarding the fact I'm actually working on xcode 6 + Swift, what would be the alternative to make this process of letting the user create a room that uses X,Y coordinates?
I hope I'm clear, if you have any questions, I'll be happy to complete my requests. Thanks folks !
Nicolas
It depends on the design of your application and what it's requirements in terms of user interface. With SpriteKit, many of the interface elements provided by UIKit are not available and you'd have to build your own if you wanted to use SpriteKit exclusively.
However, there is nothing stopping you from also using UIKit for certain elements such as a UITableView, but it would be a separate view and input would need to be handled via UIKit system. With SpriteKit you don't have a bunch of UI elements to work with.
SpriteKit would mainly be most useful if you need animation and game-like functionality in your utility app.
Apple wouldn't restrict you from using SpriteKit for any kind of app.
In terms of an x,y coordinates, any element you create via SpriteKit or otherwise is going to allow you to position it in that way.
From SpriteKit programming guide, first sentence actually:
"Sprite Kit provides a graphics rendering and animation infrastructure that you can use to animate arbitrary textured images, or sprites."
That is what makes it ideal for games, however not limited to that.
I am going to make a 2D iPad game today, but I do not want to use a game framework. I am more interested in how the framework is created, how to program the physics, and other low level topics.
So, if I'm not using a framework, how do I start? Is the first step to create an OpenGL based app in XCode?
OpenGL would be a place to start, but i would look through the cocos2d source, and see how various things are being done in that.
To program a 2D game from the ground up, especially if you're new to iOS, I don't see any reason to use anything other than the CoreGraphics and CoreAnimation APIs. Any bitmap-based imaging is typically done via OpenGL behind the scenes.
I have been building a game in cocos for a while now I it has just occurred to me that it might just be a whole lot easier to use UIKit.
Could you please help me weight up the pros and cons, and share some experiences you have.
Here is my basic list of advantages for each. I feel I dont know enought about cocos to make a informed decision which is best.
Cocos
Game engine comes for free. Pause / resume callbacks every frame
Sprite animations
Uses open GL (is this true? is this an advantage?)
...Help me think of some more!
UI Kit
Far more Help / Documentation / Sample Code
Familiar for iPhone programmers
Easy to handel touch
Easy view animations
Easy to customise
Faster loading times? (is this true?)
Any feedback would be great!
EDIT: I have just seen a developer video (on an open GL game called Quest) where they used UI Kit for the UI elements, drawn over the top of the GL View. Is this possible / practical with cocos?
Cocos2d uses OpenGL for drawing its sprites, movements, and particles. Trying to use Quartz/Core Graphics (which is NOT accelerated!) is fundamentally much slower and power hungry.
Cocos2d is a sprite library with a scenegraph first and foremost. You would be duplicating effort to make a scenegraph using UIKit.
There are lots of nice freebies that work within Cocos which you would have to develop from the ground up.
So, in short: It draws way faster than CPU bound drawing calls, it provides 95% of what most sprite based games need without reinventing the same thing over and over, and is free.
Although UIKit is incredibly useful for gaming, Cocos2D offers a variety of easier ways to accomplish many common game-making operations. For instance, it has the ability to create easy scrolling-tile games (very common and very popular) using a simple few lines of code to import a "Tiled" map set. In terms of some of the benefits of UIKit over Cocos2D that you mentioned, they are very easy to accomplish in Cocos2D, as well.
Touch handling:
This is as easy as replacing the "touchesBegan" method of UIKit with "ccTouchesBegan" and setting self.isTouchEnabled = YES in the init method.
Animations:
This is so much easier in Cocos2d, mainly because frame rate and animation issues are solved. In UIKit, you cannot use CoreAnimation to move an object while still implementing collision detection. You would have to animate the object with an NSTimer. In Cocos2d, you can easily animate objects (called sprites) and still use collision detection and interaction with the object.
More Help/Documentation:
Cocos2D offers an incredible amount of documentation and, even more so, examples of code! If you can't find it there, there is a growing number of iPhone game developers who implement Cocos2D in their apps and are willing to help many problems.
If you are planning on developing games for iPhone, and not just general apps for productivity, music, etc., I highly suggest Cocos2D. Remember, you can always still find ways to combine this and UIKit for many operations! Those operations aren't completely lost!
I had an idea for an app that would require me to implement these little sprites that would require basic physics features like gravity, acceleration, etc... so naturally I looked into a game loop for the iPhone, there were plenty of threads on this, but what I am trying to understand is that I want to be able to create these sprites and have them behave naturally using a game loop, but still have full "standard" iPhone interaction, i.e. touches, pinching, swiping, core animation, core data, etc...
Is this just as simple as implementing a game loop on a background thread and updating sprites on that thread then doing the standard operations on the main UI thread (except of course for obvious background tasks)?
I would like some general overview of this type of thing if thats possible.
I wanted the same thing, but the iPhone SDK is all about async and callbacks and it's better to roll with the framework rather than fight it. If Cocos2d does not satisfy you, you could look into hooking into NSRunLoop.
With regards to CADisplayLink: I noticed a drop in performance (decreased triangle throughput) when using CADisplayLink with OpenGL ES (which you have stated you are not using so I will not elaborate further).
In Xcode try creating a iPhone OpenGL ES project. Just build and run with the default code. You should see a box moving up and down. This simple example should give you an insight into animating objects and how the OS version of the device matters. The OpenGL view is based off a normal view that you can attach gesture watchers to.
Check out one of the available game physics engines. Cocos2D is a good place to start: http://www.cocos2d-iphone.org/ -- free and lots of resouRces to get started with.