OpenAphid-Engine

JavaScript&OpenGL ES Powered 2D Game Engine for Native iOS/Android Apps

Safe Type Casting in Objective-C With ‘Instancetype’

instancetype is a relative new keyword in Objective-C language. Besides its general usage scenarios, it can be leveraged for safe casting. The approach is simply a category to NSObject:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@interface NSObject (OAUtils)
+ (instancetype)oa_cast:(id)any;
+ (instancetype)oa_cast:(id)any warnOnFailure:(BOOL)warnOnFailure;
@end

@implementation NSObject (OAUtils)
+ (instancetype)oa_cast:(id)any
{
    return [self oa_cast:any warnOnFailure:NO];
}

+ (instancetype)oa_cast:(id)any warnOnFailure:(BOOL)warnOnFailure
{
    if (any)
    {
        if ([any isKindOfClass:[self class]])
            return any;
        else if (warnOnFailure)
            NSLog(@"Can't cast %@ to type %@", any, NSStringFromClass([self class]));
    }

    return nil;
}

Part I: How to Choose a JavaScript Engine for iOS and Android Development

DISCLAIMER: the post contains my personal opinions on the subject. I would appreciate it if you could correct my mistakes.

Back to the time when I started OpenAphid-Engine, there were already several similar iOS/Android projects. These projects, either commercial or open source, expose their core features by JavaScript language. For instance, Titanium and PhoneGap allow developers to use JavaScript to build native iOS/Android apps; ngCore enables building cross platform games by pure JavaScript. JavaScript language has been chosen as a first-class citizen as it’s one of the most popular programming language. It eases the learning curve and easily attracts developers into a new product ecosystem.

How to Handle Touch Events in Flip Animation

Updates at 2012-12-12: Please checkout FlipView for an improved solution.

This short post explains how to handle touch events for the flip animation introduced in our previous post.

The full source codes of the demo application are available at Github:

https://github.com/openaphid/android-flip/tree/master/Legacy/Demo-Touch/

A pre-built APK file is also present for your Android devices:

https://github.com/openaphid/android-flip/blob/master/Legacy/Demo-Touch/APK/Flip-Touch.apk

Updated at 2012-08-17: Fixed the broken links to the project and the APK file.

OpenAphid-Engine Android v0.1 Released

We’re excited to release the first version of OpenAphid-Engine which supports Android OS. OpenAphid-Engine is now a cross platform 2D game engine with both iOS and Android support.

Several github repositories have been updated, please check them out for more details: