cocos2d-x学习记录1——图片显示
这篇算是cocos2d-x入门篇,显示一张图片即可。
观察工程中HelloWorld的结构,包含AppDelegate和HelloWorldScene两个类文件,AppDelegate中包含基本的处理,并且创建最初要显示的Scene并运行之。
而HelloWorldScene中则做了相关的初始化工作,在这里,自己仿照HelloWorldScene写个更简单的Scene用于显示。
AppDelegate.cpp内容
#include "AppDelegate.h"
//#include "HelloWorldScene.h"
#include "MyScene.h" USING_NS_CC; AppDelegate::AppDelegate() { } AppDelegate::~AppDelegate()
{
} bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
CCDirector* pDirector = CCDirector::sharedDirector();
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); pDirector->setOpenGLView(pEGLView); // turn on display FPS
pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / ); // create a scene. it's an autorelease object
//CCScene *pScene = HelloWorld::scene();
CCScene *pScene = MyScene::createScene(); // run
pDirector->runWithScene(pScene); return true;
} // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground() {
CCDirector::sharedDirector()->stopAnimation(); // if you use SimpleAudioEngine, it must be pause
// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
} // this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
CCDirector::sharedDirector()->startAnimation(); // if you use SimpleAudioEngine, it must resume here
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}
MyScene.h内容
#ifndef MyScene_H_H
#define MyScene_H_H #include "cocos2d.h"
using namespace cocos2d; class MyScene : public CCLayer
{
public:
static CCScene* createScene();
virtual bool init();
CREATE_FUNC( MyScene ); private:
}; #endif
MyScene.cpp内容
#include "MyScene.h" CCScene* MyScene::createScene()
{
CCScene *scene = CCScene::create();
MyScene *layer = MyScene::create();
scene->addChild(layer);
return scene;
}; bool MyScene::init()
{
if( !CCLayer::init() ){
return false;
}
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSprite *sprite = CCSprite::create("pal4.png");
sprite->setAnchorPoint( ccp(0.5f, 0.5f) );
sprite->setPosition( ccp(size.width/, size.height/) );
sprite->setScale(0.5f);
addChild(sprite); return true;
}
运行结果:
cocos2d-x学习记录1——图片显示的更多相关文章
- libgdx学习记录1——图片显示Texture
libgdx底层采用opengl渲染,对图片进行了优化处理,与android原生态的bitmap不太一样. 相比而言,效率要高一些,不过只支持png,jpg,bmp三种格式. 显示中,一般将图片放在a ...
- libgdx学习记录23——图片移动选择
模拟移动选择图片,采用相机实现. package com.fxb.newtest; import com.badlogic.gdx.ApplicationAdapter; import com.bad ...
- libgdx学习记录19——图片动态打包PixmapPacker
libgdx中,opengl 1.x要求图片长宽必须为2的整次幂,一般有如下解决方法 1. 将opengl 1.x改为opengl 2.0.(libgdx 1.0版本后不支持1.x,当然不存在这个问题 ...
- libgdx学习记录2——文字显示BitmapFont
libgdx对中文支持不是太好,主要通过Hireo和ttf字库两种方式实现.本文简单介绍最基本的bitmapfont的用法. 代码如下: package com.fxb.newtest; import ...
- IOS开发-UI学习-根据URL显示图片,下载图片的练习(button,textfield,image view,url,data)
编写一个如下界面,实现: 1.在文本输入框中输入一个网址,然后点击显示图片,图片显示到UIImageView中. 2.点击下载,这张显示的图片被下载到手机的Documents文件夹下的Dowmload ...
- Cocos2dx 学习记录 [2] 关于混合和高亮一些知识点的体会
网上有一篇博客讲的是高亮的http://www.cnblogs.com/mrblue/p/3455775.html 就是这篇,尽管代码简单,但对于刚開始学习的人的我,看的还是有些吃力的,毕竟有些内容不 ...
- UWP学习记录7-设计和UI之控件和模式4
UWP学习记录7-设计和UI之控件和模式4 1.翻转视图 使用翻转视图浏览集合中的图像或其他项目(例如相册中的照片或产品详细信息页中的项目),一次显示一个项目. 对于触摸设备,轻扫某个项将在整个集合中 ...
- Matlab 进阶学习记录
最近在看 Faster RCNN的Matlab code,发现很多matlab技巧,在此记录: 1. conf_proposal = proposal_config('image_means', ...
- Material Calendar View 学习记录(二)
Material Calendar View 学习记录(二) github link: material-calendarview; 在学习记录一中简单翻译了该开源项目的README.md文档.接下来 ...
随机推荐
- python websocket client 使用
import websocket ws = websocket.WebSocket() ws.connect("xx.xx.xx") ws.send("string&qu ...
- 有关于《Linux C编程一站式学习》(备份)
Linux C编程一站式学习 -- PDF版本,共37章: Linux C编程一站式学习 -- 在线版,来自灰狐: Linux C编程一站式学习 -- 在线版,来自亚嵌教育: Linux C一站式学习 ...
- Oracle EBS OPM 查询现有量
--查询现有量 --created by jenrry DECLARE p_inventory_item_id NUMBER := 231652; --NOT NULL p_organization_ ...
- Distribution setup SQL Server Agent error: "RegCreateKeyEx() returned error 5, 'Access is denied.'" (转载)
In the Configure Distribution Wizard, the step "Configuring SQL Server Agent to start automatic ...
- jboss eap6.1(1)
最近决定把公司的项目从jboss3.x迁移出来,先试着摸索一下最新的jboss服务器,从jboss官网上下了一份jboss-eap-6.1,然后找资料准备学习,同时将此次迁移过程记录下来,以备后续复习 ...
- Spring中的destroy-method方法
1. Bean标签的destroy-method方法 配置数据源的时候,会有一个destroy-method方法 <bean id = "dataSource" class ...
- 转:queue
数据结构C#版笔记--队列(Quene) 队列(Quene)的特征就是“先进先出”,队列把所有操作限制在"只能在线性结构的两端"进行,更具体一点:添加元素必须在线性表尾部进行, ...
- CentOS7 安装 JDK
安装步骤 1. 将 jdk 安装包传到 用户 centos 的 home 目录 (/home/centos) 通过 Xftp 将安装包( jdk-8u161-linux-x64.tar.gz )传到用 ...
- 一起学习Boost标准库--Boost.StringAlgorithms库
概述 在未使用Boost库时,使用STL的std::string处理一些字符串时,总是不顺手,特别是当用了C#/Python等语言后trim/split总要封装一个方法来处理.如果没有形成自己的com ...
- Gitkraken的使用
一个优秀的团队合作离不开git,一个优秀的程序员也离不开git.gitkraken是我在进行软工实践这门课接触到的git的UI界面的工具,它给我留下的印象就是非常好用和方便 怎么个方便法呢? 方便的安 ...