[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. ...
随机推荐
- bt和wifi的共存
转自:http://bbs.52rd.com/Thread-291892-1-1.html 蓝牙和802.11b/g/n都可能工作在2.4GISM,可能互相干扰.干扰的典型应用之一是VOIP,用手机的 ...
- 【数据库】 Sqlserver 2008 error 40出现连接错误的解决方法
经常要连接到远程数据库上,因此常常碰到这个错误,然后又屡次忘记解决方法,所以今天坐下笔迹,好下次能快速回忆起来. 一.首先检查数据库的TCP/TP是否启动 1.启动Sql server配置管理器 2. ...
- Android - 控件android:ems属性
Android - 控件android:ems属性http://blog.csdn.net/caroline_wendy/article/details/41684255?utm_source=tui ...
- Pyqt 音视频播放器
在寻找如何使用Pyqt做一个播放器时首先找到的是openCV2 openCV2 貌似太强大了,各种关于图像处理的事情它都能完成,如 读取摄像头.图像识别.人脸识别. 图像灰度处理 . 播放视频等,强 ...
- 【翻译二十】-java线程池
Thread Pools Most of the executor implementations in java.util.concurrent use thread pools, which co ...
- angularjs 权威指南 版本 1.2.6
1 $rootScope run : run 方法初始化全局的数据 ,只对全局作用域起作用 如$rootScope <script src="http://apps.bdimg.c ...
- bootstrap表单带验证
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...
- 跟着鸟哥学Linux系列笔记2-第10章VIM学习
跟着鸟哥学Linux系列笔记0-扫盲之概念 跟着鸟哥学Linux系列笔记0-如何解决问题 跟着鸟哥学Linux系列笔记1 常用的文本编辑器:Emacs, pico, nano, joe, vim VI ...
- 【c++】必须在类初始化列表中初始化的几种情况
转自:http://www.cnblogs.com/kaituorensheng/p/3477630.html 1. 类成员为const类型 2. 类成员为引用类型 #include <iost ...
- C语言里面捕获错误机制
在C语言中异常处理一般有这么几种方式: 1.使用标准C库提供了abort()和exit()两个函数,它们可以强行终止程序的运行,其声明处于<stdlib.h>头文件中. 2.使用asser ...