先看效果图

界面制作过程

  1. 初始化加载动画:包括初始化背景,初始化标题,初始化进入游戏按钮。
void LoadingGameScene::InitLoadingGameAnimation()
{// 初始化背景InitBackground();// 初始化标题InitTitle();// 初始化进入游戏按钮InitEnterGameButton();
}
  1. 初始化背景图
void LoadingGameScene::InitBackground()
{// 创建背景图片作为一个精灵auto backgroundSprite = Sprite::create("images/loadingGameImages/background.png");// 设置背精灵位置backgroundSprite->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));// 将精灵添加到场景中addChild(backgroundSprite);
}

效果图:

源图:

  1. 初始化标题
    // 标题auto titleSprite = Sprite::create("images/loadingGameImages/title.png");titleSprite->setScaleX(1.25f);auto titleSize = titleSprite->getContentSize();// 动画光auto sparkSprite = Sprite::create("images/loadingGameImages/spark.png");sparkSprite->setPosition(Vec2(-sparkSprite->getContentSize().width, 0));sparkSprite->setScale(2.0f);sparkSprite->runAction(RepeatForever::create(Sequence::create(MoveTo::create(1.0f, Vec2(titleSize.width, 0)), DelayTime::create(2.0f),CallFunc::create([=]() {sparkSprite->setPosition(Vec2(-titleSize.width, 0));}), nullptr)));/* 创建裁剪节点 */auto clippingNode = ClippingNode::create();clippingNode->setPosition(Vec2(visibleSize.width / 2, visibleSize.height + titleSize.height / 2));clippingNode->runAction(MoveTo::create(0.5f, Vec2(visibleSize.width / 2, visibleSize.height - (titleSize.height / 3 * 2))));addChild(clippingNode);clippingNode->setAlphaThreshold(0.01f); clippingNode->setContentSize(titleSize);clippingNode->setStencil(titleSprite);clippingNode->addChild(titleSprite); clippingNode->addChild(sparkSprite);

效果图:

源图:

  1. 初始化进入游戏按钮。
    // 地auto groundSprite = Sprite::create("images/loadingGameImages/ground.png");groundSprite->setScale(2.0f);groundSprite->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 5));addChild(groundSprite);// 草坪auto greenswardSprite = Sprite::create("images/loadingGameImages/greensward.png");greenswardSprite->setScale(2.0f);greenswardSprite->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 5 + groundSprite->getContentSize().height));addChild(greenswardSprite);// 进入游戏按钮auto label = MenuItemLabel::create(Label::createWithTTF(TR("开始游戏"), WENSHUAI_FONT_TTF, 40),CC_CALLBACK_1(LoadingGameScene::BeginGameCallBack, this));label->setColor(Color3B(0, 255, 255));auto action = TintBy::create(0.5f, 0, 255, 255);label->runAction(RepeatForever::create(Sequence::create(action, action->reverse(), nullptr)));label->setEnabled(true);/* 创建菜单 */auto menu = Menu::create(label, nullptr);menu->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 5 - 10));addChild(menu);

效果图:

源图:

源代码

// LoadingGameScene.h
// vs2022 + cocos2dx 4.0
// by: wangjie
#ifndef __LOADING_GAME_SCENE_H__
#define __LOADING_GAME_SCENE_H__
#include "SceneBase.h"
NS_PVZ_BEGIN
class LoadingGameScene : public SceneBase
{
public:CREATE_FUNC(LoadingGameScene);static NS_CC::Scene* createScene();bool init() override;
private:// 初始化 cocos2dx图标void InitCocos2dxLogo();// 初始化加载游戏动画void InitLoadingGameAnimation();// 初始化水印void InitWatermark();// 初始化背景void InitBackground();// 初始化标题void InitTitle();// 初始化进入游戏按钮void InitEnterGameButton();// 运行加载后回调函数void RunLoadingCallBack(NS_CC::Node* node);// 开始游戏回调函数void BeginGameCallBack(NS_CC::Ref* pSender);
private:NS_CC::Size visibleSize;NS_CC::Vec2 origin;
};
NS_PVZ_END
#endif // __LOADING_GAME_SCENE_H__
// LoadingGameScene.cpp
// vs2022 + cocos2dx 4.0
// by: wangjie
#include "LoadingGameScene.h"
#include "HomePageScene.h"
USING_NS_CC;
NS_PVZ_BEGIN
Scene* LoadingGameScene::createScene()
{return LoadingGameScene::create();
}
void LoadingGameScene::InitCocos2dxLogo()
{auto cocos2dxLogoSprite = Sprite::create("images/loadingGameImages/cocos2dx_logo.png");if (cocos2dxLogoSprite != nullptr){cocos2dxLogoSprite->setName("cocos2dxLogoSprite");cocos2dxLogoSprite->setScale(2);cocos2dxLogoSprite->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));addChild(cocos2dxLogoSprite, 0);cocos2dxLogoSprite->runAction(Sequence::create(FadeIn::create(1.f),FadeOut::create(1.f), CallFuncN::create(CC_CALLBACK_1(LoadingGameScene::RunLoadingCallBack, this)), NULL));}
}
void LoadingGameScene::InitLoadingGameAnimation()
{InitBackground();InitTitle();InitEnterGameButton();
}
void LoadingGameScene::InitWatermark()
{auto label = Label::createWithTTF("by:wangjie\nqq:1020785391\nemail:1020785391@qq.com", MARKER_FELT_TTF, 24);if (label != nullptr){float x = origin.x + visibleSize.width - label->getContentSize().width / 2;float y = origin.y + label->getContentSize().height / 2;label->setPosition(Vec2(x, y));label->setTextColor(Color4B(0, 255, 255, 100));addChild(label, 1);}
}
void LoadingGameScene::InitBackground()
{// 背景auto backgroundSprite = Sprite::create("images/loadingGameImages/background.png");backgroundSprite->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));addChild(backgroundSprite);
}
void LoadingGameScene::InitTitle()
{// 标题auto titleSprite = Sprite::create("images/loadingGameImages/title.png");titleSprite->setScaleX(1.25f);auto titleSize = titleSprite->getContentSize();// 动画光auto sparkSprite = Sprite::create("images/loadingGameImages/spark.png");sparkSprite->setPosition(Vec2(-sparkSprite->getContentSize().width, 0));sparkSprite->setScale(2.0f);sparkSprite->runAction(RepeatForever::create(Sequence::create(MoveTo::create(1.0f, Vec2(titleSize.width, 0)), DelayTime::create(2.0f),CallFunc::create([=]() {sparkSprite->setPosition(Vec2(-titleSize.width, 0));}), nullptr)));/* 创建裁剪节点 */auto clippingNode = ClippingNode::create();clippingNode->setPosition(Vec2(visibleSize.width / 2, visibleSize.height + titleSize.height / 2));clippingNode->runAction(MoveTo::create(0.5f, Vec2(visibleSize.width / 2, visibleSize.height - (titleSize.height / 3 * 2))));addChild(clippingNode);clippingNode->setAlphaThreshold(0.01f);clippingNode->setContentSize(titleSize);clippingNode->setStencil(titleSprite);clippingNode->addChild(titleSprite);clippingNode->addChild(sparkSprite);
}
void LoadingGameScene::InitEnterGameButton()
{// 地auto groundSprite = Sprite::create("images/loadingGameImages/ground.png");groundSprite->setScale(2.0f);groundSprite->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 5));addChild(groundSprite);// 草坪auto greenswardSprite = Sprite::create("images/loadingGameImages/greensward.png");greenswardSprite->setScale(2.0f);greenswardSprite->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 5 + groundSprite->getContentSize().height));addChild(greenswardSprite);// 进入游戏按钮auto label = MenuItemLabel::create(Label::createWithTTF(TR("开始游戏"), WENSHUAI_FONT_TTF, 40),CC_CALLBACK_1(LoadingGameScene::BeginGameCallBack, this));label->setColor(Color3B(0, 255, 255));auto action = TintBy::create(0.5f, 0, 255, 255);label->runAction(RepeatForever::create(Sequence::create(action, action->reverse(), nullptr)));label->setEnabled(true);/* 创建菜单 */auto menu = Menu::create(label, nullptr);menu->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 5 - 10));addChild(menu);
}
bool LoadingGameScene::init()
{if ( !Scene::init() ){return false;}visibleSize = Director::getInstance()->getVisibleSize();origin = Director::getInstance()->getVisibleOrigin();// 加cocos2dx logoInitCocos2dxLogo();// 加水印InitWatermark();return true;
}
void LoadingGameScene::RunLoadingCallBack(Node* node)
{auto sprite = dynamic_cast<Sprite*>(node);if (sprite == nullptr) {return;}std::string name = sprite->getName();removeChild(sprite);if (name._Equal("cocos2dxLogoSprite")) {// 初始化加载游戏动画InitLoadingGameAnimation();}
}
void LoadingGameScene::BeginGameCallBack(NS_CC::Ref* pSender)
{Director::getInstance()->replaceScene(HomePageScene::createScene());
}
NS_PVZ_END

植物大战僵尸(cocos2dx 4.0 - cpp - pc)- 游戏加载画面相关推荐

  1. c语言游戏call调用,C语言-植物大战僵尸-刷僵尸call;fps游戏CS-方框透视(矩阵+传统)...

    C语言-植物大战僵尸-刷僵尸call:fps游戏CS-方框透视(矩阵+传统)前言:大家好,我是向上先生,嘿嘿~最近在学习逆向.反汇编等等,首先我在非常感谢52pojie这个平台,差不多很多学习资源都是 ...

  2. [搬运工]移动游戏加载性能和内存管理全解析

    UWA 六月直播季 | 6.8 移动游戏加载性能和内存管理全解析 https://blog.uwa4d.com/archives/livebroadcast6-8.html 因为这篇文章没有提供PPT ...

  3. 并发—— CountDownLatch应用之王者荣耀游戏加载

    王者荣耀加载 1.介绍 1.介绍 王者荣耀加载过程模拟,10个线程表示不同的玩家,加载进入王者荣耀 import java.util.Arrays; import java.util.Random; ...

  4. cocos creator小游戏加载跨域头像

    cocos creator小游戏加载跨域头像 // 玩家头像 和 名字 (防止跨域问题) cc.assetManager.downloader.downloadDomImage(avatarUrl , ...

  5. 【翻译】基于 Create React App路由4.0的异步组件加载(Code Splitting)

    基于 Create React App路由4.0的异步组件加载 本文章是一个额外的篇章,它可以在你的React app中,帮助加快初始的加载组件时间.当然这个操作不是完全必要的,但如果你好奇的话,请随 ...

  6. eui加载时间长_游戏加载时间越来越短了?背后藏着这些小心机

    在两大尚未发售的次世代主机中,或许你们还没决定好究竟是选择 PS5 还是 Xbox Series X,但毫无疑问次世代游戏表现已经震撼了所有人.更精美画面表现,更丰富的 HDR 效果,更快速的读取时间 ...

  7. 华为鸿蒙系统游戏体验,华为鸿蒙系统首发体验,游戏加载比安卓快60%,全面苹果挑战iOS...

    距离华为发布鸿蒙OS开发者版本已经过去将近一个月,按照计划,再有一两个月,鸿蒙OS就会向华为手机推送正式版. 其实,目前有不少申请测试版资格的用户,都提前用上鸿蒙OS.而从使用者给出的首发体验信息来看 ...

  8. 弹弹堂服务器响应时间过长,弹弹堂游戏加载问题全攻略

    新闻公告/NEWS 当前位置: 7k7k小游戏 > 弹弹堂 > 新闻公告 弹弹堂游戏加载问题全攻略 更新日期:2016-07-21     来源:7k7k     作者:7k7k卡卡 关于 ...

  9. NVIDIA GEFORCE 2080 / 2080 SUPER / 2080 Ti + CUDA Toolkit 8.0 深度学习模型加载速度慢

    NVIDIA GEFORCE 2080 / 2080 SUPER / 2080 Ti + CUDA Toolkit 8.0 深度学习模型加载速度慢 (卡顿) GEFORCE RTX 2080 / GE ...

最新文章

  1. CSS中浮动布局float(小米布局案例、导航栏案例、overflow)
  2. apache部署多个项目
  3. python计算机图形学_图形图像学习随笔:计算机图形学的一些基本概念
  4. Ribbon Finance将WBTC Theta Vault存款上限提高至250WBTC
  5. jquery中去重复排序(函数: $.grep() join() sort() )
  6. 安徽合肥一共享单车堆放点发生火灾
  7. 9个Console命令
  8. 单片机C51之1:流水灯
  9. 【单片机基础】(四)单片机的引脚功能
  10. 做好震荡筑底打持久战的准备
  11. 主流量化交易策略:统计套利交易策略
  12. php pear pecl 区别,pecl 简单介绍
  13. eclipse新建java项目报错 jrt-fs.jar
  14. SNS运营之Tumblr迅速涨粉的20个方法-适用于海外社媒推广,外贸独立站,自建站,让你粉丝快速翻倍
  15. 用深度学习做命名实体识别(五)-模型使用
  16. 游戏设计艺术(第3版) The Art of Game Design 看评论
  17. 默认google浏览器打不开链接(点击超链接没有反应)
  18. 超全Python 量化金融库汇总,必看
  19. 3月9日——3月13日课程表
  20. 如何处理前端js报错——容错处理的汇总

热门文章

  1. 第八周项目32-对程序运行结果的理解
  2. BGP选路原则和属性
  3. 数字化转型时代的主流商业模式 ——订阅服务
  4. CAD计算机辅助设计与BIM的区别,告诉你如何正确认识CAD与BIM的关系
  5. 如果要快速的读写表格,Pandas 并不是最好的选择
  6. dg的几个redo解释及备库目录
  7. 蚁群算法(Ant Colony Algorithm, ACA)简介及其MATLAB实现
  8. ASO优化之应用商店列表的视觉效果
  9. 剪映pc电脑版下载 | 剪映(视频剪辑软件)官方正式版V1.1.1.0 | 剪映专业版剪映电脑版安装非常简单
  10. Pikachu漏洞平台练习——PHP序列化与反序列化、PHP反序列化漏洞