Skip to content

Instantly share code, notes, and snippets.

@sdkfz181tiger
Created October 25, 2013 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdkfz181tiger/7163652 to your computer and use it in GitHub Desktop.
Save sdkfz181tiger/7163652 to your computer and use it in GitHub Desktop.
デバッグモード表示クラス
//
// DebugDraw.cpp
// ShimejiGame
//
// Created by sdkfz181yagni on 13/09/15.
//
//
#include "DebugDraw.h"
DebugDraw::DebugDraw(){
points = new vector<DebugPoint>();
lines = new vector<DebugLine>();
}
DebugDraw::~DebugDraw(){
delete points;
delete lines;
}
DebugDraw* DebugDraw::create(bool debug){
DebugDraw* dd = new DebugDraw();
dd->autorelease();
dd->debug = debug;
return dd;
}
void DebugDraw::draw(void){
if(debug){
// DebugPoint
int count = points->size();
for(int c=0; c<count; c++){
DebugPoint dp = points->at(c);
DrawPrimitives::setPointSize(10.0f);
DrawPrimitives::setDrawColor4B(dp.r, dp.g, dp.b, dp.o);
DrawPrimitives::drawPoint(dp.point);
}
// DebugLine
count = lines->size();
for(int c=0; c<count; c++){
DebugLine line = lines->at(c);
DrawPrimitives::setDrawColor4B(line.r, line.g, line.b, line.o);
DrawPrimitives::drawLine(line.start, line.end);
}
}
}
void DebugDraw::drawDot(
Point point,
int r, int g, int b, int o){
if(debug){
DebugPoint dp;
dp.point = point;
dp.r = r;
dp.g = g;
dp.b = b;
dp.o = o;
points->push_back(dp);
}
}
void DebugDraw::drawLine(
Point start, Point end,
int r, int g, int b, int o){
if(debug){
DebugLine line;
line.start = start;
line.end = end;
line.r = r;
line.g = g;
line.b = b;
line.o = o;
lines->push_back(line);
}
}
void DebugDraw::drawArea(int gridSize, int numX, int numY){
int width = gridSize * numX;
int height = gridSize * numY;
// draw x line
drawLine(Point(0, 0), Point(width, 0));
drawLine(Point(0, height), Point(width, height));
drawLine(Point(0, 0), Point(0, height));
drawLine(Point(width, 0), Point(width, height));
drawLine(Point(0, 0), Point(width, height));
drawLine(Point(0, height), Point(width, 0));
}
void DebugDraw::drawGrid(int gridSize, int numX, int numY){
int width = gridSize * numX;
int height = gridSize * numY;
// draw x line
for(int y=1; y<numY; y++){
if(y%5 == 0){
drawLine(Point(0, gridSize * y), Point(width, gridSize * y), 0, 0, 255, 255);
}else{
drawLine(Point(0, gridSize * y), Point(width, gridSize * y));
}
}
// draw y line
for(int x=1; x<numX; x++){
if(x%5 == 0){
drawLine(Point(gridSize * x, 0), Point(gridSize * x, height), 0, 0, 255, 255);
}else{
drawLine(Point(gridSize * x, 0), Point(gridSize * x, height));
}
}
}
void DebugDraw::clear(){
points->clear();
lines->clear();
}
//
// DebugDraw.h
// ShimejiGame
//
// Created by sdkfz181yagni on 13/09/15.
//
//
#ifndef __ShimejiGame__DebugDraw__
#define __ShimejiGame__DebugDraw__
#include "cocos2d.h"
using namespace cocos2d;
using namespace std;
USING_NS_CC;
typedef struct{
Point point;
int r;
int g;
int b;
int o;
} DebugPoint;
typedef struct{
Point start;
Point end;
float r;
float g;
float b;
float o;
} DebugLine;
class DebugDraw:public Node{
private:
bool debug;
vector<DebugPoint>* points;
vector<DebugLine>* lines;
public:
DebugDraw();
~DebugDraw();
static DebugDraw* create(bool debug);
virtual void draw(void);
void drawDot(
Point point,
int r = 255,
int g = 0,
int b = 0,
int o = 255);
void drawLine(
Point pointStart,
Point pointEnd,
int r = 255,
int g = 0,
int b = 0,
int o = 255);
void drawArea(
int gridSize,
int numX,
int numY);
void drawGrid(
int gridSize,
int numX,
int numY);
void clear();
};
#endif /* defined(__ShimejiGame__DebugDraw__) */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment