[Cocos2d-x For WP8]DrawPrimitives画图
生活随笔
收集整理的這篇文章主要介紹了
[Cocos2d-x For WP8]DrawPrimitives画图
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
??? 在Silverlight框架的WP8應(yīng)用程序里面,我們畫幾何圖形的時(shí)候會(huì)通過(guò)Line等等的類在用C#代碼或者在XAML上畫圖,那么在Cocos2d-x For WP8里面我們一樣也可以實(shí)現(xiàn)這樣的功能。那么在Cocos2d-x中畫圖的邏輯要放在自己寫的draw函數(shù)里面,這樣圖形引擎才會(huì)把你的圖形給畫出來(lái)。
比如說(shuō):
將畫一條直線放到下面這函數(shù)是畫不出來(lái)的
bool HelloWorld::init()
{
ccDrawLine( ccp(0, 0), ccp(s.width, s.height) ); CHECK_GL_ERROR_DEBUG();
}
而放到draw函數(shù)就能畫出來(lái),也不需要調(diào)用
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();// 畫兩條對(duì)角的直線// 默認(rèn)的數(shù)值:// 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(0, s.height), CCPointMake(s.width, 0) );ccDrawLine( CCPointMake(0, 0), CCPointMake(s.width,s.height ) );// TIP://如果是使用同一種顏色則不需要重新去調(diào)用CCDrawingPrimitive::D3DColor4f方法去設(shè)置顏色 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(65, 65) );/*ccDrawPoint( CCPointMake(s.width / 2, s.height / 2) );*/// draw 4 small pointsCCPoint points[] = { CCPointMake(60,60), CCPointMake(70,70), CCPointMake(60,70), CCPointMake(70,60) };//glPointSize(4);/*glColor4ub(0,255,255,255);*/CCDrawingPrimitive::D3DColor4f(0.0, 1.0, 1.0, 1.0);ccDrawPoints( points, 4);// 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/2, s.height/2), 100, 0, 10, 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/2, s.height/2), 50, CC_DEGREES_TO_RADIANS(90), 50, true); // open yellow poly/*glColor4ub(255, 255, 0, 255);*/CCDrawingPrimitive::D3DColor4f(1.0, 1.0, 0.0, 1.0);//glLineWidth(10);CCPoint vertices[] = { CCPointMake(0,0), CCPointMake(50,50), CCPointMake(100,50), CCPointMake(100,100), CCPointMake(50,100) };ccDrawPoly( vertices, 5, false);// closed purble poly/*glColor4ub(255, 0, 255, 255);*/CCDrawingPrimitive::D3DColor4f(1.0, 0.0, 1.0, 1.0);//glLineWidth(2);CCPoint vertices2[] = { CCPointMake(30,130), CCPointMake(30,230), CCPointMake(50,200) };ccDrawPoly( vertices2, 3, true);// draw quad bezier pathccDrawQuadBezier(CCPointMake(0,s.height), CCPointMake(s.width/2,s.height/2), CCPointMake(s.width,s.height), 50);// draw cubic bezier pathccDrawCubicBezier(CCPointMake(s.width/2, s.height/2), CCPointMake(s.width/2+30,s.height/2+50), CCPointMake(s.width/2+60,s.height/2-50),CCPointMake(s.width, s.height/2),100);// restore original values//glLineWidth(1);/*glColor4ub(255,255,255,255);*/CCDrawingPrimitive::D3DColor4f(1.0, 1.0, 1.0, 1.0);//glPointSize(1); }運(yùn)行的效果:
?
轉(zhuǎn)載于:https://www.cnblogs.com/linzheng/p/3279528.html
總結(jié)
以上是生活随笔為你收集整理的[Cocos2d-x For WP8]DrawPrimitives画图的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 基于Mahout的电影推荐系统
- 下一篇: 深入Java虚拟机读书笔记第五章Java