在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画图的更多相关文章

  1. Cocos2d-x游戏移植到WP8之路 -- c++和c#交互

    Cocos2d-x是眼下最流行的手机游戏引擎之中的一个,开源.轻量.多平台等的诸多特性使得它被非常多国内外手游开发人员所喜爱. 利用Cocos2d-x来开发Windows Phone 8的游戏相同也是 ...

  2. cocos2d_x_03_经常使用类的使用_事件_画图

    一.TextFieldTTF输入框的使用 #pragma mark - 自己定义方法 // 自己定义方法,加入一个 TextField void TextFieldScene::addOneTextF ...

  3. cocos2dx基础篇(16) 基本绘图DrawPrimitives

    [3.x] (1)去掉前缀 "cc" (2)将 ccDraw***() 封装到了 DrawPrimitives 命名空间中. (3)重写绘图函数:         draw(Ren ...

  4. 【Cocos2d-x for WP8 学习整理】(4)CCTableView 实现《天天爱消除》中的得分榜

    接上回 CCScrollView 继续,在GUI 里还有个 CCScrollView 的子类---CCTableView . 这个名字应该是从 IOS 里的 UITableView来的,其实是跟WP8 ...

  5. [Cocos2D-x For WP8]CocosDenshion音频播放

    Cocos2D-x的音频分为长时间的背景音乐和短的音效两种,我们可以通过SimpleAudioEngine::sharedEngine()方法来获取音频播放的引擎,然后调用对音频相关的操作方法就可以了 ...

  6. [Cocos2D-x For WP8]Box2D物理引擎

    物理引擎通过为刚性物体赋予真实的物理属性的方式来计算运动.旋转和碰撞反映.为每个游戏使用物理引擎并不是完全必要的—简单的“牛顿”物理(比如加速和减速)也可以在一定程度上通过编程或编写脚本来实现.然而, ...

  7. [Cocos2d-x For WP8]EaseActions缓动动作

    我们用Silverlight框架开发WP8的应用程序的时,编写动画可以使用缓动效果来实现缓动动画对吧,那么在Cocos2d-x框架里面我们一样是可以缓动动作(缓动动画),其实技术的东西都是想通的,如果 ...

  8. [Cocos2d-x For WP8]Hello world

    [Cocos2d-x For WP8]Hello world Cocos2d-x For WP8使用C++开发,使用cocos2d-xv0.13同样的接口,Cocos2d-x For WP8的相关项目 ...

  9. [Cocos2d-x for WP8学习笔记] HelloWorld结构分析

    先来看一下目录结构: Assets:游戏资源文件,图片音频等,Resource文件夹也有类似功能 include:用于放置游戏头文件 Shaders:渲染器着色器文件(大雾) cocos2dorig. ...

随机推荐

  1. 微信支付开发(1) JS API支付V3版(转)

    http://www.cnblogs.com/txw1958/p/wxpayv3-jsapi.html 本文介绍微信支付下的jsapi实现流程 前言 微信支付现在分为v2版和v3版,2014年9月10 ...

  2. C# 中的Singleton模式

    一般写Singleton基本都是一下这个套路 class Singleton { public static Singleton instance; private Singleton() { } p ...

  3. 【转载】 Pyqt 利用QDataStream对文件进行存取

    # -*- coding: utf-8 -*- from PyQt4.QtGui import * from PyQt4.QtCore import * import sys QTextCodec.s ...

  4. poj 1724:ROADS(DFS + 剪枝)

    ROADS Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10777   Accepted: 3961 Descriptio ...

  5. 数据结构之图 Part3 – 2 遍历

    BFS using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ...

  6. 数据结构之图 Part2 - 3

    十字链表 简单的说就是邻接表和逆邻接表的合体,解决了原邻接表或者逆邻接表出度和入度的计算无法兼得的问题. using System; using System.Collections.Generic; ...

  7. 第二篇:SOUI源码的获取及编译

    源代码的获取 SOUI的源码采用SVN管理. SVN:http://code.taobao.org/svn/soui2 这里主要包含两个目录:trunk 及 third-part. trunk目录保存 ...

  8. [荐]javascript Date format(js日期格式化)

    cnblog:http://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html 方法一: // 对Date的扩展,将 Date  ...

  9. ListView中每个item条目在被单击选中时能够高亮显示

    在布局文件中设定: android:listSelector="@android:color/holo_red_light" 在代码中实现 listView.setSelector ...

  10. LeetCode——Reverse Integer(逆置一个整数)

    问题: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return –321   Ha ...