|
Topics
Advertisement
|
|
Topics
Advertisement
|
FaceBlimp on iTunes store for iPhone, iPad and iPod Touch (requires iOS 5 or newer).
Just releases this app that utilizes iOS 5′s new face detection capability. The app detects the eyes and mouth in the picture them animates them. Apply glasses and mustache to the face using easy to use interface. Save the photo into photo ablum or send via email. You cam import photos or take photos using the device camera.
![]() |
![]() |
More about iOS 5 facial detection can be read here: http://www.permadi.com/blog/2011/12/facial-recognition-in-ios-5/
Using UIWebView is an efficient way to make an About screen, Help screen, or other sort of hard to layout. Consider how easy it is to lay out your ‘page’ in html, instead of having to build it using Interface Builder. You can even use JavaScript and add interactivity if you want.
You can even use the same code for your web page and app.
The process is simple. Create the html and include all the files (in the project, then load the html, using code such as:
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"Help"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[m_webView loadRequest:request];
Above example assumes your HTML files and all its associated assets (such as images and stylesheet) are in a folder named Help. When adding these files into the project, I usually select the “Create Folder References For Any Added Folders” so that all the files inside that folder is added into the project.
You can also load from a remote site, instead of embedding the HTML files into the app. Another extra benefit is that you can modify the HTML content any time you want, as opposed to having to submit a new version to iTunes. The code is something like this:
NSString *urlAddressString = @"http://www.permadi.com/tutorial/ios-html-help-example/index.php";
NSURL *url = [NSURL URLWithString:urlAddressString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[m_webView loadRequest:request];
You should take into account is that if you load from the internet, sometimes the device may not have an internet connection, and in that case, you should have a fallback, otherwise user may see a blank screen and think your app is crap. The method that use to check for connection uses the Reachability utility class from Apple: http://developer.apple.com/library/ios/#samplecode/Reachability/
Reachability* reachability = [Reachability reachabilityWithHostName:@"permadi.com"];
NetworkStatus networkStatus = [reachability currentReachabilityStatus];
So the complete code looks like this:
Reachability* reachability = [Reachability reachabilityWithHostName:@"permadi.com"];
NetworkStatus networkStatus = [reachability currentReachabilityStatus];
if(networkStatus == NotReachable)
{
// Load local version if there's no internet connection
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"Help"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[m_webView loadRequest:request];
//[m_webView setBackgroundColor:[UIColor clearColor]];
}
else
{
NSString *urlAddressString = @"http://www.permadi.com/tutorial/ios-html-help-example/index.php";
NSURL *url = [NSURL URLWithString:urlAddressString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[m_webView loadRequest:request];
//[m_webView setBackgroundColor:[UIColor clearColor]];
}
If you want the UIWebView to have a transparent background (great in popup), then you should set the Background Color of the UIWebView as Clear Color and set it to non Opaque.
In addition, in the html side, set background-color of the body element to transparent.
<style type="text/css">
body
{
background-color:transparent;
}
</style>
For this to work on iOS less than version 5, you should call this:
[m_webView setBackgroundColor:[UIColor clearColor]];
Yes, do this even if you already set the background color to Clear Color in the XCode Interface Builder.
You can tell iOS to shrink your page to fit by for example:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
[m_webView setScalesPageToFit:YES];
}
Attached is an example project that loads a page from the remote site. Download.
Click the i button on the top left to open the HTML view.
The project is made in XCode 4.2.
Cocos2d has always been a popular choice for iPhone game development. Now there's now cocos2d-x (http://www.cocos2d-x.org/), a spinoff initiated by Walzer Wang. cocos2d-x is a cross platform version of cocos2d that produces iOS and Android app (plus Windows executable output as bonus if you like). Cocos2d-x accomplishes the cross-platformness by using native C/C++ code. This means that, yes, you need to use C/C++ for most of your code.
After trying it and running the examples, cocos2d-x seems to be a solid choice for cross platform development.
This walkthrough is my experience in getting the sample code to compile and run. I stumbled along the way and hopefully this guide can help you in some ways.
One of the first thing I tried was to compile the Sample game by Ray Wenderlich, for iOS and Android, which can be found at: http://www.cocos2d-x.org/attachments/535/Cocos2dxSimpleGame-0.9.1.rar (aka "The -x port of RayWenderlich's Cocos2dSimpleGame").
The sample game is an arcade game where you shoot incoming aliens by touching the screen to set bullet directions. I successfully ran it on an iPad 2, an iPod Touch, a Nook Color and a Kindle Fire.
As you examine the code, pay attention to are stub files that handle the platform specific tasks and you can even mix and match when you want. On the Android, these are the Activity class and the JNI stubs, while in iOS, there are the ViewControllers and Delegates. Notice that these stub files does not contain much (which is good), and you can even use the same stub as a template. Setting up the environment is half of the battle, especially getting the NDK (this is Android's Native Code (C/C++) interface) on the Android side, while on iOS, it's a lot more straightforward if you are already savvy with XCode. On Android, I specifically used the Sequoyah plug-in.
Assuming you already have XCode installed (version 3 or 4), then using cocos2d-x in XCode is straightforward. I am using XCode 4.3.
I got this error . This might have been fixed in the latest version, but the version that I downloaded are not finding some files (in red):
And you might also received this error:
If you look at <your-folder>Cocos2dxSimpleGame\Cocos2dxSimpleGame\libss folder, you'll see that it's empty, so just copy the lib files from <your-folder>Cocos2dxSimpleGame\cocos2x and <your-folder>Cocos2dxSimpleGame\CocosDenshions into <your-folder>Cocos2dxSimpleGame\Cocos2dxSimpleGame\libs. (Note: Might be possible to do folder symbolic link? I didn't try that.)cocos2d libraries Group Command /DeveloperXCode4.2/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1 Command /DeveloperXCode4.2/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1 Command /DeveloperXCode4.2/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1 Command /DeveloperXCode4.2/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1
I think this is because the project was built with XCode 3 and I am using 4. To fix it, go to the Build Settings and make sure these circled values are valid:Unsupported compiler 'GCC 4.2' selected for architecture 'i386'
In the Compiler for X/C++/Objective C section, if it says Unrecognized, chose either the Apple LLVM Compiler or LLVM Compiler.
Do the same for the cocos2dx libraries target.
If you get this error when running on Simulator 4.3:
Goto here to see possible solutions: - http://www.cocos2d-iphone.org/forum/topic/19384 - http://stackoverflow.com/questions/8178287/dyld-library-not-loaded-usr-lib-libcabi-dylibdyld: Library not loaded: /usr/lib/libc++abi.dylib Referenced from: /Users/Ferry/Library/Application Support/iPhone Simulator/4.3.2/Applications/F7A7BBFD-2749-46B3-B57B-B462CBFF4619/Cocos2dxSimpleGameForIOS.app/Cocos2dxSimpleGameForIOS Reason: image not found
.
More details on the official Wiki.sudo ./install-templates-xcode.sh
I run Mac OS and Windows but I primarily uses Windows to develop for Android so the guide below is for Windows Eclipse. You need the Android NDK setup to compile cocos2d-x projects. Also, I am using the Sequoyah plug-in to enable NDK compilation from Eclipse. I don't know about you, but I hate using command prompts and this plug-in makes creating native apps much more enjoyable. The Sequoyah set-up is not straightforward but for me it's worth it in the long run. You can read about my set-up here: http://www.permadi.com/blog/2011/09/setting-up-android-jni-projects-in-windows-eclipse-and-sequoyah/.
This guide assumes you have Sequoyah and Eclipse.
Alternatively, you can read about running the environment without Sequoyah from the cocos2d-x wiki: http://www.cocos2d-x.org/projects/cocos2d-x/wiki
**** Build of configuration Default for project Cocos2dxSimpleGame **** bash C:\android-ndk-r5c\ndk-build V=1 cygwin warning: MS-DOS style path detected: C:\PERMADI_WORKSPACE\AndroidExamples\Cocos2dxSimpleGame\Cocos2dxSimpleGame\android Preferred POSIX equivalent is: /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android CYGWIN environment variable option "nodosfilewarning" turns off this warning. Consult the user's guide for more details about POSIX paths: http://cygwin.com/cygwin-ug-net/using.html#using-pathnames rm -f /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/armeabi/lib*.so /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/armeabi-v7a/lib*.so /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/x86/lib*.so rm -f /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/armeabi/gdbserver /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/armeabi-v7a/gdbserver /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/x86/gdbserver rm -f /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/armeabi/gdb.setup /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/armeabi-v7a/gdb.setup /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/x86/gdb.setup Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver mkdir -p /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/armeabi install -p /cygdrive/c/android-ndk-r5c/toolchains/arm-linux-androideabi-4.4.3/prebuilt/gdbserver /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/armeabi/gdbserver Gdbsetup : libs/armeabi/gdb.setup mkdir -p /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/armeabi echo "set solib-search-path C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/obj/local/armeabi" > /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/armeabi/gdb.setup echo "directory C:/android-ndk-r5c/platforms/android-9/arch-arm/usr/include C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/jni/../../../cocos2dx/ C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/jni/../../../cocos2dx/include C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/jni/../../../cocos2dx/platform C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/jni/../../../cocos2dx/platform/third_party/android/iconv C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/jni/../../../cocos2dx/platform/third_party/android/libpng C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/jni/../../../cocos2dx/platform/third_party/android/libxml2 C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/jni/../../../cocos2dx/platform/third_party/android/libjpeg C:/android-ndk-r5c/sources/cxx-stl/stlport/stlport C:/android-ndk-r5c/sources/cxx-stl/system/include C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/jni/../../../CocosDenshion/android/../include C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/jni/helloworld/../../../../cocos2dx C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/jni/helloworld/../../../../cocos2dx/platform C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/jni/helloworld/../../../../cocos2dx/include C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/jni/helloworld/../../../../CocosDenshion/include C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/jni/helloworld/../../../Classes" >> /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/armeabi/gdb.setup Compile++ thumb : cocos2d <= CCConfiguration.cpp /cygdrive/c/android-ndk-r5c/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-g++ -MMD -MP -MF C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/obj/local/armeabi/objs-debug/cocos2d/CCConfiguration.o.d.org -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -Wno-psabi -march=armv5te -mtune=xscale -msoft-float -fno-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 - ............... Compile++ thumb : cocos2d <= CCLayer.cpp /cygdrive/c/android-ndk-r5c/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-g++ -MMD -MP -MF C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/obj/local/armeabi/objs-debug/cocos2d/layers_scenes_transitions_nodes/CCLayer.o.d.org -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -Wno-psabi -march=armv5te -mtune=xscale /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/obj/local/armeabi/libgame.so /cygdrive/c/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/armeabi/libgame.so /cygdrive/c/android-ndk-r5c/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-strip --strip-unneeded C:/PERMADI_WORKSPACE/AndroidExamples/Cocos2dxSimpleGame/Cocos2dxSimpleGame/android/libs/armeabi/libgame.so **** Build Finished ****
When the build is done, you'll see the message **** Build Finished **** in the Console. Pay attention to the Console output because it is going to say **** Build Finished **** even if there're errors. Errors are shaded in faint-red background in the Console. Another way to tell if there's no error, when you try to run the app, it will refuse to run if there's error.
In this case, make sure that you set the target to >3 because GLES is 4 or later only:android/jni/../../../cocos2dx/platform/CCGL.h:58:21: error: GLES/gl.h: No such file or directory
You might also encounter this kind of Eclipse FALSE WARNINGS galore (what fun!).
Since Eclipse will refuse to let you Run the app, your option is to confirm that these are not real errors, and turn off the Syntax And Semantics Error warnings in the Eclipse (Preference->C/C++->General->Code Analysis).
Do Clean and Build afterward.
Where are the game code? Before answering that, note that there are two type of game code. 1) Shared 2) Platform specific.
In the example code, the Shared code is located in /../../../Classes. You can tell that they are Shared by the file type. The Cpp files are Shared and the .java ones are for Android only. You can see the list of the cpp files in jni/helloworld/
LOCAL_SRC_FILES := main.cpp \ ../../../Classes/AppDelegate.cpp \ ../../../Classes/HelloWorldScene.cpp \ ../../../Classes/GameOverScene.cpp
In Eclipse, switch to Native Development perspective (you'll have this Perspective if you did the Sequoyah install guide):
Then expand the Project in the Project view:
The Classes folder contains the game logic source files shared between platforms.
The AppDelegate.cpp is the entry point common to all the platforms. It tells which Scene to run and you'll find this line there:
// create a scene. it's an autorelease object
CCScene *pScene = HelloWorld::scene();
The HelloWorld.cpp naturally contains the game itself. In this sample game, almost all the game logic is there.
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../cocos2dx \
$(LOCAL_PATH)/../../../../cocos2dx/platform \
$(LOCAL_PATH)/../../../../cocos2dx/include \
$(LOCAL_PATH)/../../../../CocosDenshion/include \
$(LOCAL_PATH)/../../../Classes
Goto Build Settings -> Header Search Paths
For instance, there is a Box2D library in Cocos2d-x, you can use it by including it in the build:
Android
=====
Examine the jni folder and open Application.mk:
# it is needed for ndk-r5 APP_STL := stlport_static APP_MODULES := cocos2d cocosdenshion gameThe APP_MODULES tells the compiler to compile. In this case: cocos2d, cocosdenshion, and game module. Where are those module defined? 1. The game module is in jni/helloworld/Android.mk. 2. The cocos2d-x module is defined at ../../../cocos2dx/Android.mk 3. The cocosdenshion module is defined at ../../../CocosDenshion/Android.mk
To add more library (such as the preincluded Box2D library) - open jni/Android.mk in this portion:
subdirs := $(addprefix $(LOCAL_PATH)/../../../,$(addsuffix /Android.mk, \
cocos2dx \
CocosDenshion/android \
))
subdirs += $(LOCAL_PATH)/helloworld/Android.mk
Android will look for Android.mk in each of those library folder (you can find premade Android.mk in each of those folder).
- Then add the module name into Application.mk:
Then find the main Activity file and add the library.APP_MODULES := cocos2d cocosdenshion game libbox2d
static {
System.loadLibrary("cocos2d");
System.loadLibrary("cocosdenshion");
System.loadLibrary("game");
System.loadLibrary("libbox2d");
}
Way more straightforward: just add them into the project and make sure any included files has their paths set in the Build Settings.