Android 启动时cocos2d-x错误

Android 启动时cocos2d-x错误,android,cocos2d-x,android-anr-dialog,Android,Cocos2d X,Android Anr Dialog,我正在为android开发一款简单的游戏,在cocos2d-x-2.2.2中出现了ANR错误 ----- pid 9068 at 2014-04-28 10:12:02 ----- Cmd line: lexu.me.childstudy_lite DALVIK THREADS: (mutexes: tll=0 tsl=0 tscl=0 ghl=0) "main" prio=5 tid=1 WAIT | group="main" sCount=1 dsCount=0 obj=0x41f565

我正在为android开发一款简单的游戏,在cocos2d-x-2.2.2中出现了ANR错误

----- pid 9068 at 2014-04-28 10:12:02 -----
Cmd line: lexu.me.childstudy_lite

DALVIK THREADS:
(mutexes: tll=0 tsl=0 tscl=0 ghl=0)

"main" prio=5 tid=1 WAIT
| group="main" sCount=1 dsCount=0 obj=0x41f56568 self=0x41f469d8
| sysTid=9068 nice=0 sched=0/0 cgrp=apps handle=1074292272
| schedstat=( 0 0 0 ) utm=1332 stm=1187 core=0
at java.lang.Object.wait(Native Method)
- waiting on <0x42598a28> (a android.opengl.GLSurfaceView$GLThreadManager)
at java.lang.Object.wait(Object.java:364)
at android.opengl.GLSurfaceView$GLThread.surfaceDestroyed(GLSurfaceView.java:1618)
at android.opengl.GLSurfaceView.surfaceDestroyed(GLSurfaceView.java:532)
at android.view.SurfaceView.updateWindow(SurfaceView.java:543)
at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:229)
at android.view.View.dispatchWindowVisibilityChanged(View.java:7425)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1042)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1042)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1042)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1042)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1220)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:736)
at android.view.Choreographer.doCallbacks(Choreographer.java:566)
at android.view.Choreographer.doFrame(Choreographer.java:536)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:722)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)

"Thread-152" prio=5 tid=19 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x4259c358 self=0x5bf0a018
| sysTid=9125 nice=0 sched=0/0 cgrp=apps handle=1542320592
| schedstat=( 0 0 0 ) utm=1 stm=4 core=0
#00 pc 0000dce0 /system/lib/libc.so (__futex_syscall3+8)
#01 pc 00012ea4 /system/lib/libc.so (__pthread_cond_timedwait_relative+48)
#02 pc 00012f00 /system/lib/libc.so (__pthread_cond_timedwait+60)
#03 pc 000f135d /system/lib/libwebcore.so
#04 pc 0036ba79 /system/lib/libwebcore.so
#05 pc 002940b5 /system/lib/libwebcore.so
#06 pc 000f121d /system/lib/libwebcore.so
#07 pc 00012e60 /system/lib/libc.so (__thread_entry+48)
#08 pc 000125b8 /system/lib/libc.so (pthread_create+172)
at dalvik.system.NativeStart.run(Native Method)

"Thread-151" prio=5 tid=18 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x425c9588 self=0x5bedf278
| sysTid=9104 nice=0 sched=0/0 cgrp=apps handle=1539574728
| schedstat=( 0 0 0 ) utm=27 stm=35 core=1
#00 pc 0000dab0 /system/lib/libc.so (epoll_wait+12)
#01 pc 0012bb89 /system/lib/libchromium_net.so
#02 pc 0012b995 /system/lib/libchromium_net.so
#03 pc 000585d9 /system/lib/libchromium_net.so
#04 pc 00056cd7 /system/lib/libchromium_net.so (MessageLoop::RunInternal()+114)
#05 pc 00056d35 /system/lib/libchromium_net.so (MessageLoop::Run()+16)
#06 pc 000773f9 /system/lib/libchromium_net.so (base::Thread::ThreadMain()+188)
#07 pc 00076e83 /system/lib/libchromium_net.so
#08 pc 00012e60 /system/lib/libc.so (__thread_entry+48)
#09 pc 000125b8 /system/lib/libc.so (pthread_create+172)
#10 pc 000fedd4 <unknown>
at dalvik.system.NativeStart.run(Native Method)

"Binder_3" prio=5 tid=17 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x425ed620 self=0x41c98950
| sysTid=9099 nice=0 sched=0/0 cgrp=apps handle=1103726864
| schedstat=( 0 0 0 ) utm=1 stm=0 core=1
#00 pc 0000cbd0 /system/lib/libc.so (__ioctl+8)
#01 pc 00027ea5 /system/lib/libc.so (ioctl+16)
#02 pc 00016bfd /system/lib/libbinder.so (android::IPCThreadState::talkWithDriver(bool)+124)
#03 pc 000173af /system/lib/libbinder.so (android::IPCThreadState::joinThreadPool(bool)+154)
#04 pc 0001b171 /system/lib/libbinder.so
#05 pc 00010f47 /system/lib/libutils.so (android::Thread::_threadLoop(void*)+114)
#06 pc 00044b53 /system/lib/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+66)
#07 pc 00010aad /system/lib/libutils.so
#08 pc 00012e60 /system/lib/libc.so (__thread_entry+48)
#09 pc 000125b8 /system/lib/libc.so (pthread_create+172)
at dalvik.system.NativeStart.run(Native Method)

"AsyncTask #1" prio=5 tid=16 WAIT
| group="main" sCount=1 dsCount=0 obj=0x425844f0 self=0x5c32b008
| sysTid=9087 nice=10 sched=0/0 cgrp=apps/bg_non_interactive handle=1545663784
| schedstat=( 0 0 0 ) utm=0 stm=0 core=0
at java.lang.Object.wait(Native Method)
- waiting on <0x42567c40> (a java.lang.VMThread) held by tid=16 (AsyncTask #1)
at java.lang.Thread.parkFor(Thread.java:1231)
at sun.misc.Unsafe.park(Unsafe.java:323)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2022)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:413)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1009)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1069)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)

"CookieSyncManager" prio=5 tid=15 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x42584628 self=0x41ca32e8
| sysTid=9086 nice=10 sched=0/0 cgrp=apps/bg_non_interactive handle=1105207824
| schedstat=( 0 0 0 ) utm=0 stm=0 core=0
#00 pc 0000dab0 /system/lib/libc.so (epoll_wait+12)
#01 pc 00014791 /system/lib/libutils.so (android::Looper::pollInner(int)+96)
#02 pc 000149f9 /system/lib/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+104)
#03 pc 0005b3b3 /system/lib/libandroid_runtime.so (android::NativeMessageQueue::pollOnce(_JNIEnv*, int)+22)
#04 pc 0001de30 /system/lib/libdvm.so (dvmPlatformInvoke+112)
#05 pc 0004d083 /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+394)
#06 pc 00000214 /dev/ashmem/dalvik-jit-code-cache (deleted)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:125)
at android.os.Looper.loop(Looper.java:124)
at android.webkit.WebSyncManager.run(WebSyncManager.java:92)
at android.webkit.CookieSyncManager.run(CookieSyncManager.java:58)
at java.lang.Thread.run(Thread.java:856)

"WebViewCoreThread" prio=5 tid=13 SUSPENDED
| group="main" sCount=1 dsCount=0 obj=0x42584d78 self=0x41b03a68
| sysTid=9084 nice=0 sched=0/0 cgrp=apps handle=1103257784
| schedstat=( 0 0 0 ) utm=14380 stm=645 core=0
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:125)
at android.os.Looper.loop(Looper.java:124)
at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:827)
at java.lang.Thread.run(Thread.java:856)

"SoundPoolThread" prio=5 tid=12 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x42591b78 self=0x41a68a88
| sysTid=9082 nice=0 sched=0/0 cgrp=apps handle=1545786216
| schedstat=( 0 0 0 ) utm=0 stm=0 core=0
#00 pc 0000dce0 /system/lib/libc.so (__futex_syscall3+8)
#01 pc 00012ea4 /system/lib/libc.so (__pthread_cond_timedwait_relative+48)
#02 pc 00012f00 /system/lib/libc.so (__pthread_cond_timedwait+60)
#03 pc 00050df1 /system/lib/libmedia.so (android::SoundPoolThread::read()+16)
#04 pc 00050fa1 /system/lib/libmedia.so (android::SoundPoolThread::run()+12)
#05 pc 00044b53 /system/lib/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+66)
#06 pc 00010aad /system/lib/libutils.so
#07 pc 00012e60 /system/lib/libc.so (__thread_entry+48)
#08 pc 000125b8 /system/lib/libc.so (pthread_create+172)
at dalvik.system.NativeStart.run(Native Method)

"SoundPool" prio=5 tid=11 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x425943e8 self=0x5c9f17c8
| sysTid=9081 nice=0 sched=0/0 cgrp=apps handle=1073884736
| schedstat=( 0 0 0 ) utm=0 stm=0 core=0
#00 pc 0000dce0 /system/lib/libc.so (__futex_syscall3+8)
#01 pc 00012ea4 /system/lib/libc.so (__pthread_cond_timedwait_relative+48)
#02 pc 00012f00 /system/lib/libc.so (__pthread_cond_timedwait+60)
#03 pc 00050b65 /system/lib/libmedia.so (android::SoundPool::run()+22)
#04 pc 00044b53 /system/lib/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+66)
#05 pc 00010aad /system/lib/libutils.so
#06 pc 00012e60 /system/lib/libc.so (__thread_entry+48)
#07 pc 000125b8 /system/lib/libc.so (pthread_create+172)
at dalvik.system.NativeStart.run(Native Method)

"GLThread 134" prio=5 tid=10 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x4259aa88 self=0x41f34a90
| sysTid=9080 nice=0 sched=0/0 cgrp=apps handle=1546811672
| schedstat=( 0 0 0 ) utm=27 stm=21 core=0
#00 pc 0000cbd0 /system/lib/libc.so (__ioctl+8)
#01 pc 00027ea5 /system/lib/libc.so (ioctl+16)
#02 pc 00016bfd /system/lib/libbinder.so (android::IPCThreadState::talkWithDriver(bool)+124)
#03 pc 000170e9 /system/lib/libbinder.so (android::IPCThreadState::waitForResponse(android::Parcel*, int*)+44)
#04 pc 00017303 /system/lib/libbinder.so (android::IPCThreadState::transact(int, unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+114)
#05 pc 00014aa3 /system/lib/libbinder.so (android::BpBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+34)
#06 pc 00041df9 /system/lib/libmedia.so
#07 pc 0003f5eb /system/lib/libmedia.so (android::MediaPlayer::start()+78)
#08 pc 00011a49 /system/lib/libmedia_jni.so
#09 pc 0001de30 /system/lib/libdvm.so (dvmPlatformInvoke+112)
#10 pc 0004d083 /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+394)
#11 pc 00027260 /system/lib/libdvm.so
#12 pc 0002bb68 /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+180)
#13 pc 0005f7f1 /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+272)
#14 pc 00049673 /system/lib/libdvm.so
#15 pc 001be8d3 /data/data/lexu.me.childstudy_lite/lib/libcocos2dcpp.so (_JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...)+20)
#16 pc 0023cb01 /data/data/lexu.me.childstudy_lite/lib/libcocos2dcpp.so (playBackgroundMusicJNI+48)
#17 pc 0023c765 /data/data/lexu.me.childstudy_lite/lib/libcocos2dcpp.so (CocosDenshion::SimpleAudioEngine::playBackgroundMusic(char const*, bool)+16)
#18 pc 0015bd11 /data/data/lexu.me.childstudy_lite/lib/libcocos2dcpp.so (mMusic::musicLoop()+96)
#19 pc 0015bb35 /data/data/lexu.me.childstudy_lite/lib/libcocos2dcpp.so (HelloWorld::init()+9796)
at android.media.MediaPlayer._start(Native Method)
at android.media.MediaPlayer.start(MediaPlayer.java:1025)
at org.cocos2dx.lib.Cocos2dxMusic.playBackgroundMusic(Cocos2dxMusic.java:120)
at org.cocos2dx.lib.Cocos2dxHelper.playBackgroundMusic(Cocos2dxHelper.java:137)
at org.cocos2dx.lib.Cocos2dxRenderer.nativeInit(Native Method)
at org.cocos2dx.lib.Cocos2dxRenderer.onSurfaceCreated(Cocos2dxRenderer.java:72)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1494)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
第一个场景很大,所以我只发布了初始化

CCScene* HelloWorld::scene(){
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::create();

    // 'layer' is an autorelease object
    HelloWorld *layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init(){
    if ( !CCLayer::init() ){
        return false;
    }

    visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    //Creating menu,


    CCLayerGradient* layer1 = CCLayerGradient::create(ccc4(177, 208, 220, 255), ccc4(49, 121, 239, 255));
    layer1->setContentSize(CCSizeMake(visibleSize.width, visibleSize.height));
    layer1->setPosition(ccp(0,0));
    addChild(layer1);
    CCLayerColor *layerSea = CCLayerColor::create(ccc4(34, 88, 131,255), visibleSize.width, (int) (visibleSize.height*0.15));
    layerSea->setPosition(ccp(0, 0));
    addChild(layerSea);

    //солнце

    CCSprite* pSun = CCSprite::create("main_sun.png");
    pSun->setPosition(ccp(visibleSize.width-pSun->boundingBox().size.width, visibleSize.height-pSun->boundingBox().size.height));

    for (int i = 0; i<12; i++) {
        CCSprite* pSun1 = CCSprite::create(arc4random()%2 == 0?"main_sun_1.png":"main_sun_2.png");
        pSun1->setPosition(pSun->getPosition());
        pSun1->setRotation(arc4random()%360);
        pSun1->setOpacity(arc4random()%150+100);
        CCTargetedAction *t1 = CCTargetedAction::create(pSun1, CCRotateBy::create(arc4random()%10+10, arc4random()%2 == 0?360:-360));
        CCActionInterval* seq1 = CCSequence::create(CCScaleTo::create(1, 0.7),
                                                    CCScaleTo::create(1, 1),
                                                    NULL);
        CCSpawn * act1 = CCSpawn::createWithTwoActions(seq1, t1);
        this->addChild(pSun1, 0);
        pSun1->runAction(CCRepeatForever::create(act1));
    }
    this->addChild(pSun, 0);

    CCSprite* pSprite = CCSprite::create("main_cloud_1.png");

    // position the sprite on the center of the screen
    int randNum = (arc4random() % (int)(visibleSize.height - visibleSize.height*0.5)) + (int)visibleSize.height*0.5;
    //облако 1
    pSprite->setPosition(ccp((arc4random() % (int)(visibleSize.width - visibleSize.width*0.5)), randNum));
    CCActionInterval*  actionTo = CCMoveTo::create((arc4random() % 11) + 5, ccp(visibleSize.width+pSprite->boundingBox().size.width, randNum));
    CCActionInterval*  actionfrom = CCMoveTo::create(0, ccp(-pSprite->boundingBox().size.width, randNum));
    CCAction*  action2 = CCRepeatForever::create(CCSequence::create((CCActionInterval*)(actionTo->copy()->autorelease()), actionfrom, NULL));
    this->addChild(pSprite, 0);
    pSprite->runAction(action2);

    //облако 2
    randNum = (arc4random() % (int)(visibleSize.height - visibleSize.height*0.5)) + (int)visibleSize.height*0.5;
    CCSprite* pSprite2 = CCSprite::create("main_cloud_1.png");
    pSprite2->setPosition(ccp((arc4random() % (int)(visibleSize.width - visibleSize.width*0.5)), randNum));
    actionTo = CCMoveTo::create((arc4random() % 5) + 5, ccp(visibleSize.width+pSprite2->boundingBox().size.width, randNum));
    actionfrom = CCMoveTo::create(0, ccp(-pSprite2->boundingBox().size.width, randNum));
    action2 = CCRepeatForever::create(CCSequence::create((CCActionInterval*)(actionTo->copy()->autorelease()), actionfrom, NULL));
    this->addChild(pSprite2, 0);
    pSprite2->runAction(action2);

    //облако 3
    randNum = (arc4random() % (int)(visibleSize.height - visibleSize.height*0.5)) + (int)visibleSize.height*0.5;
    CCSprite* pSprite3 = CCSprite::create("main_cloud_1.png");
    pSprite3->setPosition(ccp((arc4random() % (int)(visibleSize.width - visibleSize.width*0.5)), randNum));
    actionTo = CCMoveTo::create((arc4random() % 16) + 5, ccp(visibleSize.width+pSprite3->boundingBox().size.width, randNum));
    actionfrom = CCMoveTo::create(0, ccp(-pSprite3->boundingBox().size.width, randNum));
    action2 = CCRepeatForever::create(CCSequence::create((CCActionInterval*)(actionTo->copy()->autorelease()), actionfrom, NULL));
    this->addChild(pSprite3, 0);
    pSprite3->runAction(action2);

    //облако 4
    randNum = (arc4random() % (int)(visibleSize.height - visibleSize.height*0.5)) + (int)visibleSize.height*0.5;
    CCSprite* pSprite4 = CCSprite::create("main_cloud_2.png");
    pSprite4->setPosition(ccp((arc4random() % (int)(visibleSize.width - visibleSize.width*0.5)), randNum));
    actionTo = CCMoveTo::create((arc4random() % 15) + 5, ccp(visibleSize.width+pSprite4->boundingBox().size.width, randNum));
    actionfrom = CCMoveTo::create(0, ccp(-pSprite4->boundingBox().size.width, randNum));
    action2 = CCRepeatForever::create(CCSequence::create((CCActionInterval*)(actionTo->copy()->autorelease()), actionfrom, NULL));
    this->addChild(pSprite4, 0);
    pSprite4->runAction(action2);

    //облако 5
    randNum = (arc4random() % (int)(visibleSize.height - visibleSize.height*0.5)) + (int)visibleSize.height*0.5;
    CCSprite* pSprite5 = CCSprite::create("main_cloud_2.png");
    pSprite5->setPosition(ccp((arc4random() % (int)(visibleSize.width - visibleSize.width*0.5)), randNum));
    actionTo = CCMoveTo::create((arc4random() % 15) + 5, ccp(visibleSize.width+pSprite5->boundingBox().size.width, randNum));
    actionfrom = CCMoveTo::create(0, ccp(-pSprite5->boundingBox().size.width, randNum));
    action2 = CCRepeatForever::create(CCSequence::create((CCActionInterval*)(actionTo->copy()->autorelease()), actionfrom, NULL));
    this->addChild(pSprite5, 0);
    pSprite5->runAction(action2);

    //трава
    CCSprite* pGrass = CCSprite::create("main_grass.png");
    pGrass->setPosition(ccp(visibleSize.width-pGrass->boundingBox().size.width/2, pGrass->boundingBox().size.height/2));
    addChild(pGrass);

    //корабль
    CCSprite* pShip = CCSprite::create("main_ship.png");
    pShip->setPosition(ccp(pShip->boundingBox().size.width/2, pShip->boundingBox().size.height/2));
    CCAction*  actionRotShip = CCRepeatForever::create(CCSequence::create(CCRotateBy::create(2, 5), CCRotateBy::create(2, -5), NULL));
    this->addChild(pShip, 0);
    pShip->runAction(actionRotShip);

    //дерево
    CCSprite* ptrees = CCSprite::create("main_trees.png");
    ptrees->setAnchorPoint(ccp(0, 0));
    ptrees->setPosition(ccp(visibleSize.width-ptrees->boundingBox().size.width, 0));
    //продолжение после ежа

    //ЁЖ
    CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("main_ej.png");

    int frameWidth = (int) texture->getContentSizeInPixels().width/2;
    int frameHeight = (int) texture->getContentSizeInPixels().height/2;
    // manually add frames to the frame cache
    CCSpriteFrame *frame0 = CCSpriteFrame::createWithTexture(texture, CCRectMake(frameWidth*0, frameHeight*0, frameWidth, frameHeight));
    CCSpriteFrame *frame1 = CCSpriteFrame::createWithTexture(texture, CCRectMake(frameWidth*1, frameHeight*0, frameWidth, frameHeight));
    CCSpriteFrame *frame2 = CCSpriteFrame::createWithTexture(texture, CCRectMake(frameWidth*0, frameHeight*1, frameWidth, frameHeight));
    CCSpriteFrame *frame3 = CCSpriteFrame::createWithTexture(texture, CCRectMake(frameWidth*1, frameHeight*1, frameWidth, frameHeight));

    CCSprite* pEj = CCSprite::createWithSpriteFrame(frame0);
    pEj->setPosition( ccp( ptrees->getPositionX(), pEj->boundingBox().size.height/2) );
    addChild(pEj);

    CCArray* animFrames = CCArray::createWithCapacity(6);
    animFrames->addObject(frame0);
    animFrames->addObject(frame1);
    animFrames->addObject(frame2);
    animFrames->addObject(frame3);

    CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.7f);
    CCAnimate *animate = CCAnimate::create(animation);
    pEj->runAction(CCRepeatForever::create( animate ) );
    //конец ежа

    //продолжение дерева
    addChild(ptrees);
    actionTo = CCSkewTo::create(2, 5, 0);
    CCActionInterval *actionToBack = CCSkewTo::create(2, 0, 0);
    ptrees->runAction(CCRepeatForever::create(CCSequence::create(actionTo, actionToBack, NULL)));

    //ласточка
    CCSprite* pBird1 = CCSprite::create("main_bird_1.png");
    pBird1->setPosition(ccp(-pBird1->boundingBox().size.width, visibleSize.height/2));
    addChild(pBird1);

    animation = CCAnimation::create();
    // load image file from local file system to CCSpriteFrame, then add into CCAnimation
    for (int i = 0; i <= 2; i++){
        char szImageFileName[128] = {0};
        sprintf(szImageFileName, "main_bird_%d.png", i);
        animation->addSpriteFrameWithFileName(szImageFileName);
    }

    animation->setDelayPerUnit(1.0f / 3.0f); // This animation contains 14 frames, will continuous 2.8 seconds.
    animation->setRestoreOriginalFrame(true); // Return to the 1st frame after the 14th frame is played.

    CCAnimate *action = CCAnimate::create(animation);
    pBird1->runAction(CCRepeatForever::create(action));  // run action on sprite object

    // sprite 1
    ccBezierConfig bezier;
    bezier.controlPoint_1 = ccp(0, visibleSize.height/2);
    bezier.controlPoint_2 = ccp(300, -visibleSize.height/2);
    bezier.endPosition = ccp(visibleSize.width+pBird1->boundingBox().size.width*4, 0);

    CCActionInterval*  bezierForward = CCBezierBy::create(7, bezier);
    CCActionInterval*  bezierBack = bezierForward->reverse();
    CCAction*  rep = CCRepeatForever::create(CCSequence::create( bezierForward, CCFlipX::create(true), bezierBack, CCFlipX::create(false), NULL));

    pBird1->runAction(rep);

    actionToShow = CCMoveTo::create(1, CCPointZero);
    actionToHideNums = CCMoveTo::create(1, ccp(0, visibleSize.height));
    actionToHideMenu = CCMoveTo::create(1, ccp(0, -visibleSize.height));
    actionToShow->retain();
    actionToHideNums->retain();
    actionToHideMenu->retain();

    CCDirector::sharedDirector()->getScheduler()->scheduleSelector(schedule_selector(HelloWorld::playEffect),this,2.0f,true);
    HelloWorld::playEffect();

    mMusic::sharedManager()->musicLoop();

    return true;
}
CCScene*HelloWorld::scene(){
//“场景”是一个自动释放对象
CCScene*scene=ccscscene::create();
//“层”是一个自动释放对象
HelloWorld*layer=HelloWorld::create();
//将层作为子层添加到场景中
场景->添加子对象(层);
//返回现场
返回场景;
}
//在“init”中,您需要初始化实例
bool HelloWorld::init(){
如果(!CCLayer::init()){
返回false;
}
visibleSize=CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin=CCDirector::sharedDirector()->getVisibleOrigin();
//创建菜单,
CCLayerGradient*layer1=CCLayerGradient::create(ccc4(177208 220 255)、ccc4(49121 239255));
layer1->setContentSize(CCSizeMake(visibleSize.width,visibleSize.height));
第1层->设置位置(ccp(0,0));
addChild(第1层);
CCLayerColor*layerSea=CCLayerColor::create(ccc4(34,88131255),visibleSize.width,(int)(visibleSize.height*0.15));
layerSea->设置位置(ccp(0,0));
addChild(layerSea);
//солнце
CCSprite*pSun=CCSprite::create(“main_sun.png”);
pSun->setPosition(ccp(visibleSize.width pSun->boundingBox().size.width,visibleSize.height pSun->boundingBox().size.height));
对于(inti=0;isetPosition(pSun->getPosition());
pSun1->setRotation(arc4random()%360);
pSun1->setOpacity(arc4random()%150+100);
CCTargetedAction*t1=CCTargetedAction::create(PSUNI,CCRotateBy::create(arc4random()%10+10,arc4random()%2==0?360:-360));
CCActionInterval*seq1=CCSequence::create(CCScaleTo::create(1,0.7),
CCScaleTo::创建(1,1),
无效);
CCSpawn*act1=CCSpawn::createWithTwoActions(seq1,t1);
此->添加子对象(pSun1,0);
pSun1->runAction(CCRepeatForever::create(act1));
}
此->添加子对象(pSun,0);
CCSprite*pSprite=CCSprite::create(“main_cloud_1.png”);
//将精灵放置在屏幕中央
int randNum=(arc4random()%(int)(visibleSize.height-visibleSize.height*0.5))+(int)visibleSize.height*0.5;
//облако 1
pSprite->setPosition(ccp((arc4random()%(int)(visibleSize.width-visibleSize.width*0.5)),randNum));
CCActionInterval*actionTo=CCMoveTo::create((arc4random()%11)+5,ccp(visibleSize.width+pSprite->boundingBox().size.width,randNum));
CCActionInterval*actionfrom=CCMoveTo::create(0,ccp(-pSprite->boundingBox().size.width,randNum));
CCAction*action2=CCRepeatForever::create(CCSequence::create((CCActionInterval*)(actionTo->copy()->autorelease()),actionfrom,NULL));
此->添加子项(pSprite,0);
pSprite->runAction(action2);
//облако 2
randNum=(arc4random()%(int)(visibleSize.height-visibleSize.height*0.5))+(int)visibleSize.height*0.5;
CCSprite*pSprite2=CCSprite::create(“main_cloud_1.png”);
pSprite2->setPosition(ccp((arc4random()%(int)(visibleSize.width-visibleSize.width*0.5)),randNum));
actionTo=CCMoveTo::create((arc4random()%5)+5,ccp(visibleSize.width+pSprite2->boundingBox().size.width,randNum));
actionfrom=CCMoveTo::create(0,ccp(-pSprite2->boundingBox().size.width,randNum));
action2=CCRepeatForever::create(CCSequence::create((CCActionInterval*)(actionTo->copy()->autorelease()),actionfrom,NULL));
此->添加子项(pSprite2,0);
pSprite2->runAction(action2);
//облако 3
randNum=(arc4random()%(int)(visibleSize.height-visibleSize.height*0.5))+(int)visibleSize.height*0.5;
CCSprite*pSprite3=CCSprite::create(“main_cloud_1.png”);
pSprite3->setPosition(ccp((arc4random()%(int)(visibleSize.width-visibleSize.width*0.5)),randNum));
actionTo=CCMoveTo::create((arc4random()%16)+5,ccp(visibleSize.width+pSprite3->boundingBox().size.width,randNum));
actionfrom=CCMoveTo::create(0,ccp(-pSprite3->boundingBox().size.width,randNum));
action2=CCRepeatForever::create(CCSequence::create((CCActionInterval*)(actionTo->copy()->autorelease()),actionfrom,NULL));
此->添加子项(pSprite3,0);
pSprite3->runAction(action2);
//облако 4
randNum=(arc4random()%(int)(visibleSize.height-visibleSize.height*0.5))+(int)visibleSize.height*0.5;
CCSprite*pSprite4=CCSprite::create(“main_cloud_2.png”);
pSprite4->setPosition(ccp((arc4random()%(int)(visibleSize.width-visibleSize.width*0.5)),randNum));
actionTo=CCMoveTo::create((arc4random()%15)+5,ccp(visibleSize.width+pSprite4->boundingBox().size.width,randNum));
actionfrom=CCMoveTo::create(0,ccp(-pSprite4->boundingBox().size.width,randNum));
action2=CCRepeatForever::create(CCSequence::create((CCActionInterval*)(actionTo->copy()->autorelease()),actionfrom,NULL));
此->添加子项(pSprite4,0);
pSprite4->runAction(action2);
//облако 5
randNum=(arc4random()%(int)(visibleSize.height-visibleSize.height*0.5))+(int)visibleSize.height*0.5;
CCSprite*pSprite5=CCSprite::create(“main_cloud_2.png”);
pSprite5->setPosition(ccp((arc4random()%(int)(visibleSize.width-visibleSize.width*0.5)),randNum));
actionTo=CCMoveTo::create((arc4random()%15)+5,ccp(visibleSize.width+pSprite5->boundingBox().size.width,randNum));
actionfrom=CCMoveTo::create(0,ccp(-pSprite5->boundingBox().size.width,randNum));
action2=CCRepeatForever::create(CCSequence::create((CCActionInterval*)(actionTo->copy()->autorelease()),actionfrom,NULL));
此->添加子对象(pSprite5,0);
pSprite5->runAction(action2);
//трава
CCSprite*pGrass=CCSprite::create(“main_grass.png”);
pGrass->setPosition(ccp(visibleSize.width pGrass->boundingBox().size.width/2,pGrass->boundingBox().size.height/2));
addChild(pGr
#include "mMusic.h"
#include "cocos2d.h"
using namespace cocos2d;

mMusic* mMusic::m_mySingleton = NULL;

mMusic::mMusic()
{
    idPlayingMusic= 0;
    isMusWasPlaying  = false;
    mMusic::startMusicPlaying ();
    CocosDenshion::SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.25);
}

mMusic* mMusic::sharedManager()
{
    //If the singleton has no instance yet, create one
    if(NULL == m_mySingleton)
    {
        //Create an instance to the singleton
        m_mySingleton = new mMusic();
    }

    //Return the singleton object
    return m_mySingleton;
}

void mMusic::musicLoop (){
    if (!CCUserDefault::sharedUserDefault()->getBoolForKey("musicPlaying", true)) return; //если музыка не включена - выходим
        switch (idPlayingMusic) {
            case 0:
                CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("kelise.mp3",true);
                isMusWasPlaying=true;
                idPlayingMusic=1;
                break;
            case 1:
                CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("landmann.mp3",true);
                isMusWasPlaying=true;
                idPlayingMusic=2;
                break;
            case 2:
                CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("sonata.mp3",true);
                isMusWasPlaying=true;
                idPlayingMusic=0;
                break;
            default:
                CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("kelise.mp3",true);
                isMusWasPlaying=true;
                idPlayingMusic=1;
                break;
        }
}
void mMusic::stopAllEffects(){
    CocosDenshion::SimpleAudioEngine::sharedEngine()->stopAllEffects();
}
void mMusic::playFinish(){
    if (!CCUserDefault::sharedUserDefault()->getBoolForKey("soundPlaying", true)) return;
    CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("finish.mp3");
}
void mMusic::playOk(){
    if (!CCUserDefault::sharedUserDefault()->getBoolForKey("soundPlaying", true)) return;
    CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("ok.mp3");
}
bool mMusic::isMusicPlaying (){
    return CocosDenshion::SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying();
}
void mMusic::startMusicPlaying (){
    if (!CCUserDefault::sharedUserDefault()->getBoolForKey("musicPlaying", true)) return; //если музыка не включена - выходим
    if (!isMusWasPlaying){
        CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("kelise.mp3",true);
        isMusWasPlaying=true;
    }else{
        CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
    }
}
void mMusic::stopMusicPlaying (){
    CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}
CCScene* HelloWorld::scene(){
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::create();

    // 'layer' is an autorelease object
    HelloWorld *layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init(){
    if ( !CCLayer::init() ){
        return false;
    }

    visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    //Creating menu,


    CCLayerGradient* layer1 = CCLayerGradient::create(ccc4(177, 208, 220, 255), ccc4(49, 121, 239, 255));
    layer1->setContentSize(CCSizeMake(visibleSize.width, visibleSize.height));
    layer1->setPosition(ccp(0,0));
    addChild(layer1);
    CCLayerColor *layerSea = CCLayerColor::create(ccc4(34, 88, 131,255), visibleSize.width, (int) (visibleSize.height*0.15));
    layerSea->setPosition(ccp(0, 0));
    addChild(layerSea);

    //солнце

    CCSprite* pSun = CCSprite::create("main_sun.png");
    pSun->setPosition(ccp(visibleSize.width-pSun->boundingBox().size.width, visibleSize.height-pSun->boundingBox().size.height));

    for (int i = 0; i<12; i++) {
        CCSprite* pSun1 = CCSprite::create(arc4random()%2 == 0?"main_sun_1.png":"main_sun_2.png");
        pSun1->setPosition(pSun->getPosition());
        pSun1->setRotation(arc4random()%360);
        pSun1->setOpacity(arc4random()%150+100);
        CCTargetedAction *t1 = CCTargetedAction::create(pSun1, CCRotateBy::create(arc4random()%10+10, arc4random()%2 == 0?360:-360));
        CCActionInterval* seq1 = CCSequence::create(CCScaleTo::create(1, 0.7),
                                                    CCScaleTo::create(1, 1),
                                                    NULL);
        CCSpawn * act1 = CCSpawn::createWithTwoActions(seq1, t1);
        this->addChild(pSun1, 0);
        pSun1->runAction(CCRepeatForever::create(act1));
    }
    this->addChild(pSun, 0);

    CCSprite* pSprite = CCSprite::create("main_cloud_1.png");

    // position the sprite on the center of the screen
    int randNum = (arc4random() % (int)(visibleSize.height - visibleSize.height*0.5)) + (int)visibleSize.height*0.5;
    //облако 1
    pSprite->setPosition(ccp((arc4random() % (int)(visibleSize.width - visibleSize.width*0.5)), randNum));
    CCActionInterval*  actionTo = CCMoveTo::create((arc4random() % 11) + 5, ccp(visibleSize.width+pSprite->boundingBox().size.width, randNum));
    CCActionInterval*  actionfrom = CCMoveTo::create(0, ccp(-pSprite->boundingBox().size.width, randNum));
    CCAction*  action2 = CCRepeatForever::create(CCSequence::create((CCActionInterval*)(actionTo->copy()->autorelease()), actionfrom, NULL));
    this->addChild(pSprite, 0);
    pSprite->runAction(action2);

    //облако 2
    randNum = (arc4random() % (int)(visibleSize.height - visibleSize.height*0.5)) + (int)visibleSize.height*0.5;
    CCSprite* pSprite2 = CCSprite::create("main_cloud_1.png");
    pSprite2->setPosition(ccp((arc4random() % (int)(visibleSize.width - visibleSize.width*0.5)), randNum));
    actionTo = CCMoveTo::create((arc4random() % 5) + 5, ccp(visibleSize.width+pSprite2->boundingBox().size.width, randNum));
    actionfrom = CCMoveTo::create(0, ccp(-pSprite2->boundingBox().size.width, randNum));
    action2 = CCRepeatForever::create(CCSequence::create((CCActionInterval*)(actionTo->copy()->autorelease()), actionfrom, NULL));
    this->addChild(pSprite2, 0);
    pSprite2->runAction(action2);

    //облако 3
    randNum = (arc4random() % (int)(visibleSize.height - visibleSize.height*0.5)) + (int)visibleSize.height*0.5;
    CCSprite* pSprite3 = CCSprite::create("main_cloud_1.png");
    pSprite3->setPosition(ccp((arc4random() % (int)(visibleSize.width - visibleSize.width*0.5)), randNum));
    actionTo = CCMoveTo::create((arc4random() % 16) + 5, ccp(visibleSize.width+pSprite3->boundingBox().size.width, randNum));
    actionfrom = CCMoveTo::create(0, ccp(-pSprite3->boundingBox().size.width, randNum));
    action2 = CCRepeatForever::create(CCSequence::create((CCActionInterval*)(actionTo->copy()->autorelease()), actionfrom, NULL));
    this->addChild(pSprite3, 0);
    pSprite3->runAction(action2);

    //облако 4
    randNum = (arc4random() % (int)(visibleSize.height - visibleSize.height*0.5)) + (int)visibleSize.height*0.5;
    CCSprite* pSprite4 = CCSprite::create("main_cloud_2.png");
    pSprite4->setPosition(ccp((arc4random() % (int)(visibleSize.width - visibleSize.width*0.5)), randNum));
    actionTo = CCMoveTo::create((arc4random() % 15) + 5, ccp(visibleSize.width+pSprite4->boundingBox().size.width, randNum));
    actionfrom = CCMoveTo::create(0, ccp(-pSprite4->boundingBox().size.width, randNum));
    action2 = CCRepeatForever::create(CCSequence::create((CCActionInterval*)(actionTo->copy()->autorelease()), actionfrom, NULL));
    this->addChild(pSprite4, 0);
    pSprite4->runAction(action2);

    //облако 5
    randNum = (arc4random() % (int)(visibleSize.height - visibleSize.height*0.5)) + (int)visibleSize.height*0.5;
    CCSprite* pSprite5 = CCSprite::create("main_cloud_2.png");
    pSprite5->setPosition(ccp((arc4random() % (int)(visibleSize.width - visibleSize.width*0.5)), randNum));
    actionTo = CCMoveTo::create((arc4random() % 15) + 5, ccp(visibleSize.width+pSprite5->boundingBox().size.width, randNum));
    actionfrom = CCMoveTo::create(0, ccp(-pSprite5->boundingBox().size.width, randNum));
    action2 = CCRepeatForever::create(CCSequence::create((CCActionInterval*)(actionTo->copy()->autorelease()), actionfrom, NULL));
    this->addChild(pSprite5, 0);
    pSprite5->runAction(action2);

    //трава
    CCSprite* pGrass = CCSprite::create("main_grass.png");
    pGrass->setPosition(ccp(visibleSize.width-pGrass->boundingBox().size.width/2, pGrass->boundingBox().size.height/2));
    addChild(pGrass);

    //корабль
    CCSprite* pShip = CCSprite::create("main_ship.png");
    pShip->setPosition(ccp(pShip->boundingBox().size.width/2, pShip->boundingBox().size.height/2));
    CCAction*  actionRotShip = CCRepeatForever::create(CCSequence::create(CCRotateBy::create(2, 5), CCRotateBy::create(2, -5), NULL));
    this->addChild(pShip, 0);
    pShip->runAction(actionRotShip);

    //дерево
    CCSprite* ptrees = CCSprite::create("main_trees.png");
    ptrees->setAnchorPoint(ccp(0, 0));
    ptrees->setPosition(ccp(visibleSize.width-ptrees->boundingBox().size.width, 0));
    //продолжение после ежа

    //ЁЖ
    CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("main_ej.png");

    int frameWidth = (int) texture->getContentSizeInPixels().width/2;
    int frameHeight = (int) texture->getContentSizeInPixels().height/2;
    // manually add frames to the frame cache
    CCSpriteFrame *frame0 = CCSpriteFrame::createWithTexture(texture, CCRectMake(frameWidth*0, frameHeight*0, frameWidth, frameHeight));
    CCSpriteFrame *frame1 = CCSpriteFrame::createWithTexture(texture, CCRectMake(frameWidth*1, frameHeight*0, frameWidth, frameHeight));
    CCSpriteFrame *frame2 = CCSpriteFrame::createWithTexture(texture, CCRectMake(frameWidth*0, frameHeight*1, frameWidth, frameHeight));
    CCSpriteFrame *frame3 = CCSpriteFrame::createWithTexture(texture, CCRectMake(frameWidth*1, frameHeight*1, frameWidth, frameHeight));

    CCSprite* pEj = CCSprite::createWithSpriteFrame(frame0);
    pEj->setPosition( ccp( ptrees->getPositionX(), pEj->boundingBox().size.height/2) );
    addChild(pEj);

    CCArray* animFrames = CCArray::createWithCapacity(6);
    animFrames->addObject(frame0);
    animFrames->addObject(frame1);
    animFrames->addObject(frame2);
    animFrames->addObject(frame3);

    CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.7f);
    CCAnimate *animate = CCAnimate::create(animation);
    pEj->runAction(CCRepeatForever::create( animate ) );
    //конец ежа

    //продолжение дерева
    addChild(ptrees);
    actionTo = CCSkewTo::create(2, 5, 0);
    CCActionInterval *actionToBack = CCSkewTo::create(2, 0, 0);
    ptrees->runAction(CCRepeatForever::create(CCSequence::create(actionTo, actionToBack, NULL)));

    //ласточка
    CCSprite* pBird1 = CCSprite::create("main_bird_1.png");
    pBird1->setPosition(ccp(-pBird1->boundingBox().size.width, visibleSize.height/2));
    addChild(pBird1);

    animation = CCAnimation::create();
    // load image file from local file system to CCSpriteFrame, then add into CCAnimation
    for (int i = 0; i <= 2; i++){
        char szImageFileName[128] = {0};
        sprintf(szImageFileName, "main_bird_%d.png", i);
        animation->addSpriteFrameWithFileName(szImageFileName);
    }

    animation->setDelayPerUnit(1.0f / 3.0f); // This animation contains 14 frames, will continuous 2.8 seconds.
    animation->setRestoreOriginalFrame(true); // Return to the 1st frame after the 14th frame is played.

    CCAnimate *action = CCAnimate::create(animation);
    pBird1->runAction(CCRepeatForever::create(action));  // run action on sprite object

    // sprite 1
    ccBezierConfig bezier;
    bezier.controlPoint_1 = ccp(0, visibleSize.height/2);
    bezier.controlPoint_2 = ccp(300, -visibleSize.height/2);
    bezier.endPosition = ccp(visibleSize.width+pBird1->boundingBox().size.width*4, 0);

    CCActionInterval*  bezierForward = CCBezierBy::create(7, bezier);
    CCActionInterval*  bezierBack = bezierForward->reverse();
    CCAction*  rep = CCRepeatForever::create(CCSequence::create( bezierForward, CCFlipX::create(true), bezierBack, CCFlipX::create(false), NULL));

    pBird1->runAction(rep);

    actionToShow = CCMoveTo::create(1, CCPointZero);
    actionToHideNums = CCMoveTo::create(1, ccp(0, visibleSize.height));
    actionToHideMenu = CCMoveTo::create(1, ccp(0, -visibleSize.height));
    actionToShow->retain();
    actionToHideNums->retain();
    actionToHideMenu->retain();

    CCDirector::sharedDirector()->getScheduler()->scheduleSelector(schedule_selector(HelloWorld::playEffect),this,2.0f,true);
    HelloWorld::playEffect();

    mMusic::sharedManager()->musicLoop();

    return true;
}