这篇算是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文档.接下来 ...
随机推荐
-
Hadoop学习12-配置集群环境
由于之前虚拟机都是用的桥接方式,有时候没有网络可用,想学习的时候,就狠不方便. 于是研究了一下,希望搭建一个多台虚机组成一个局域网的集群,即host-only方式 1.安装VM,网络选择“host-o ...
-
C# 好书一本推荐
书名<CLR Via C#>第三版中文版,我已上传: 下载地址:http://files.cnblogs.com/jackchiang/CLR_Via_Csharp.%E7%AC%AC3% ...
-
Python学习笔记 - 数据类型和变量
Python中有整数和浮点数,表示方法和C语言一样 浮点数也很像,不过Python可以用单引号把字符串括起来 字符串是以单引号'或双引号"括起来的任意文本,比如'abc',"xyz ...
-
vue.js使用vue-preview做移动端缩略图时报错Property or method ";$preview"; is not defined
报错的详细信息为: Property or method "$preview" is not defined on the instance but referenced duri ...
-
使用EWS API读取邮件
#安装EwsManagedApi.msi,然后导入EWS模块 Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Ser ...
-
Linux 小记 — Ubuntu 自动化配置
前言 工欲善其事,必先利其器.经过多次的重复配置 ubuntu 开发坏境,我终于决定花点时间总结一下,并将其写成一个自动化配置脚本.服务器实例:ubuntu 16.04,技术栈:shell,pytho ...
-
PHP伪造referer突破网盘禁止外链(附115源码)
新建一个文件file.php.后面的参数就是需要伪造referfer的目标地址吧.如:file.php/http://www.xxx.xxx/xxx.mp3 复制内容到剪贴板 代码: <?$ur ...
-
[pat]1007 Maximum Subsequence Sum
经典最大连续子序列,dp[0]=a[0],状态转移dp[i]=max(dp[i-1]+a[i],a[i])找到最大的dp[i]. 难点在于记录起点,这里同样利用动态规划s[i],如果dp[i]选择的是 ...
-
解决ASP.NET MVC4中使用Html.DropDownListFor显示枚举值默认项问题
从ASP.NET MVC 5开始,Html.DropDownListFor已经提供了对Enum的支持,但在这以前,需要通过帮助方法或扩展方法来让Html.DropDownListFor显示枚举值. 本 ...
-
java quartz 中的时间格式
SimpleTrigger 如果需要计划一个任务在指定的时间执行,或者在指定的时间后以指定的间隔连续执行多次,比如希望在2005年1月12号上午11:22:54开始执行一个任务,在这之后每隔20分钟执 ...