#include"AppDelegate.h"
#include"HelloWorldScene.h"
USING_NS_CC;
AppDelegate::AppDelegate(){
}
AppDelegate::~AppDelegate()
{
}
AppDelegate::initGLContextAttrs()
{
//设置OpenGL上下文属性,现在只能设置六个属性:
//红,绿,蓝,阿尔法,深度,模板
GLContextAttrsglContextAttrs={8,8,24,8};
GLView::setGLContextAttrs(glContextAttrs);
}
AppDelegate::applicationDidFinishLaunching()
{
//初始化导演
autodirector=Director::getInstance();
//获得OpenGL视图
autoglview=director->getOpenGLView();
if
(!glview)
{
//设置程序名和窗口的尺寸
glview=GLViewImpl::createWithRect(
"myProject"
,Rect(0,960,640));
//设置OpenGL视图
director->setOpenGLView(glview);
}
//设置分辨率
director->getOpenGLView()->setDesignResolutionSize(960,640,ResolutionPolicy::SHOW_ALL);
//设置是否显示调试信息
director->setDisplayStats(
true
);
//设置帧率
director->setAnimationInterval(1.0/60);
//设置文件的搜索路径
FileUtils::getInstance()->addSearchPath(
"res"
);
//调用场景
autoscene=HelloWorld::createScene();
//执行场景
director->runWithScene(scene);
return
;
}
AppDelegate::applicationDidEnterBackground()
{
//停止播放动画
Director::getInstance()->stopAnimation();
//如果程序中有背景音乐,停止播放背景音乐
//SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
}
AppDelegate::applicationWillEnterForeground()
{
//播放动画
Director::getInstance()->startAnimation();
//当程序中有背景音乐的时候继续播放背景音乐
//SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
HelloWorldScene.h中的代码(本人已经注释)
20
#ifndef__HELLOWORLD_SCENE_H__
#define__HELLOWORLD_SCENE_H__
//HelloWorld继承自Layer
HelloWorld:
cocos2d::Layer
//创建场景
static
cocos2d::Scene*createScene();
//初始化场景
init();
//实施静态的create方法
CREATE_FUNC(HelloWorld);
};
#endif//__HELLOWORLD_SCENE_H__
|
HelloWorldScene.cpp中的代码(本人已经注释)
40
#include"HelloWorldScene.h"
#include"cocostudio/CocoStudio.h"
#include"ui/CocosGUI.h"
//使用动画需要引入的命名空间
using
namespace
cocostudio::timeline;
Scene*HelloWorld::createScene()
{
//创建场景
autoscene=Scene::create();
//创建层
autolayer=HelloWorld::create();
//将层添加到场景中
scene->addChild(layer);
//返回场景
scene;
}
HelloWorld::init()
{
//初始化父类的层
(!Layer::init())
{
false
;
}
//加载Cocostudio的资费
autorootNode=CSLoader::createNode(
"MainScene.csb"
);
addChild(rootNode);
;
}
|
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|