cocos2d-x 场景无法切换

AppDelegate.cpp

/****************************************************************************
 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
 
 http://www.cocos2d-x.org
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/

#include "AppDelegate.h"
#include <proj.win32/PlayScene.h>
#include <proj.win32/GameInitialScene.h>

// #define USE_AUDIO_ENGINE 1
// #define USE_SIMPLE_AUDIO_ENGINE 1

#if USE_AUDIO_ENGINE && USE_SIMPLE_AUDIO_ENGINE
#error "Don't use AudioEngine and SimpleAudioEngine at the same time. Please just select one in your game!"
#endif

#if USE_AUDIO_ENGINE
#include "audio/include/AudioEngine.h"
using namespace cocos2d::experimental;
#elif USE_SIMPLE_AUDIO_ENGINE
#include "audio/include/SimpleAudioEngine.h"
using namespace CocosDenshion;
#endif


USING_NS_CC;

static cocos2d::Size designResolutionSize = cocos2d::Size(480, 320);
static cocos2d::Size smallResolutionSize = cocos2d::Size(480, 320);
static cocos2d::Size mediumResolutionSize = cocos2d::Size(1024, 768);
static cocos2d::Size largeResolutionSize = cocos2d::Size(2048, 1536);

AppDelegate::AppDelegate()
{
}

AppDelegate::~AppDelegate()
{
#if USE_AUDIO_ENGINE
    AudioEngine::end();
#elif USE_SIMPLE_AUDIO_ENGINE
    SimpleAudioEngine::end();
#endif
}

// if you want a different context, modify the value of glContextAttrs
// it will affect all platforms
void AppDelegate::initGLContextAttrs()
{
    // set OpenGL context attributes: red,green,blue,alpha,depth,stencil,multisamplesCount
    GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};

    GLView::setGLContextAttrs(glContextAttrs);
}

// if you want to use the package manager to install more packages,  
// don't modify or remove this function
static int register_all_packages()
{
    return 0; //flag for packages manager
}

bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
        //glview = GLViewImpl::createWithRect("TheImmortal", cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
        glview = GLViewImpl::createWithRect("TheImmortal", cocos2d::Rect(0, 0, 800, 600));
#else
        glview = GLViewImpl::create("TheImmortal");
#endif
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0f / 60);
    // Set the design resolution
    glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
    
    auto frameSize = glview->getFrameSize();
    // if the frame's height is larger than the height of medium size.
    if (frameSize.height > mediumResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
    }
    // if the frame's height is larger than the height of small size.
    else if (frameSize.height > smallResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
    }
    // if the frame's height is smaller than the height of medium size.
    else
    {        
        director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
    }

    register_all_packages();

    // create a scene. it's an autorelease object
    //auto scene = Play::create();
    auto scene = GameInitial::create();
    // run
    director->runWithScene(scene);
   
    return true;
}

// This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
void AppDelegate::applicationDidEnterBackground() {
    Director::getInstance()->stopAnimation();

#if USE_AUDIO_ENGINE
    AudioEngine::pauseAll();
#elif USE_SIMPLE_AUDIO_ENGINE
    SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
    SimpleAudioEngine::getInstance()->pauseAllEffects();
#endif
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
    Director::getInstance()->startAnimation();

#if USE_AUDIO_ENGINE
    AudioEngine::resumeAll();
#elif USE_SIMPLE_AUDIO_ENGINE
    SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
    SimpleAudioEngine::getInstance()->resumeAllEffects();
#endif
}


AppDelegate.h

/****************************************************************************
 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
 
 http://www.cocos2d-x.org
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/

#ifndef  _APP_DELEGATE_H_
#define  _APP_DELEGATE_H_

#include "cocos2d.h"

/**
@brief    The cocos2d Application.

Private inheritance here hides part of interface from Director.
*/
class  AppDelegate : private cocos2d::Application
{
public:
    AppDelegate();
    virtual ~AppDelegate();

    virtual void initGLContextAttrs();

    /**
    @brief    Implement Director and Scene init code here.
    @return true    Initialize success, app continue.
    @return false   Initialize failed, app terminate.
    */
    virtual bool applicationDidFinishLaunching();

    /**
    @brief  Called when the application moves to the background
    @param  the pointer of the application
    */
    virtual void applicationDidEnterBackground();

    /**
    @brief  Called when the application reenters the foreground
    @param  the pointer of the application
    */
    virtual void applicationWillEnterForeground();
};

#endif // _APP_DELEGATE_H_


GameInitialScene.cpp

#include "cocos2d.h"
#include "GameInitialScene.h"
#include <proj.win32/PlayScene.h>
#include "SimpleAudioEngine.h"
#include "ui/CocosGUI.h"
#include "AppDelegate.h"
#include <iostream>
#include <string>

USING_NS_CC;
using namespace cocos2d::ui;

Button* NEWGAME_Button;
Button* LOADGAME_Button;
Button* SETTING_Button;
Button* QUITGAME_Button;
Size NEWGAME_Size;
Size LOADGAME_Size;
Size SETTING_Size;
Size QUITGAME_Size;
Vec2 NEWGAME_Position;
Vec2 LOADGAME_Position;
Vec2 SETTING_Position;
Vec2 QUITGAME_Position;


Scene* GameInitial::createScene()
{
    return GameInitial::create();
}

// Print useful error message instead of segfaulting when files are not there.
static void problemLoading(const char* filename)
{
    printf("Error while loading: %s\n", filename);
    printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in GameInitialScene.cpp\n");
}

bool GameInitial::init()
{
    if (!Scene::init())
    {
        return false;
    }
    auto director = Director::getInstance();
    auto visibleSize = director->getVisibleSize();
    Vec2 origin = director->getVisibleOrigin();
    //NEW GAME
    NEWGAME_Button = Button::create("Button/Button_Normal.png", "Button/Button_Normal_or_Click.png", "Button/Button_Disable.png");
    NEWGAME_Button->setTitleText("NEW GAME");
    NEWGAME_Button->setTitleColor(Color3B::BLACK);
    NEWGAME_Button->addTouchEventListener([&](Ref* sender, Widget::TouchEventType type) {
        Scene* PlayScene = Play::createScene();
        switch (type)
        {
        case ui::Widget::TouchEventType::BEGAN:
            break;
        case ui::Widget::TouchEventType::ENDED:
            director->replaceScene(PlayScene);
            break;
        default:
            break;
        }
    });
    this->addChild(NEWGAME_Button);
    NEWGAME_Button->setPosition(Vec2(100,200));
    //LOAD GAME
    LOADGAME_Button = Button::create("Button/Button_Normal.png", "Button/Button_Normal_or_Click.png", "Button/Button_Disable.png");
    LOADGAME_Button->setTitleText("LOADGAME");
    LOADGAME_Button->setTitleColor(Color3B::BLACK);
    LOADGAME_Button->addTouchEventListener([&](Ref* sender, Widget::TouchEventType type) {
        switch (type)
        {
        case ui::Widget::TouchEventType::BEGAN:
            break;
        case ui::Widget::TouchEventType::ENDED:
            
            break;
        default:
            break;
        }
    });
    this->addChild(LOADGAME_Button);
    LOADGAME_Button->setPosition(Vec2(100,180));
    //SETTING
    SETTING_Button = Button::create("Button/Button_Normal.png", "Button/Button_Normal_or_Click.png", "Button/Button_Disable.png");
    SETTING_Button->setTitleText("SETTING");
    SETTING_Button->setTitleColor(Color3B::BLACK);
    SETTING_Button->addTouchEventListener([&](Ref* sender, Widget::TouchEventType type) {
        switch (type)
        {
        case ui::Widget::TouchEventType::BEGAN:
            break;
        case ui::Widget::TouchEventType::ENDED:
            CCLOG("SETTING Interface");
            break;
        default:
            break;
        }
    });
    this->addChild(SETTING_Button);
    SETTING_Button->setPosition(Vec2(100,160));
    //QUIT GAME
    QUITGAME_Button = Button::create("Button/Button_Normal.png", "Button/Button_Normal_or_Click.png", "Button/Button_Disable.png");
    QUITGAME_Button->setTitleText("QUIT GAME");
    QUITGAME_Button->setTitleColor(Color3B::BLACK);
    QUITGAME_Button->addTouchEventListener([&](Ref* sender, Widget::TouchEventType type) {
        switch (type)
        {
        case ui::Widget::TouchEventType::BEGAN:
            break;
        case ui::Widget::TouchEventType::ENDED:
            director->popScene();
            break;
        default:
            break;
        }
    });
    this->addChild(QUITGAME_Button);
    QUITGAME_Button->setPosition(Vec2(100,140));
    //Mouse
    NEWGAME_Size = NEWGAME_Button->getContentSize();
    LOADGAME_Size = LOADGAME_Button->getContentSize();
    SETTING_Size = SETTING_Button->getContentSize();
    QUITGAME_Size = QUITGAME_Button->getContentSize();
    NEWGAME_Position = NEWGAME_Button->getParent()->convertToWorldSpace(NEWGAME_Button->getPosition());
    LOADGAME_Position = LOADGAME_Button->getParent()->convertToWorldSpace(LOADGAME_Button->getPosition());
    SETTING_Position = SETTING_Button->getParent()->convertToWorldSpace(SETTING_Button->getPosition());
    QUITGAME_Position = QUITGAME_Button->getParent()->convertToWorldSpace(QUITGAME_Button->getPosition());
    auto listener = cocos2d::EventListenerMouse::create();
    listener->onMouseMove = [](cocos2d::Event* event)
    {
        auto const mouseEvent = static_cast<cocos2d::EventMouse*>(event);
        auto const x = mouseEvent->getCursorX();
        auto const y = mouseEvent->getCursorY();
        if (((x >= NEWGAME_Position.x) && (x <= (NEWGAME_Position.x + NEWGAME_Size.width)))
            && ((y >= NEWGAME_Position.y) && (y <= (NEWGAME_Position.y + NEWGAME_Size.height))))
        {
            NEWGAME_Button->loadTextureNormal("Button/Button_Suspension.png");
            CCLOG("NEWGAME_Suspensionl");
        }
        else
        {
            NEWGAME_Button->loadTextureNormal("Button/Button_Normal.png");
            CCLOG("NEWGAME_Normal");
        }
        if (((x >= LOADGAME_Position.x) && (x <= (LOADGAME_Position.x + LOADGAME_Size.width)))
            && ((y >= LOADGAME_Position.y) && (y <= (LOADGAME_Position.y + LOADGAME_Size.height))))
        {
            LOADGAME_Button->loadTextureNormal("Button/Button_Suspension.png");
            CCLOG("LOADGAME_Suspensionl");
        }
        else
        {
            LOADGAME_Button->loadTextureNormal("Button/Button_Normal.png");
            CCLOG("LOADGAME_Normal");
        }
        if (((x >= SETTING_Position.x) && (x <= (SETTING_Position.x + SETTING_Size.width)))
            && ((y >= SETTING_Position.y) && (y <= (SETTING_Position.y + SETTING_Size.height))))
        {
            SETTING_Button->loadTextureNormal("Button/Button_Suspension.png");
            CCLOG("SETTING_Suspension");
        }
        else
        {
            SETTING_Button->loadTextureNormal("Button/Button_Normal.png");
            CCLOG("SETTING_Normal");
        }
        if (((x >= QUITGAME_Position.x) && (x <= (QUITGAME_Position.x + QUITGAME_Size.width)))
            && ((y >= QUITGAME_Position.y) && (y <= (QUITGAME_Position.y + QUITGAME_Size.height))))
        {
            QUITGAME_Button->loadTextureNormal("Button/Button_Suspension.png");
            CCLOG("QUITGAME_Suspension");
        }
        else
        {
            QUITGAME_Button->loadTextureNormal("Button/Button_Normal.png");
            CCLOG("QUITGAME_Normal");
        }
    };
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    return true;
}
void GameInitial::menuCloseCallback(Ref* pSender)
{
    Director::getInstance()->end();
}


GameInitialScene.h

#ifndef __GAMEINITIAL_SCENE_H__
#define __GAMEINITIAL_SCENE_H__

#include "cocos2d.h"

class GameInitial : public cocos2d::Scene
{
public:
    static cocos2d::Scene* createScene();
    virtual bool init();
    // a selector callback
    void menuCloseCallback(cocos2d::Ref* pSender);
    // implement the "static create()" method manually
    CREATE_FUNC(GameInitial);
};

#endif


PlayScene.cpp

/****************************************************************************
 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.

 http://www.cocos2d-x.org

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/

#include "PlayScene.h"
#include "SimpleAudioEngine.h"
#include "cocos2d.h"
#include <string>


USING_NS_CC;
using namespace std;
Sprite* Player;

Scene* Play::createScene()
{
    return Play::create();
}

// Print useful error message instead of segfaulting when files are not there.
static void problemLoading(const char* filename)
{
    printf("Error while loading: %s\n", filename);
    printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in HelloWorldScene.cpp\n");
}

// on "init" you need to initialize your instance
bool Play::init()
{
    //
    // 1. super init first
    if (!Scene::init())
    {
        return false;
    }

    auto visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    /
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    auto closeItem = MenuItemImage::create(
        "CloseNormal.png",
        "CloseSelected.png",
        CC_CALLBACK_1(Play::menuCloseCallback, this));

    if (closeItem == nullptr ||
        closeItem->getContentSize().width <= 0 ||
        closeItem->getContentSize().height <= 0)
    {
        problemLoading("'CloseNormal.png' and 'CloseSelected.png'");
    }
    else
    {
        float x = origin.x + visibleSize.width - closeItem->getContentSize().width / 2;
        float y = origin.y + closeItem->getContentSize().height / 2;
        closeItem->setPosition(Vec2(x, y));
    }

    // create menu, it's an autorelease object
    auto menu = Menu::create(closeItem, NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu, 1);

    /
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label

    /*auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24);
    if (label == nullptr)
    {
        problemLoading("'fonts/Marker Felt.ttf'");
    }
    else
    {
        // position the label on the center of the screen
        label->setPosition(Vec2(origin.x + visibleSize.width/2,
                                origin.y + visibleSize.height - label->getContentSize().height));

        // add the label as a child to this layer
        this->addChild(label, 1);
    }*/
    Player = Sprite::create("PlayerImage/run/0.jpg");
    if (Player == nullptr)
    {
        problemLoading("PlayerImage/run/0.jpg");
    }
    else
    {
        // position the sprite on the center of the screen
        Player->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));
        // add the sprite as a child to this layer
        this->addChild(Player, 0);
    }
    //PlayerImage
    Vector<SpriteFrame*> animFrames;
    auto size = Player->getContentSize();
    animFrames.reserve(4);
    for (int i = 0; i < 10; i++)
    {
        animFrames.pushBack(SpriteFrame::create("PlayerImage/run/" + to_string(i) + ".jpg", Rect(0, 0, size.width, size.height)));
    }
    // create the animation out of the frames
    Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f);
    Animate* animate = Animate::create(animation);
    Player->runAction(RepeatForever::create(animate));
    //keyboard
    auto listener = EventListenerKeyboard::create();
    listener->onKeyPressed = CC_CALLBACK_2(Play::onKeyPressed, this);
    listener->onKeyReleased = CC_CALLBACK_2(Play::onKeyReleased, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    this->scheduleUpdate();
    return true;
}

void Play::menuCloseCallback(Ref* pSender)
{
    //Close the cocos2d-x game scene and quit the application
    Director::getInstance()->end();

    /*To navigate back to native iOS screen(if present) without quitting the application  ,do not use Director::getInstance()->end() as given above,instead trigger a custom event created in RootViewController.mm as below*/

    //EventCustom customEndEvent("game_scene_close_event");
    //_eventDispatcher->dispatchEvent(&customEndEvent);
}

void Play::onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event)
{
    keysPressed[keyCode] = true;
}

void Play::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event)
{
    keysPressed[keyCode] = false;
}
void Play::update(float delta)
{
    const float moveSpeed = 20.0f * delta;
    if (keysPressed[EventKeyboard::KeyCode::KEY_W])
    {
        Player->setPositionY(Player->getPositionY() + moveSpeed);
    }
    if (keysPressed[EventKeyboard::KeyCode::KEY_A])
    {
        Player->setPositionX(Player->getPositionX() - moveSpeed);
    }
    if (keysPressed[EventKeyboard::KeyCode::KEY_S])
    {
        Player->setPositionY(Player->getPositionY() - moveSpeed);
    }
    if (keysPressed[EventKeyboard::KeyCode::KEY_D])
    {
        Player->setPositionX(Player->getPositionX() + moveSpeed);
    }
    if (keysPressed[EventKeyboard::KeyCode::KEY_SPACE])
    {
        Player->runAction(JumpBy::create(0.5f, Vec2(0, 0), moveSpeed, 1));
    }
    if (keysPressed[EventKeyboard::KeyCode::KEY_CAPS_LOCK])
    {
        Player->runAction(JumpBy::create(0.5f, Vec2(0, 0), 100, 1));
    }
}


PlayScene.h
 

/****************************************************************************
 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.

 http://www.cocos2d-x.org

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/

#ifndef __PLAY_SCENE_H__
#define __PLAY_SCENE_H__

#include "cocos2d.h"

class Play : public cocos2d::Scene
{
public:
    static cocos2d::Scene* createScene();

    virtual bool init();


    void onKeyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event);
    virtual void update(float delta);
    void onKeyReleased(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event);

    // a selector callback
    void menuCloseCallback(cocos2d::Ref* pSender);

    // implement the "static create()" method manually
    CREATE_FUNC(Play);
private:
    std::map<cocos2d::EventKeyboard::KeyCode, bool> keysPressed;
};

#endif

报错信息:
按下QUIT GAME后:


控制台输出:

引发了异常: 读取访问权限冲突。
**std::vector<cocos2d::Scene *,std::allocator<cocos2d::Scene *> >::back**(...) 返回 0x8B000002。

线程 0xf84 已退出,返回值为 0 (0x0)。
线程 0x6648 已退出,返回值为 0 (0x0)。
引发了未经处理的异常:读取访问权限冲突。
**std::vector<cocos2d::Scene *,std::allocator<cocos2d::Scene *> >::back**(...) 返回 0x8B000002。

引发了异常: 读取访问权限冲突。
**std::vector<cocos2d::Scene *,std::allocator<cocos2d::Scene *> >::back**(...) 返回 0x8B000002。

引发了未经处理的异常:读取访问权限冲突。
**std::vector<cocos2d::Scene *,std::allocator<cocos2d::Scene *> >::back**(...) 返回 0x8B000002。

程序“[19792] TheImmortal.exe”已退出,返回值为 0 (0x0)。

 按下NEW GAME后:

控制台输出:


引发了异常: 读取访问权限冲突。
this->**_nextScene** 是 0xF4458B08。

引发了未经处理的异常:读取访问权限冲突。
this->**_nextScene** 是 0xF4458B08。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值