強火で進め

このブログではプログラム関連の記事を中心に書いてます。

スプライト、シェイプを使う


※ビルド方法についてはこちらを参照。

#include <AS3/AS3.h>
#include <Flash++.h>

using namespace AS3::ui;

int main()
{
	// ステージ(Stage)を作成
	flash::display::Stage stage = internal::get_Stage();

	// シェープ(Shape)を作成
	flash::display::Shape myShape = flash::display::Shape::_new();
	// 実際に描画処理を行うのは Graphics プロパティなので使いやすい様に変数に保存
	flash::display::Graphics graphics = myShape->graphics;

	// 背景を黒で塗り潰す
	graphics->beginFill(0x000000, 1.0);
	graphics->drawRect(0, 0, stage->stageWidth, stage->stageHeight);
	graphics->endFill();
	
	// 円を描画
	graphics->beginFill(0x0000ff, 1.0);
	graphics->drawCircle(64.0, 64.0, 64.0);
	graphics->endFill();

	// ビットマップデータを作成
	flash::display::BitmapData myBitmapData = flash::display::BitmapData::_new(128, 128);

	// シェープの内容をビットマップデータに描画
	myBitmapData->draw(myShape);

	// ビットマップを作成
	flash::display::Bitmap myBitmap = flash::display::Bitmap::_new(myBitmapData);

	// スプライトを作成
	flash::display::Sprite mySprite = flash::display::Sprite::_new();

	// スプライトにビットマップデータを追加
	mySprite->addChild(myBitmap);
	
	// ステージにスプライトを追加
	stage->addChild(mySprite);

	return 0;
}