玩龙天子 发表于 2016-1-3 01:14:19

Cocos2d-x之绘制填充矩形

  Cocos2d-x之绘制填充矩形
  自定义的方法
  SRect.h
  



1 //
2 //SRect.h
3 //L01DrawingAPI
4 //
5 //Created by Mac OS 10.9.3 on 15-3-30.
6 //
7 //
8
9 #ifndef __L01DrawingAPI__SRect__
10 #define __L01DrawingAPI__SRect__
11
12 #include <iostream>
13 #include <cocos2d.h>
14
15 using namespace cocos2d;
16
17 namespace bobo {
18   class SRect:public Node{
19         
20   public:
21         
22         virtual bool init();
23         virtual void draw();
24         CREATE_FUNC(SRect);
25   };
26 }
27
28
29 #endif /* defined(__L01DrawingAPI__SRect__) */
  Srect.cpp



1 //
2 //SRect.cpp
3 //L01DrawingAPI
4 //
5 //Created by Mac OS 10.9.3 on 15-3-30.
6 //
7 //
8
9 #include "SRect.h"
10
11 namespace bobo {
12   
13   bool SRect::init(){
14         return true;
15   }
16   
17   void SRect::draw(){
18         //绘制了一个蓝色不透明的填充矩形
19         DrawPrimitives::drawSolidRect(Point(0, 0), Point(100, 100), Color4F(0, 0, 1, 1));
20   }
21 }
  在bool HelloWorld::init() 方法中
  



1 auto sr = bobo::SRect::create();//创建填充矩形
2   sr->setPosition(Point(200, 50));//设置位置
3   addChild(sr);//添加到层中
  
页: [1]
查看完整版本: Cocos2d-x之绘制填充矩形