首页 技术 正文
技术 2022年11月19日
0 收藏 594 点赞 2,549 浏览 2819 个字

说明:这里是平局:晓风残月前辈的博客。他是将泰然网的跑酷教程。用cocos2d-x
2.X 版本号重写的,眼下我正在学习cocos2d-X3.0 于是就用cocos2d-X 3.0重写,并做相关笔记

開始界面和前辈的基本上差点儿相同:cocos2d-x游戏开发
跑酷(一)開始界面
     可是也有不同

首先你得自己先新建一个项目,我们从头開始

以下先给出游戏过程中用到的全部资源

到今天8-1号,整个游戏已经完毕重写。

。后面也给出全部代码和资源,以及整个项目都打包好的地址,或者你愿意跟着我的笔记一步一步来的话,在这里以下给出全部资源的百度云下载地址

開始界面定义为:MainScene 有例如以下功能:

1.背景

2.进入游戏界面button

3.预先载入背景音乐文件

.h文件

#ifndef __MainScene__H__
#define __MainScene__H__#include "cocos2d.h"class MainScene : cocos2d::Layer{
public:
virtual bool init();
static cocos2d::Scene* scene();
CREATE_FUNC(MainScene);private:
//
void createBG();
//
void createButton(cocos2d::Point centerPoint);
//
void preLoadMusic();
//menu start the game
void start();
};/**/#endif

.cpp

#include "MainScene.h"
#include "SimpleAudioEngine.h"
//#include "PlayScene.h"USING_NS_CC;
using namespace CocosDenshion;Scene* MainScene::scene(){
Scene* scene = Scene::create();
Layer* layer = MainScene::create();
scene->addChild(layer);
return scene;
}bool MainScene::init(){
if(!Layer::init()){
return false;
}//preloadMusic
preLoadMusic();//create background
createBG();return true;
}void MainScene::createBG(){
auto winSize = Director::getInstance()->getWinSize();
auto centerPoint = ccp(winSize.width / 2, winSize.height / 2);//BG
Sprite* spriteBg = Sprite::create("MainBG.png");
spriteBg->setPosition(centerPoint);
this->addChild(spriteBg);//create button
createButton(centerPoint);
}void MainScene::createButton(cocos2d::Point centerPoint){
//Start mutton
MenuItemImage* menuItem = MenuItemImage::create(
"start_n.png",
"start_s.png",
CC_CALLBACK_0(MainScene::start,this));Menu* menu = Menu::create(menuItem,NULL);menu->setPosition(centerPoint);this->addChild(menu);
}void MainScene::preLoadMusic(){
SimpleAudioEngine* audioEngin = SimpleAudioEngine::getInstance();
audioEngin->preloadBackgroundMusic("background.mp3");
audioEngin->preloadEffect("jump.mp3");
audioEngin->preloadEffect("crouch.mp3");
}void MainScene::start(){
CCLOG("game is start !");
//Scene* playScene = TransitionFade::create(1,PlayScene::createScene());
//Director::getInstance()->replaceScene(playScene);
}

这里因为我对屏幕自适应的知识还不够了解,尽管看过几篇文章。可是还是比較迷茫。不怎么知道运用到实例其中。所以对于这次重写中,背景图片一般都是 640*320大小的 ,所以须要在AppDelegate.cpp 其中设置显示窗体大小:

bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::create("My Game");
glview->setFrameSize(640,320);//------改动显示窗体大小
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.0 / 60); // create a scene. it's an autorelease object
auto scene = MainScene::scene(); // run
director->runWithScene(scene); return true;
}

自己仅仅能后面了解相关知识啦,假设有好的相关教程,麻烦推荐一下,谢谢!!

我们能够删掉HelloWorld,在AppDelegate里面替换成MainScene::scene();

执行之后如图:

游戏资源:跑酷游戏资源 ,这里已经改动成网盘地址啦,或者在以下留言留下邮箱&私信我。我就给你发种子。

哦不,发资源,游戏资源!!!每天都在

这一部分的单独项目:http://pan.baidu.com/s/1hqHwEPI

个人愚昧观点,欢迎指正与讨论

版权声明:本文博客原创文章,博客,未经同意,不得转载。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,557
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898