c++ tips
int hoge = 100
cout << hoge << endl; // 100
#pragma once
は重複してincludeした場合に2回目のincludeを無視してくれる
仮想関数に宣言した関数のみ、継承先のクラスでoverrideができる
#pragma once
#include "ofMain.h"
#include "Particle.h"
class Hanabi {
ofVec2f originPos;
int size;
public:
Hanabi();
virtual ~Hanabi(){};
void setPosition(float px, float py);
void setColor(int r, int g, int b, int a);
void setSize(int size);
void prepare();
void fire();
vector <Particle> sparks;
};
この場合、継承先のクラスは、Particleのdescractorを上書きできる
C++では、virtualデストラクタのないクラスは継承するつもりのないクラス(Javaでいうfinalクラス)であると考えた方がよい。
http://d.hatena.ne.jp/ajiyoshi/20080925/p1
void hoge(int size){
this->size = size;
}
array
かvector
を使う
arrayは要素数が決まってる、vectorは決まっていない
// array
Particle p[100];
// vector
vector<Particle> particles;
int i = 0;
for(; i < 100; i++){
Particle p;
particles.push_back(p);
}
vector<Particle> particles;
int i = 0;
for(; i < 100; i++){
Particle p;
particles.push_back(p);
}
particles.erase(sparks.begin() + 10); // 10番目の要素を削除
ofGraphics.hの中
void ofSetColor(int r, int g, int b); // 0-255
void ofSetColor(int r, int g, int b, int a); // 0-255
void ofSetColor(const ofColor & color);
void ofSetColor(const ofColor & color, int _a);
void ofSetColor(int gray); // new set a color as grayscale with one argument
これをsetup()に
ofSetBackgroundAuto(false); //フレーム更新時に塗り潰しを無効化
ofBackground(0, 0, 0); //背景色を黒に設定
これをdrawに
ofSetColor(0, 0, 0, 30); //半透明の黒(背景色)
ofRect(0, 0, ofGetWidth(), ofGetHeight()); //画面と同じ大きさの四角形を描画
ofSetLogLevel(OF_LOG_VERBOSE);
とsetUpに書くとdebug consoleにlogが表示される