Friday, March 22, 2013

Launching URLs

How critical is this for Cocos2dx games? Very critical!

http://digitalsynapsesblog.blogspot.com/2011/09/cocos2d-x-launching-url-on-android.html

Tuesday, March 19, 2013

CCB Error with Cocos2d-x 2.0.4 and Cocos Builder (CCB)


Assertion failed: (ccNodeLoadersIterator != this->mCCNodeLoaders.end()), function getCCNodeLoader, file /Users/corytrese/Desktop/Development/SDK/cocos2d-2.0-x-2.0.4/HeroesOfSteel/proj.ios/../../extensions/CCBReader/CCNodeLoaderLibrary.cpp, line 70.

Translation: "You have put the wrong object type into the CCB file, under 'CustomClass' on your CCLayer.

Probably you put in your Scene not your child of  cocos2d::CCLayer and 
public cocos2d::extension::CCBSelectorResolver

Easy to fix once you figure out what that assertion is testing.

Using JNI? You'll Have Make Errors

When you get those mysterious 'make' errors, you'll need this reference:

http://www.gnu.org/software/make/manual/html_node/Error-Messages.html

Friday, March 15, 2013

Reading and Writing Files in C++ and Cocos2Dx

How to write a simple text file with Cocos2dx
http://www.cocos2d-x.org/boards/6/topics/10822

Someone tries to load XML file in Cocos2dx (and gets very close!)
http://www.cocos2d-x.org/boards/6/topics/882

Biggest Struggle for Cocos2dx file loading ... is Android. Look out for this issue
http://stackoverflow.com/questions/8220527/android-reading-a-text-file-from-assets-seems-to-include-a-lot-of-junk-before

There are many ways to copy one file to another file in C++
http://stackoverflow.com/questions/10195343/copy-a-file-in-an-sane-safe-and-efficient-way

Debugging bonus link:
http://www.cocos2d-x.org/boards/6/topics/12601

If you get all of the above working, soon you'll want to add IAP
http://www.cocos2d-x.org/boards/6/topics/20664

Here is a good link that shows syntax differences between Cocos2d and Cocos2dx
http://www.rengelbert.com/tutorial.php?id=190

Android SDK / NDK Debugging (device does not support the application's targetted CPU ABI)

First, just go into this assuming it is really hard.

You have two options that I can see.

First, Eclipse + CDT + NDK + ADT + SDK.
http://tools.android.com/recent/usingthendkplugin

Second, Visual Studio + WinDBG + NDK + SDK
http://www.wingdb.com/wgMobileEdition.htm
(http://ian-ni-lewis.blogspot.com/2011/01/its-like-coming-home-again.html)

I'm trying this with Cocos2d-x which makes it easier and harder at the same time.

The bad -- poor documentation, lots of unanswered questions
http://www.cocos2d-x.org/boards/6/topics/11046

The good -- ndkgbd.sh

--------------------------------------------

http://stackoverflow.com/questions/15067215/ndk-gdb-error-device-does-not-support-the-applications-targetted-cpu-abis


jni/Android.mk:26: *** Android NDK: Aborting.    .  Stop.
ERROR: The device does not support the application's targetted CPU ABIs!
       Device supports:  armeabi-v7a armeabi
       Package supports: Android NDK:

My challenge here was that I needed to add these to every static AND shared library I was building.

APP_ABI := armeabi

Android Developer? Windows? Download Ant Now!

You'll thank me if you do.

http://ant.apache.org/bindownload.cgi

Android SDK Cannot Contain Spaces -- How to Fix?

Set you SDK_ROOT to something like this:

C:\PROGRA~2\Android\android-sdk-windows

http://stackoverflow.com/questions/6629273/android-emulator-invalid-command-line-parameter

Very useful for WinDBG
http://www.wingdb.com/wgMobileEdition.htm



Thursday, March 14, 2013

C++ Inheritance and Virtual Functions

This link was really useful for understanding 'virtual' and how it works in the C++ syntax.

http://www.flipcode.com/archives/Using_Inheritance_And_Virtual_Functions.shtml

Cocos2d-x Events and Watchdog

The app delegate method applicationDidEnterBackground: is called after your application transitions to the background, but before your application is suspended. Unfortunately, you may not perform any GPU instructions while in the background, or the watchdog will terminate you (as you're seeing here).


libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient:
0x3797e094:  trap   
0x3797e096:  nop  

Thursday, March 07, 2013

Cocos2dx Extensions

This page was useful:
http://www.cocos2d-x.org/boards/6/topics/19388

For Visual Studio, add the following argument to the build command line:
/I"\cocos2d-2.0-x-2.0.4\extensions" 

For Android.mk file, add the following line to the end
$(call import-module,extensions) \

For XCode, add the "extensions" folder to the project

Tuesday, March 05, 2013

Mobile Game Cross Platform Development Tools

So I want to make a cross-platform game for mobile devices...lots of choices ...
  • Xamarin (Monotouch)
  • LibGDX + Monotouch
  • Cocos2d-x
  • Unity 3d
  • Shiva 3d
  • Corona
  • JUCE 
  • Marmalade (Airplay SDK)
  • HTML5 + JavaScript
  • JqueryMobile
  • Cocos2d-HTML5
  • Sio2
  • Adobe AIR

Bonus link:

Setting up Cocos2dx on Mac OS X:
http://gamedev.stackexchange.com/questions/28743/how-to-setup-cocos2d-x-android-under-mac-os-x

Bunch of Weird Lines on your TMX File in Cocos2dx?

Try setting CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL (in ccConfig.h) to a value of 1

Having trouble with loading files from 'assets' folder in Android, but it works in win32? Try the suggestions in this StackOverflow but also, check the case of the filenames.

http://stackoverflow.com/questions/12417748/cocos2dx-android-get-data-from-fileassets-failed

Random Bada Tutorial with some good code:

http://developer.bada.com/documentation/docView.do?docID=D000002309&&searchCategoryID=&searchTag=&searchDisplayDate=&currentPage=1&menu=MC01320300&pageCount=10&orderField=DISP_DD_TXT_DESC&searchPubYNFlag=Y

Errors with SimpleAudioEngine? Make sure you include the headers :)

http://stackoverflow.com/questions/12875426/simpleaudioengine-has-not-been-declared-error-when-trying-to-enable-music-paus

Using 2.0? They have moved sharedDispatcher

http://stackoverflow.com/questions/11264191/cocos2d-x-cctouchdispatcher-no-shareddispatcher

Use this:
CCDirector::sharedDirector()->getTouchDispatcher();

Not that:
CCTouchDispatcher::sharedDispatcher()->getTouchDispatcher();



Fixing Compile Issues with Visual Studio Project (.csproj) calling CCEGLView::create?

1. Open Property of Project.
2. Change the item value of "Character Set" to "Use Multi-Byte Character Set".
3. Rebuild your project.

'setIsTouchEnabled' : is not a member of 'HelloWorld'


If you are upgrading from Coocs2dx 1.x to Cocos2dx 2.x you will have a lot of conversion to do.

If you get the error:

'setIsTouchEnabled' : is not a member of 'HelloWorld'

you really want to switch the code to this:

this->setTouchEnabled(true);


You might struggle with how to convert a CCObject to an int. Use this type of cast:

int x = ((CCString *)spawnPoint->objectForKey("x"))->intValue();


You might also struggle with callfunc, which is very simple to use in Objective-C but not so easy in Cocos2dx.

http://stackoverflow.com/questions/11917928/callfunc-in-cocos2d-x

This tutorial was very useful building a demo game in Cocos2dx

http://www.raywenderlich.com/1163/how-to-make-a-tile-based-game-with-cocos2d

I was already familiar with it from using Cocos2d.


This commit is really large, but shows a lot of useful conversion moves from early Coocos2dx to modern. This guy or girl knew what he/she was doing and made quick work of a lot of before/after conversion code that made doing similar work on my side very easy. Just search for the code I had and found what they changed it to.

https://github.com/cocos2d/cocos2d-x/pull/779/files


Often we need to concatenate strings using the + operator. A shortcut way to do this in C++ is as follows:

CCSprite *sprite = CCSprite::spriteWithFile((name+".png").c_str());


This was kinda useful tutorial to introduce Cocos2d vs. Cocos2dx from a memory and reference counting standpoint:

http://www.rengelbert.com/tutorial.php?id=188

Cocos2dx Setup: Windows 7 Visual Studio and Eclipse

I have been working on building a cocos2dx application that runs on Windows 7 x64 in Visual Studio, Eclipse, iPhone and MacOS X.

I started with this setup guide:

I had to do a lot of installing ....
  • Cocos2d-2.0x (same download for Mac OS X and Win32)
  • NDK r8d on Mac OS X and Windows (different downloads for Mac OS X and Win32)
  • Newest ADT and Android SDK on Mac OS X and Windows (different downloads)
  • Native Development Tools -- Eclipse Plugin
  • Android Development Tools -- Eclipse Plugin
  • Cygwin on Windows (with : autoconf, automake, binutils, gcc-core, gcc-g++, gcc4-core, gcc4-g++, gdb, pcre, pcre-devel, gawk, make)
  • Visual Studio 2010 C++ Language Support
  • Eclipse CDT (C++ Development Tools)
  • Several Eclipse, Java, Windows and Mac OS X Updates along the way

In the end, I believe that the correct way to configure the application is to have a folder for the project and sub-folders as follows:
  • \cocos2d-2.0-x-2.0.4\TileMapGame\Classes
  • \cocos2d-2.0-x-2.0.4\TileMapGame\Resources
  • \cocos2d-2.0-x-2.0.4\TileMapGame\proj.android
  • \cocos2d-2.0-x-2.0.4\TileMapGame\proj.win32

You can get this far using two included .sh scripts
  • \cocos2d-2.0-x-2.0.4\create-android-project.bat
  • \cocos2d-2.0-x-2.0.4\create-android-project.sh

You will quickly notice that Cocos2d-2.0-x does not come with an easy facility to create an XCode project folder the way it does for Visual Studio and Eclipse.

To create the following folders I used Notepad2 and editing the .xcodeproj files
  • \cocos2d-2.0-x-2.0.4\TileMapGame\proj.ios
  • \cocos2d-2.0-x-2.0.4\TileMapGame\proj.mac
I started by copying over these folders
  • \cocos2d-2.0-x-2.0.4\samples\HelloCpp\proj.ios
  • \cocos2d-2.0-x-2.0.4\samples\HelloCpp\proj.mac
Then I made some important changes
  • Changed relative paths to 'cocos2dx.xcodeproj'
  • Renamed Project
  • Reconnected plist file
  • Fixed "Header Search Paths" to include correct relative paths
  • Converted "Resource" sub-folders to 'groups' by deleting and re-adding
  • Added CocosDenshion group and added 'ios' and 'include' folders
  • Added missing frameworks
    • AudioToolkit
    • OpenAL
    • AVFoundation
  • Set 'version' and deployment targets for iOS and Mac OS X

So at the end I have this structure
  • \cocos2d-2.0-x-2.0.4\TileMapGame\Classes
  • \cocos2d-2.0-x-2.0.4\TileMapGame\Resources
  • \cocos2d-2.0-x-2.0.4\TileMapGame\proj.android
  • \cocos2d-2.0-x-2.0.4\TileMapGame\proj.win32
  • \cocos2d-2.0-x-2.0.4\TileMapGame\proj.ios
  • \cocos2d-2.0-x-2.0.4\TileMapGame\proj.mac
The only two I have not created are 'proj.linux' and 'proj.blackberry' because at this time I do not have any need for them.

I used the following pages for debugging and troubleshooting: