Thursday, May 31, 2012

cocos2d-x resume from background issue...


I love cocos2d-x, it helps me to write games quickly on iOS and android with just one code base.

But I found a small problem that if my cocos2d-x games run into background, and when it get back to foreground, it will restart !

That means if you play my game for a while and a phone call just received, after you pick up the call, you will need to re-play the game from the very first stage.

That's bad, and I don't like it !

After a while googling, I found the solution, and I post here to make sure if someone have the same issue with me, and you can try this solution, it works for me, and maybe you too !

Step1 : open the AppDelegate.cpp

Step2 : make your code like below


// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
    CCDirector::sharedDirector()->stopAnimation();
    CCDirector::sharedDirector()->pause();

// if you use SimpleAudioEngine, it must be pause
CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
    CCDirector::sharedDirector()->stopAnimation();
    CCDirector::sharedDirector()->resume();
    CCDirector::sharedDirector()->startAnimation();

// if you use SimpleAudioEngine, it must resume here
CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}

Step3 : re-compile and run it

And that's all !!!

Hope you will enjoy your coding time !!!

Wednesday, May 16, 2012

MapRecord 3.0 is now coming !!!



Download Link:MapRecord 3.0 on App Store!

謝謝大家的捧場…MapRecord終於迎來了3.0的更新…此次更新了不少東西…詳列如下…還請各位新雨舊知記得更新啊…小弟叩謝…

★★★★★ 感謝大家的支持!新功能強力改版推出!

1. 改善錄影效率 - 支援最新的iOS5錄影,大幅減少lag的狀況!
2. 增加facebook、twitter分享功能以及可轉存至內建的照片庫 - 可以錄影畫面單格輸出,分享給好友,或是警察杯杯^_^!
3. 保留循環錄影段落 - 重要錄影畫面可立刻保留,不怕被循環錄影功能蓋掉。
4. 強化手勢操作 - 二指雙擊可開始/停止錄影,二指滑動可保留循環錄影片段,雙指可放大以及縮小地圖!
5. bug修正以及UI加強

PS:iPhone錄影時會產生高熱,請將機器放置於通風良好處以及將機體露出散熱,以免熱當。

Thanks for your support, MapRecord 3.0 finally comes out to App Store. There are several big things update, please don't forget to get your latest update version.

★★★★★ Thank you for your support! All new features are here for you!

1. Improve recording efficiency - Supports latest new iOS5 recording features, give you the smoothly video recording experience ever and never!
2. Facebook, Twitter sharing and save to Camera Roll features - You can save a whole video or a "Single Frame" of video, and share them to your friends!
3. Keeping a section of cycling videos - Instantly keep your cycling video clips, no afraid of overwriting them!
4. Improved gestures - Double taps with two fingers makes Start/Stop recording! Swiping with two fingers makes Keeping an recording clip! Two finger to zoom in/out maps!
5. Some bugs fix, and UI improve.

PS: When recording, to avoid that iPhone becoming over-heating! Please set device on a well ventilated place, and make it's body exposed for radiating the heat.

Monday, April 16, 2012

A simple note for On-Device-Crash...(Cocos2d-x)

This is my experience sharing.

I encounter a crash that only happened on device, but not on simulator.

It's painful to find the bug, but I did find finally.

The reason is simple, I just change my CCSprite action from a single action to CCSequence with multiple actions.

And the stupid thing is that I FORGOT to add an "NULL" at the end of sequencial actions.

Compile is fine, and the simulator runs smoothly, but It crashed when I deployed to my iPhone.

If you find a crash on action execution and that only happend on Device not on simulator.

Go to check all of your CCSequence actions, maybe you will find something that save your time( and time is money).

Hope this will help someone like me.



Welcome to my Apps Site : http://www.molioapp.com

Wednesday, April 4, 2012

A note about latest XCode 4.3.1

Caution ! There is a bug at latest XCode 4.3.1 !
Don't use the dragging files to add your source files.
Sometimes the XCode can't recognize it as a source file, and you will get an error when you link your .o files.
You need to use the add file features instead.

Thursday, March 29, 2012

update notes from cocos2d-1.0.1-x-0.12 to cocos2d-1.0.1-x-0.13.0-beta release

Today, cocos2d-1.0.1-x-0.13.0-beta is released.

And if you want to update to this new version, there are some minor changes you may need to do when you updated.

1. CCTouch remove the view() method.

So, if you want to detect touches, you need change your code like below.

Before:

CCPoint touchPoint = touch->locationInView( touch->view() );

After:

CCPoint touchPoint = touch->locationInView();

2. ccc4() has changed to ccc4f().

That's straight-forward changed. Just rename your function call from ccc4() to ccc4f().


BTW, there is another change that the android.mk under helloworld folder is gone. You may take your eyes on that and check if everything is fine if you build iOS & Android dual-platform project like me.


BTW2, don't forget to take a look on our cocos2d-x game: ChickenEggs both on iOS and Android. Now we have integrated facebook and twitter share features on that.(・ω・)

Thursday, March 22, 2012

ChickenEggs 2.0 Released !!!

mainmenu_art

ChickenEggs new version 2.0 has released to Android Market and Apple Store !

You will get this update soon on Android, and several days later on Apple Store.

After update to 2.0, you will get these features.

★ Sharing Your HighScores on Facebook and Twitter !!
★ New Bomb Mode !! You can de-active bombs !!
★ Adding Fantastic Effects with Egg Breaks !!

★ 現在你可以透過Facebook和Twitter和朋友分享你的高分成就!!
★ 全新的炸彈模式,現在可以透過快速點按來解除炸彈了!!
★ 新增加了數種畫面炫麗的特效,玩起來更過癮!!

Hope you will be happy with this new version !

BTW, any comment is welcome, please email me at simon@molioapp.com

Thanks.

Monday, March 12, 2012

Upgrade with cocos2d-1.0.1-x-0.12.0 and integrated with your original JNI functions...

Here are some notes that when I upgraded my game to .12 version what I learned about with new JNI architecture that cocos2d-x used.

Question 1:In the jni\helloworld\main.cpp, you can find there is already JNI_Onload() there. Yes, that means you can't implement your JNI_Onload.

Solution:You can call RegisterNatives() at JNI_Onload() which at main.cpp instead to register your jni class.

Something like the code below :

jclass clazz;
JNIEnv *env;
vm->GetEnv((void**) &env, JNI_VERSION_1_6);
const char *classPathName = "com/zhihmeng/ChickenEggsX/ChickenEggsX";
JNINativeMethod methods[] = {
{"init", "(Ljava/lang/Object;)V",
(void *)Java_com_zhihmeng_ChickenEggsX_ChickenEggsX_init},
};
clazz = env->FindClass(classPathName);
if (clazz == NULL) {
// LOGE("Native registration unable to find class '%s'", className);
return JNI_FALSE;
}
if (env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])) < 0) { // LOGE("RegisterNatives failed for '%s'", className); return JNI_FALSE; } Question 2:You may do some modifications on your JNI class, and JniHelper make these thing easier. Solution:Use JniHelper to get some static method info like MessageJni.cpp(located at cocos2dx\platform\android\jni) does and call your method by it. The code will like below: JniMethodInfo t; if (JniHelper::getStaticMethodInfo(t , "com/zhihmeng/ChickenEggsX/ChickenEggsX" , "exportToShare" , "()V")) { t.env->CallStaticVoidMethod(t.classID, t.methodID);
}

Finally, thanks the tweaks of cocos2d-x new JniHelper, it make jni calling more elegant.

You are also welcome to my studio page to see some of my works : www.molioapp.com