Posts Tagged 'Programming'

Sequencer: Async Flow Control

Here’s a sweet library for getting rid of those annoyingly deeply nested block constructs:

berzniz / Sequencer

Sequencer is an iOS library for asynchronous flow control.

Sequencer turns complicated nested blocks logic into a clean, straightforward, and readable code.

Sequencer *sequencer = [[Sequencer alloc] init];
[sequencer enqueueStep:^(id result, SequencerCompletion completion) {
    NSLog(@"This is the first step");
    completion(nil);
}];
[sequencer enqueueStep:^(id result, SequencerCompletion completion) {
    NSLog(@"This is another step");
    completion(nil);
}];
[sequencer enqueueStep:^(id result, SequencerCompletion completion) {
    NSLog(@"This step is going to do some async work…");
    int64_t delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        NSLog(@"finished the async work.");
        completion(nil);
    });
}];
[sequencer enqueueStep:^(id result, SequencerCompletion completion) {
    NSLog(@"This is the last step");
    completion(nil);
}];
[sequencer run];

What does the above code do?

A Sequencer was created. There is no need to retain/hold-on-to-it. Trust me.

Four steps were enqueued to the Sequencer. The third step is async, but all the rest are plain sync code.

Each step finishes by calling completion() with a result object. This result is sent to the next step (in our case the result is nil).

We run the sequencer.

Note: Break the steps by just removing the call to completion(nil). Everything will be cleaned-up auto-magically.

Simple, elegant, and functional: What more could you ask for?

h/t: ManiacDev!

Continue Reading →
0

Review: Creating Games with cocos2d for iPhone 2

So as promised in our cocos2d survey a couple days back, we’ve been reading the latest from Packt,  Creating Games with cocos2d for iPhone 2:

9007OS_9007OS_Cocos2d for iPhone Hotshotcov.jpg.png

and why yes, we quite like the approach it takes. Most books we read go through pieces of a big project where the newbie finds themselves easily overwhelmed, or are snippets without a context so you need to be able to grasp their application on your own; what this one does is present nine complete but small enough to be easily graspable games of popular genres — and bundled them up to the App Store too, where you can check them out to see if you’re interested in seeing the code:

Pack 1 – Mole Thumper, Brick Breaker, Pool

Pack 2 – Memory, Match 3, Snake, Scrolling Shooter, Endless Runner

Pack 3 – Cycles of Light

The theory behind that is explained on the cocos2d blog here:

… Most developers learn the basics of cocos2d for iPhone v.2.0, and subsequently hit a wall. We have all these interesting classes that are really powerful, like CCLayer, CCSprite, actions, etc. How can we put these things together and make something equally interesting out of them?

That is the “gap” this book aims to fill. Rather than take the beginner’s book approach, where we spend several pages explaining what a sprite is, how it is drawn, etc. “Creating Games” skips many of the generalities and jumps right into the reason we are here: building games. This is the book I wished I had in hand when I was first exploring cocos2d for iPhone.

Class by class, method by method, the text explains the “good parts” of why we are building the code in this fashion. All the “good parts” are explained in detail: from building with Box2D to GameKit Bluetooth integration, and even how to build in “artificial randomness” into a Match 3 game, so you never run out of moves.

Each chapter is a complete game, and all source code is available as a download from the publisher’s web site. The games cover a wide variety of game types, and the games become more intricate and complex as the book progresses…

Can’t add to that really, except to observe that why yes the book is pretty much perfectly positioned to help cover that jump from reading the API to figuring out how to actually use it. So if you’re a complete newbie, we’d still recommend The iPhone Game Kit; but if you’ve got a bit of programming background but are new to cocos2d and/ot game programming, yep this is an excellent choice. Or if you’re interested in checking out the approach the author takes to the covered game genres, which are

  • Chapter 1: Memory
  • Chapter 2: Match 3
  • Chapter 3: Mole Thumper
  • Chapter 4: Snake
  • Chapter 5: Brick Breaker (with Box2D)
  • Chapter 6: Cycles of Light (iPad with Bluetooth integration)
  • Chapter 7: Pool (with Box2D)
  • Chapter 8: Scrolling Shooter (using Tiled)
  • Chapter 9: Endless Runner

One quibble you might have is that why isn’t v2.0 out of date already? Yep, but not by much, and download notes to bring it up to speed are on the author’s site. And while you’re there, check out the video. Definitely the best trailer we’ve ever seen for a programming book. (Pretty sure it’s the only trailer we’ve ever seen for a programming book, so the bar’s low there, but hey.)

So overall? Well, we like to reserve five stars for books that qualify as “absolutely essential fundamentals”, and it’s not quite that, but it is definitely a well done guide with far more coherence than you’ll find hunting down tutorials and samples on the web. Solid four stars, with the particular recommendation that if you find yourself in the position of being able to install cocos2d and run the samples but are having trouble gapping that over to getting started on your own game, this is the absolutely perfect book for you!

Continue Reading →
0

State of cocos2d Address: 2013

So just over one year ago we took a look at developments in the cocos2d world in the previous year while gearing up to review Packt’s latest book on the subject, and why look; we’re doing the exact same thing now! This year, it’s Creating Games with cocos2d for iPhone 2:

9007OS_9007OS_Cocos2d for iPhone Hotshotcov.jpg.png

… and in very short order we trust, we’ll have opinions for you on it!

Meanwhile, the most surprising — although in hindsight obvious — news of 2012 in cocos2d land was the announcement of the explicit refocus from iOS gaming to a cross-platform development suite:

… Our goal is to provide a complete toolchain for developing multi-platform games both for Web and Mobile, all the way from rapid prototyping to a finished high performing game. The main components of our stack are:

For the Web, we are using pure JavaScript code, while for Mobile we are using JavaScript on top of native engines for maximum performance…

Apparently 2012 was also a good year for altering common understandings of terms like “maximum”. But snarkiness aside, yes it’s pretty likely that many iOS-centric developers are willing to compromise as much as Zynga to improve cross platform development efficiency; so this is no doubt A Good Thing™ for them. Latest coordinated release as we type here was four days ago, release notes here.

On the other hand, if you understandably recoil in quivering horror at the thought of sullying your iOS-centric vision with accommodations to those other, lesser, platforms, then 2012 brought you the full blown fork “KoboldTouch”. That seems to be chugging along nicely as well so far.

Tools-wise, the landscape of essential goodies really didn’t change during the year aside from the anointing of CocosBuilder mentioned above, but keep your eye on Spriter and ArtPigEditor as possible supplements. This tools list from July looks still pretty much up to date, and of course the mothership’s Editors/Tools forum is always worth keeping an eye on. Oh, and when you get around to marketing videos, Kamcord looks pretty nifty.

On the learning resources side, the only brand new book of 2012 is the one above; but Mr. KoboldTouch brought out a third edition “Learn Cocos2D 2″, and our still #1 recommended getting started resource is The iPhone Game Kit, now updated for iOS 6 and cocos2d 2.0. ‘Course, soon as you get your feet wettish with those, you should head directly to RayWenderlich.com, who definitely wins the Internet as far as iOS tutorials go. Notable cocos2d posts/updates are

Other miscellaneous tidbits, tips and tricks from around the web (ok, mainly ManiacDev.com) of interest:

Example: Easily Creating Particles In Cocos2D That Can Both Fade In And Out

krzysztofzablocki / CCNode-SFGestureRecognizers – “a category designed to simplify adding UIGestureRecognizers support”

Exporting Flash Animations to Cocos2d Actions

Open Source: Library For Importing Flash Animations Into Cocos2D iOS

Tutorial: How To Easily Create A Cocos2D AI Controlled Actors With A Finite State Machine Compiler

Example Source Code: Easy Cocos2D Sprite Floodfill Class

List of Open Source Cocos2d Projects, Extensions and Code Snippets

18 Tools and Source Code Components for Cocos2D iOS Game Development

Tutorial: How To Make Jagged Drawn Lines Smooth In Cocos2D

How to Zoom In on a Cocos2D Node

Example: Open Source iOS Castle Destruction Game Using Cocos2D And Box2D

Cocos2D and Storyboards

nerdcave / PESprite – “a CCSprite extension for cocos2d that supports collision detection”

CloudBomber – Cocos2D deformable terrain example project

Pixel based destructible ground with Cocos2d

A Magnifying Glass for Cocos2D

Open Source Cocos2D Based Framework For Creating Highly Interactive iPad Books

Building a depth map for cocos2d in Photoshop

Tutorial: Build An Angry Birds Style Game Quickly W/Cocos2d, LevelHelper and SpriteHelper

sceresia / CCAutoType – “cocos2d-iPhone class to add RPG-like auto typing dialog”

Simple Fractal terrains [in] cocos2d

Tutorial: Create A Character With Ragdoll Physics Using Chipmunk And Cocos2D

Strategies for Accessing Other Cocos2D Nodes In The Scene Hierarchy

The Four Ways of Implementing a Scrolling View with Cocos2D Explained

Example: Displaying A 3D .OBJ Model In Cocos2D iPhone v2.x (W/Zooming, Rotation, And Movement)

Example: An Open Source iOS Pokemon/Pet Type Game Created Utilizing Cocos2D

UPDATES:

Open Source Pinch To Reveal Animation using Cocos2d

Continue Reading →
1

Overloading C Functions

Did you know that the latest versions of Clang let you overload C functions? We’d completely missed that!

Clang provides support for C++ function overloading in C. Function overloading in C is introduced using the overloadable attribute. For example, one might provide several overloaded versions of a tgsin function that invokes the appropriate standard function computing the sine of a value with float, double, or long double precision:

#include <math.h>
float __attribute__((overloadable)) tgsin(float x) { return sinf(x); }
double __attribute__((overloadable)) tgsin(double x) { return sin(x); }
long double __attribute__((overloadable)) tgsin(long double x) { return sinl(x); } 

Given these declarations, one can call tgsin with a float value to receive a float result, with a double to receive a double result, etc. Function overloading in C follows the rules of C++ function overloading to pick the best overload given the call arguments, with a few C-specific semantics…

That’s one of the vanishingly few things we still occasionally miss from our C++ days. Kinda awesome to get that for Objective-C!

Overloading C Functions with Clang demonstrates how to use this for a single map function for NSDictionary and NSArray; and by way of that, if you’re not overly familiar with functional language conventions, here’s a good article on Understanding map, filter, and fold.

h/t: @romainbriche!

Continue Reading →
0

STTweetLabel

This is certainly conveniently timed; yesterday they decided they’d like player names to be tappable to bring up the player’s card everywhere they’re displayed in Atimi’s sports apps — and why look, today we have an example of just how to go about that!

SebastienThiebaud / STTweetLabel

A custom UILabel view controller for iOS with certain words tappable like Twitter (#Hashtag, @People and http://www.link.com/page)

screenshot.png

h/t: iOS Dev Weekly!

Continue Reading →
1

CMUnistrokeGestureRecognizer

Ever tried to write a UIGestureRecognizer? Kinda hard, wasn’t it? Well, check out CMUnistrokeGestureRecognizer:

How would you go about recognising a gesture like this star shape in an iOS app?

star_gesture.png

This was the problem posed to me recently while working on a project … Created by three clever chaps at the University of Washington back in 2007, the $1 Unistroke Recognizer was designed to recognise single path (unistroke) gestures, exactly what I was looking for. Not only that, but design goals for the technique make it an ideal candidate for use in mobile applications…

CMUnistrokeGestureRecognizer is my port of the $1 Unistroke Recognizer to iOS. I’m not the first to implement this recogniser in Objective-C but none of the existing implementations met my requirements. I wanted the $1 Unistroke Recognizer to be fully contained within a UIGestureRecognizer, with as simple an API as possible.
So the CMUnistrokeGestureRecognizer implements the $1 Unistroke Recognizer as a UIGestureRecognizer. It features:

  • Recognition of multiple gestures
  • Standard UIGestureRecognizer callback for success
  • Template paths defined by UIBezierPath objects
  • Optional callbacks for tracking path drawing and recognition failure
  • Configurable minimum recognition score threshold
  • Option to disable rotation normalisation
  • Option to enable the Protractor method for potentially faster recognition

Looks like just the thing for adding complex gesture support into your apps, doesn’t it now?

h/t: iOS Dev Weekly! (Yes, we just read the Dec. 14th issue. Getting back up to speed, slowly…)

Continue Reading →
0

Injection for Xcode

Now here’s something we missed back earlier this year: Injection for Xcode!

Using Injection it is possible to make a change to the implementation of an Objective-C® class and have it take effect as soon as the class is saved without having to restart the application. This feature works for OS X and iOS applications in the simulator and on iOS devices.

Injection works by converting your classes into categories using a small set of preprocessor macros. This category can then be loaded at run time using a bundle. As Objective-C “binds” at runtime it will always chose the new implementation of the class over that which the application was last built with…

That sounds like pretty much the niftiest tool you’ve never heard of, doesn’t it? Unfortunately, seems like neither did anybody else, and Apple put it in the “we’ll just sit on this submission forever” limbo…

Screen Shot 2012-12-08 at 7.42.37 AM.png

… but hey, now it’s up on github for you!

h/t: @romainbriche!

Continue Reading →
2

Tips: Auto Layout

Had some … issues … getting iOS 6 auto layout to work quite the way you expect? Nope, you’re not alone.

Screen Shot 2012-11-29 at 6.49.38 PM.png

Here’s a couple posts with some helpful tips:

Auto Layout & Interface Builder Tutorial: Solving some common problems

IB has a few quirks (some would say large number of flaws) which can make it seem like black magic trying to bend it to your will…

Issues With Achieving Auto Layout Zen

I’ve had better luck trying to read women in my failed relationships than trying to debug why my constraints aren’t working out…

Tip: Manually Adding iOS 6 Auto Layout Constraints

Tip: Ambiguous Auto Layouts in iOS 6

If you haven’t really got into this auto layout thing yet, the best introductory tutorials are at raywenderlich.com, exactly where you would expect by now:

Beginning Auto Layout in iOS 6: Part 1/2 and Part 2/2

And finally, if you think this auto layout stuff sounds kinda nifty but are stuck targeting iOS 5, might want to take a gander at

RolandasRazma / RRAutoLayout

RRTestApp has constraints based layout and all constrains added in interface builder like you normally would do for iOS6, whats interesting is that it has deployment target iOS5. You can run same project on iOS6 and iOS5 and it should look and behave (when rotating) the same. Essentially its iOS6 AutoLayout) back port to iOS5…

UPDATES:

iOS Autolayout: Fun Facts and Tips

iMartinKiss / KeepLayout: “Making Auto Layout easier to code.”

How Much, or How Little, I Use Interface Builder These Days

⌘⇧ – Command Shift series:

dkduck / FLKAutoLayout: “is a category on UIView which makes it easy to setup layout constraints in code.”

10 Things You Need To Know About Cocoa Autolayout

Continue Reading →
1

UIActivity Providers

So you’ve probably noted in iOS 6 that UIActivity and UIActivityViewController let us simply and prettily present various sharing-type options to the user, which is a nice step forward on the data sharing front but still requires each developer to integrate UIActivity code for the services they support. So wouldn’t it be convenient if someone maintained a list of those? Why, yes, yes it would…

UIActivity Providers for iOS6

A directory of all the iOS6 UIActivity providers in one place.

Make it easy for your users to share the amazing content in your app.

…and there we go then. Currently listed providers are

Google Chrome

Pinbook

Readability

Instapaper

Instagram

Buffer

SoundCloud

NNReadLaterActivity

Flattr

plus the built in Facebook/Twitter, of course. Be sure to submit any other ones you know about!

h/t: iOSDevWeekly!

UPDATES:

CocoaControls tagged UIActivity

Dropbox!

Calendar!

Safari!

LINE!

A better UIActivity API

ZYActivity – An easier to inherit UIActivity

UIActivityCollection

Customizable UIActivityController Replacement iOS UI Control That Works On iOS 5

WHMessageActivities: “UIActivity subclasses for direct customization of MessageUI controllers.”

ADN Activity Collection for iOS

MLCruxActivity for iOS

Continue Reading →
0

User Support: Helpdesk, Neemware

You know, for how important everyone agrees that direct user support is for keeping users happy and avoiding one-star reviews, it’s kinda surprising a) how many of us actually implement it on a level somewhere between “an email link that almost nobody finds” and “nothing”; and b) how little there is available in the way of mobile-focused infrastructure for that kind of thing. Only thing we find in our archives is this three year old post which, well, still pretty much covers things as of last week, really.

But in the span of four days we got two, count em’, two, emails from people who want to do something for you about this lamentable lack! In alphabetical order, they are

Helpshift — “The first and only customer support help desk for native apps”

  • Engage users in-app with a native, familiar experience so they don’t stop using the app
  • Cut down on support time with a searchable FAQ that answers common questions
  • Privately resolve user issues to avoid negative app reviews and increase app ranking
  • Integrate a seamless UX built for mobile that you and your users will love

Helpdesk.jpg

Intriguing, yes? They’re in invitation-only preview mode right now, and there doesn’t seem to be any information available on what the eventual cost of the service is planned to be, but we certainly encourage you keen early adopters out there to sign up and let us know how things go!

And in the other corner of this week’s new contenders, we have

Neemware – “In-App Marketing, Messaging, Cross-Promotion & Feedback for Mobile”

As the tag suggests, this one is more a platform for managing user engagement — or, put less diplomatically, a way to push out all the kinds of things that the APNS terms of service don’t allow:

  • Send rich in-app messages in real time
  • Target messages to users based on app usage
  • Send messages without app updates to store
  • Cross promote apps
  • Get in-app feedback
  • In-App reply to user feedback
neemware.jpg

They’re also in try it for free mode right now, and the planned pricing seems pretty reasonable too; so we even-handedly encourage you keen early adopters to check this one out as well and let us know how that works out for you!

And as always, Dear Readers, if you have any feedback on other solutions for the user support/engagement space that have worked out well for you, please share the enjoyment!

Continue Reading →
0
Page 2 of 82 12345...»