【史上最坑爹的游戏】001 游戏介绍及开始页面的实现

本文介绍如何实现史上最坑爹的游戏的开始界面。首先,文章提及这款游戏的流行趋势,鼓励未玩过的读者尝试。接着,详细阐述了开始界面的设计,包括展示了开始界面的截图,并提及该界面由HelloWorldScene.h和HelloWorldScene.cpp两个文件实现。
摘要由CSDN通过智能技术生成

最近史上最坑爹的游戏挺风靡的,而且又更新了2,本系列文章将来一步步把这个游戏做出来。


1. 游戏介绍


相信很多人都玩过这款游戏,如果你没玩过的话,建议你下载一个试试,那么学习此系列文章,你将更有feeling。

废话不多说,上图你就明白了:










2. 开始界面的实现


游戏的开始界面如下:




开始界面有HelloWorldScene.h和HelloWorldScene.cpp实现。

HelloWorldScene.h中的代码如下:

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
class HelloWorld : public cocos2d::Layer
{
public:
    // there's no 'id' in cpp, so we recommend returning the class instance pointer
    static cocos2d::Scene* createScene();
    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    virtual bool init();  

    // a selector callback
    void menuCloseCallback(Object* pSender);

    // implement the "static create()" method manually
    CREATE_FUNC(HelloWorld);
};
#endif // __HELLOWORLD_SCENE_H__

HelloWorldScene.cpp的代码如下:

#include "HelloWorldScene.h"
#include "ScrollViewScene.h"

USING_NS_CC;

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

    // 'layer' is an autorelease object
    auto 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()
{
    //
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }

    //Size visibleSize = Director::getInstance()->getVisibleSize();
    //Point origin = Director::getInstance()->getVisibleOrigin();
    /
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.


    //加入背景
    Size size = CCDirector::getInstance()->getWinSize();
    SpriteFrameCache *cache = SpriteFrameCache::getInstance();
    cache->addSpriteFramesWithFile("UIResoure.plist");

    Sprite* sprite =Sprite::createWithSpriteFrameName("start-bg.png");
    sprite->setPosition(Point(size.width*0.5+100,size.height*0.5));
    addChild(sprite);



    // 3.0的新实现方式
    // add a "close" icon to exit the progress. it's an autorelease object
//    auto closeItem = MenuItemImage::create(
//                                           "UIResoure_play.png",
//                                           "UIResoure_plays.png",
//                                           CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
//    closeItem->setPosition(Point(size.width*0.5,size.height*0.5-100));
//
//    // create menu, it's an autorelease object
//    auto menu = Menu::create(closeItem, NULL);
//    menu->setPosition(Point::ZERO);
//    this->addChild(menu, 1);

    //2.2的实现方式
    MenuItemImage *closeItem = MenuItemImage::create();
    closeItem->setNormalSpriteFrame(cache->spriteFrameByName("play-1.png"));
    closeItem->setSelectedSpriteFrame(cache->spriteFrameByName("play-2.png"));
    closeItem->initWithTarget(this, menu_selector(HelloWorld::menuCloseCallback));
    closeItem->setPosition(Point(size.width*0.5,size.height*0.5-100));
    auto menu = Menu::create(closeItem, NULL);
    menu->setPosition(Point::ZERO);
    this->addChild(menu, 1);

    return true;
}

void HelloWorld::menuCloseCallback(Object* pSender)
{
    //Director::getInstance()->end();
    //实现
    CCDirector::getInstance()->replaceScene(CCTransitionFade::create(0.5, ScrollViewScene::create()));

    //释放没有用到过的缓冲
    //CCTextureCache::sharedTextureCache()->removeUnusedTextures();
}

这样的话,我们就把游戏的开始界面做好了。







1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看REaDME.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值