[Cocos2d-x For WP8]DrawPrimitives画图
在Silverlight框架的WP8应用程序里面,我们画几何图形的时候会通过Line等等的类在用C#代码或者在XAML上画图,那么在Cocos2d-x For WP8里面我们一样也可以实现这样的功能。那么在Cocos2d-x中画图的逻辑要放在自己写的draw函数里面,这样图形引擎才会把你的图形给画出来。
比如说:
将画一条直线放到下面这函数是画不出来的
bool HelloWorld::init()
{
ccDrawLine( ccp(0, 0), ccp(s.width, s.height) ); CHECK_GL_ERROR_DEBUG();
}
而放到draw函数就能画出来,也不需要调用
void HelloWorld::draw()
{
ccDrawLine( ccp(0, 0), ccp(s.width, s.height) ); CHECK_GL_ERROR_DEBUG();
}
示例代码:
void HelloWorld::draw()
{
CCLayer::draw(); CCSize s = CCDirector::sharedDirector()->getWinSize(); // 画两条对角的直线
// 默认的数值:
// Line Width: 1
// color: 255,255,255,255 (white, non-transparent)
// Anti-Aliased
//glEnable(GL_LINE_SMOOTH);
//ccDrawLine( CCPointMake(0, 0), CCPointMake(s.width, s.height) ); // line: color, width, aliased
//glDisable(GL_LINE_SMOOTH);
//glLineWidth( 5.0f );
/*glColor4ub(255,0,0,255);*/
CCDrawingPrimitive::D3DColor4f(1.0, 0.0, 0.0, 1.0);
ccDrawLine( CCPointMake(, s.height), CCPointMake(s.width, ) );
ccDrawLine( CCPointMake(, ), CCPointMake(s.width,s.height ) ); // TIP:
//如果是使用同一种颜色则不需要重新去调用CCDrawingPrimitive::D3DColor4f方法去设置颜色 I
//
// Remember: OpenGL is a state-machine. // draw big point in the center
//glPointSize(64);
/*glColor4ub(0,0,255,128);*/
CCDrawingPrimitive::D3DColor4f(0.0, 0.0, 1.0, 0.5);
ccDrawPoint( CCPointMake(, ) );
/*ccDrawPoint( CCPointMake(s.width / 2, s.height / 2) );*/ // draw 4 small points
CCPoint points[] = { CCPointMake(,), CCPointMake(,), CCPointMake(,), CCPointMake(,) };
//glPointSize(4);
/*glColor4ub(0,255,255,255);*/
CCDrawingPrimitive::D3DColor4f(0.0, 1.0, 1.0, 1.0);
ccDrawPoints( points, ); // draw a green circle with 10 segments
//glLineWidth(16);
/*glColor4ub(0, 255, 0, 255);*/
CCDrawingPrimitive::D3DColor4f(0.0, 1.0, 0.0, 1.0);
ccDrawCircle( CCPointMake(s.width/, s.height/), , , , false); // draw a green circle with 50 segments with line to center
//glLineWidth(2);
/*glColor4ub(0, 255, 255, 255);*/
CCDrawingPrimitive::D3DColor4f(0.0, 1.0, 1.0, 1.0);
ccDrawCircle( CCPointMake(s.width/, s.height/), , CC_DEGREES_TO_RADIANS(), , true); // open yellow poly
/*glColor4ub(255, 255, 0, 255);*/
CCDrawingPrimitive::D3DColor4f(1.0, 1.0, 0.0, 1.0);
//glLineWidth(10);
CCPoint vertices[] = { CCPointMake(,), CCPointMake(,), CCPointMake(,), CCPointMake(,), CCPointMake(,) };
ccDrawPoly( vertices, , false); // closed purble poly
/*glColor4ub(255, 0, 255, 255);*/
CCDrawingPrimitive::D3DColor4f(1.0, 0.0, 1.0, 1.0);
//glLineWidth(2);
CCPoint vertices2[] = { CCPointMake(,), CCPointMake(,), CCPointMake(,) };
ccDrawPoly( vertices2, , true); // draw quad bezier path
ccDrawQuadBezier(CCPointMake(,s.height), CCPointMake(s.width/,s.height/), CCPointMake(s.width,s.height), ); // draw cubic bezier path
ccDrawCubicBezier(CCPointMake(s.width/, s.height/), CCPointMake(s.width/+,s.height/+), CCPointMake(s.width/+,s.height/-),CCPointMake(s.width, s.height/),); // restore original values
//glLineWidth(1);
/*glColor4ub(255,255,255,255);*/
CCDrawingPrimitive::D3DColor4f(1.0, 1.0, 1.0, 1.0);
//glPointSize(1);
}
运行的效果:
[Cocos2d-x For WP8]DrawPrimitives画图的更多相关文章
- Cocos2d-x游戏移植到WP8之路 -- c++和c#交互
Cocos2d-x是眼下最流行的手机游戏引擎之中的一个,开源.轻量.多平台等的诸多特性使得它被非常多国内外手游开发人员所喜爱. 利用Cocos2d-x来开发Windows Phone 8的游戏相同也是 ...
- cocos2d_x_03_经常使用类的使用_事件_画图
一.TextFieldTTF输入框的使用 #pragma mark - 自己定义方法 // 自己定义方法,加入一个 TextField void TextFieldScene::addOneTextF ...
- cocos2dx基础篇(16) 基本绘图DrawPrimitives
[3.x] (1)去掉前缀 "cc" (2)将 ccDraw***() 封装到了 DrawPrimitives 命名空间中. (3)重写绘图函数: draw(Ren ...
- 【Cocos2d-x for WP8 学习整理】(4)CCTableView 实现《天天爱消除》中的得分榜
接上回 CCScrollView 继续,在GUI 里还有个 CCScrollView 的子类---CCTableView . 这个名字应该是从 IOS 里的 UITableView来的,其实是跟WP8 ...
- [Cocos2D-x For WP8]CocosDenshion音频播放
Cocos2D-x的音频分为长时间的背景音乐和短的音效两种,我们可以通过SimpleAudioEngine::sharedEngine()方法来获取音频播放的引擎,然后调用对音频相关的操作方法就可以了 ...
- [Cocos2D-x For WP8]Box2D物理引擎
物理引擎通过为刚性物体赋予真实的物理属性的方式来计算运动.旋转和碰撞反映.为每个游戏使用物理引擎并不是完全必要的—简单的“牛顿”物理(比如加速和减速)也可以在一定程度上通过编程或编写脚本来实现.然而, ...
- [Cocos2d-x For WP8]EaseActions缓动动作
我们用Silverlight框架开发WP8的应用程序的时,编写动画可以使用缓动效果来实现缓动动画对吧,那么在Cocos2d-x框架里面我们一样是可以缓动动作(缓动动画),其实技术的东西都是想通的,如果 ...
- [Cocos2d-x For WP8]Hello world
[Cocos2d-x For WP8]Hello world Cocos2d-x For WP8使用C++开发,使用cocos2d-xv0.13同样的接口,Cocos2d-x For WP8的相关项目 ...
- [Cocos2d-x for WP8学习笔记] HelloWorld结构分析
先来看一下目录结构: Assets:游戏资源文件,图片音频等,Resource文件夹也有类似功能 include:用于放置游戏头文件 Shaders:渲染器着色器文件(大雾) cocos2dorig. ...
随机推荐
- 【JAVA集合框架之Map】
一.概述.1.Map是一种接口,在JAVA集合框架中是以一种非常重要的集合.2.Map一次添加一对元素,所以又称为“双列集合”(Collection一次添加一个元素,所以又称为“单列集合”)3.Map ...
- 【PHP的异常处理【完整】】
PHP的异常处理机制大多数和java的很相似,但是没有finally,而且还可以自定义顶级异常处理器:捕捉到异常信息后,会跳出try-catch块,如果catch中没有跳转的动作,则会继续执行下一条语 ...
- MYSQL建表语法(主键,外键,联合主键)
在看<Learning SQL>第二版, 慢慢打实SQL的基础. 建表一: ), lname ), gender ENUM(), city ), state ), country ), p ...
- java中常用的工具类(一)
我们java程序员在开发项目的是常常会用到一些工具类.今天我汇总了一下java中常用的工具方法.大家可以在项目中使用.可以收藏!加入IT江湖官方群:383126909 我们一起成长 一.String工 ...
- <jsp:include>和<%@include file=""%>区别【131031】
<jsp:include page=""> 父页面和包含进来的页面单独编译,单独翻译成servlet后,在前台拼成一个HTML页面. <%@include fil ...
- [LeetCode] Implement strStr()
Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...
- Howto: Connect MySQL server using C program API under Linux or UNIX
From my mailbag: How do I write a C program to connect MySQL database server? MySQL database does su ...
- jquery获取radio和select选中值
//jquery 获取radio选中值 <input type="radio" name="c_type" value="a" > ...
- linux下mysql的简单使用
写这篇的主要目的是记录一点mysql的基本使用方法,当然sql查询语句本来就有不少东西,这里就不一一介绍,这个网址有详细的教程(http://www.sdau.edu.cn/support/mysq_ ...
- Cygwin的安装,卸载,以及安装gdb
转载来源 http://10000001.blog.51cto.com/4600383/1341484 1.安装 其实Cygwin的安装时很简单的,需要的安装相应的就可以了,要详细的去网上找,很多 ...