Showing posts with label cocos2d. Show all posts
Showing posts with label cocos2d. Show all posts

2014-05-22

TDDLib for cocos2d-x-3.0 go public

I am going to put my Unit Test Framework for cocos2d-x 3.0 to open source (github). If you are a lover of TDD or Unit Test, you may love it. 

Github: https://github.com/tklee1975/tddlib_cocos2dx3

Currently, I am writing some documents about how to setup the library in your project and how to add a new test. If you are interested and like this project, please let me know.  


Testing "testSprite"


Testing "testLabel"

2014-05-11

Cocos2d-x 3.0 Setup (Include Git & Github support)

Recently, I am going to try the latest cocos2d-x 3.0 final version. Here is the note to use cocos2d-x 3.0 with the source control of Git & Github;





Steps to setup



1. Download and zip cocos2d-x 


Simply following the instruction at cocos2d-x official site ( http://www.cocos2d-x.org/download) to download.


2. Setup the directory structure 


The following is my structure related to the cocos2dx
  • /w/cocos2dx/engine - Place the cocos2d core at here. (The pack of the cocos2d-x project will be placed here)
  • /w/cocos2dx/project - The project directory, where is my code placed at.
  • /w/cocos2dx/script/ -  The script files simplify some task. (will discuss later)


3. Run the setup 


Just run the following commands

cd /w/cocos2dx/engine/./setup.py

It will change your .bash_profile to add some environment variable

Prepare the following information:  

  • ANDROID_SDK_ROOT
  • ANT_ROOT

4. Create a new project using script


Use the following command to make a new project :
cd /w/cocos2dx/engine/tools/bin/cocos_console/./cocos.py new -p ken.game -l cpp Example1 -d /w/cocos2dx/project/


5. (optional) Trim down the project size

Since every project made by the cocos.py will make a copy of the cocos2d engine inside the project. If you want to share the engine code among different projects, we can do steps below; However, if you are going to hack the engine code and don't affect other project, you shouldn't do that. One more point, this action will place the cocos2d engine source code outside the source control scope. (Pro: save space;  Con: change won't be logged)

Just do the following to keep the project smaller
mv ./cocos2d ../ln -s ../cocos2d ./cocos2d


6. Setup GIT 



Do the following step to setup GIT. 
  • Install Git. (suppose Xcode will help to install the git, but it doesn't happened. just go to http://git-scm.com/ to download it) 
  • Add the .gitignore to the project directorycd /w/cocos2dx/cp ./script/.gitignore project/Example1
  • Git initialisation
    run "git init" in your project directory
  • Add to SourceTree (SourceTree is a GUI version of Git. available at http://www.sourcetreeapp.com/)Select "Add Working copy" and the select the project directory (w/cocos2dx/project/Example1)
  • Commit the work at SourceTree


7. Sync with Github 


In the previous step, we just put the source code to the local repository; It will be more safe if we put the source on the remote location. Here, I select github. Besides github, there are many alternatives such as you setup your own git remote server or using bitbucket. 

There are the steps to setup repository in github.


     
  • Create a repository in www.github.com. (Assume that you are already registered) and copy-and-paste the git url.
  • Open SourceTree and select your project to add a remote location- Select the project.
    - Choose "Repository -> Repository Setting" in the menu.
    - Select the "Remotes" Tab.
    - Click the "Add" button; It will show the "Add Remote" Popup.
    -  Enter "origin" in "Remote Name" and the given github url in "Remote Path"
  • Pull the master branch to github (origin location)

8. Start coding and Enjoy it


Open the project in Xcode, build and Run it. 


2013-12-12

Setup Android Project on Cocos2d-x 3.0

Important things need to make cocos2d-x android project running

1. Make sure the Android SDK (ADT) and NDK ready 


2. Configure the Android.mk 


Need to config the following variables:

  • LOCAL_SRC_FILES : Because we may have more sources than the "HelloWorld" project
  • LOCAL_C_INCLUDES: The related header files will be searched by the compiler
  • LOCAL_WHOLE_STATIC_LIBRARIES: Our project may not need the sdk given
  • $(call import-module, moduleName) : Need to match with the LOCAL_WHOLE_STATIC_LIBRARIES


3. Configure the AndroidManifest correctly 

Need to config these two variables:

  • <uses-sdk android:minSdkVersion="9"/>  : Need to "9" or above to use Native Activity
  • <meta-data android:name="android.app.lib_name" android:value="App" /> : it will link to your native library called "libApp.so"

4. Copy the java source to proj.android

5. Prepare Eclipse to import the android project


Other Troubleshooting

Unable to load native library: "xxx.so"

Problem: Fail to define the native library
Solution: config the library name correctly in AndroidManifest.xml

For example: your library is libs/armeabi/libGame.so
the value defined in AndroidManifest.xml should be like the following:
<meta-data android:name="android.app.lib_name" android:value="Game" /> 
Note: No need to define the path, extension, and 'lib' prefix;

LogCat said "dvmFindClassByName rejecting 'org/cocos2dx/lib/Cocos2dxHelper"

Problem: Missing the java source folder
Solution:  http://www.cocos2d-x.org/forums/6/topics/36265

2013-11-04

Fixing CCBReader v.3 with Cocos2d-iphone v2.0.0


1. Occur Exception at CCLayer

Add the “setTouchEnable” method to CCLayer(at CCLayer.m)

- (void)setTouchEnabled:(BOOL)enabled
{
     [self setIsTouchEnabled:enabled];
} 

2. Cannot see CCLayerColor properly
Add the follow code segment in CCBReader just before the code "if ([node isKindOfClass:[CCBFile class]])” in the method called "(CCNode*) readNodeGraphParent:(CCNode*)parent"

if([node isKindOfClass:[CCLayerColor class]]){
     [(CCLayerColor *)node setOpacity:255];
} 

3. Cannot see CCLayerGradient properly

Add the “init” method to CCLayerGradient  (at CCLayer.m)
- (id) init
{
     return [self initWithColor:ccc4(0, 0, 0, 255) fadingTo:ccc4(0, 0, 0, 255)];
} 


4. CCControl doesn't change to Disable Look when control.enable = NO

Problem: When CCBReader generate the ccbi, it use "3" as the disable state, but it is "4" is iOS now;

Solution: 
Place the following in "CCBReader.m" at Method "readPropertyForNode" right before "if ([node isKindOfClass:[CCBFile class]])"

// Fix for DisableState
 if ([node isKindOfClass:[CCControl class]]) {
  // the disable state value is wrong!!!!
  //  CCBReader use 3 as CCControlStateDisabled, but it is 4 in iOS now
  // Change "|3" -> "|4"
  name = [name stringByReplacingOccurrencesOfString:@"|3" withString:@"|4"];
 }





Remark CocosBuilder is an user interface builder worth to integrate to your project; It can make your code more tidy and easy to modify later. This is the screen capture of the Demo GUI using CocosBuilder.

2013-11-02

Fixing CCBReader problem for CCScale9Sprite

Today, when making some unit tests to check the behaviour of the CCBReader (CocosBuilder Reader); 
Found 2 issues when adding a CCScale9Sprite to the Interface;

1. Crash if the interface included a CCScale9Sprite Node:
https://github.com/cocos2d/CCBReader/issues/16

2. The CCScale9Sprite Node have a wrong opacity setting
https://github.com/cocos2d/CCBReader/issues/17

Hope this small pieces of information helps

2013-08-29

Key Tasks of cocos2d-x development


Setup Development Environment

  • Make the iOS binary (.ipa), run on Simulator and Device
  • Make the Android binary (.apk), run on Device

Seek and Read References

  • Reference of Cocos2d-x
  • Reference of C++
  • Reference of POCO library

Create Testing Code

  • Create UnitTest for Logic (text mode stuff), suggest to use UnitTest++
  • Create UnitTest for GUI or Graphics stuff

Create Architecture / Utility / General Code

  • Clarify how MVC architecture work
  • Create Data Class
  • Create a singleton class
  • Make and understand Useful MACROs

Manage GUI, Graphics and Scene 

  • About GUI 
    • Custom View
    • Popup View
    • Fullscreen View
    • TableView
    • Scrollable View
    • Using Cocos builder to create the views
    • Gallery View
    • Loading View
  • About Graphics
    • Render Sprites
    • Render Maps
    • Render something you want to
    • Controlling the zoom and location of the Camera
  • About Scene
    • Add a new scene
    • Switch between scenes

Network Stuff

  • Connect using Socket or HTTP
  • Adding Network Protocol
    • Create Requests
    • Handle Response
    • Handle Network errors
  • Testing the network protocol

Debugging and Profiling

  • Check the potential problem
  • Check memory leak
  • Check the performance using profiler
  • Locate where and when will crash the app

Deployment

  • Create different kinds of build using Makefile/build.xml/.… 
  •  Publish the app (ipa or apk) using TestFlight


2013-05-31

Cocos2dx Study Checklist

Start learning Cocos2dx this week (End of May 2013)

Here is the checklist to be studies


  • [ ok ] Hello World
  • [ ok] Setting up TDD framework
  • [ ] Using CCMenu
  • [ ok ] Building iOS and Android using the same source code
  • [ ok ] Understanding the Coordinate System of Cocos2d
  • [ ] Memory Management
  • [ ] Make a CCNode/CCLayer Scrollable
  • [ ] Make a custom CCNode
  • [ ] Understand the SELECTOR (Method Pointer) 

Will keep update this checklist!!