Created
August 3, 2020 02:13
-
-
Save nokotan/69211b2119f2b8495d574de010187698 to your computer and use it in GitHub Desktop.
OpenSiv3D Web版でHello, Siv3D! (TextureAsset, FontAsset使用バージョン)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <Siv3D.hpp> // OpenSiv3D v0.4.3 | |
# include <emscripten.h> | |
// 猫の座標 | |
Vec2 catPos(640, 450); | |
void MainLoop() | |
{ | |
if (!s3d::System::Update()) { | |
emscripten_cancel_main_loop(); | |
return; | |
} | |
// テキストを画面の中心に描く | |
FontAsset(U"Default")(U"Hello, Siv3D!🐣").drawAt(s3d::Scene::Center(), Palette::Black); | |
// 大きさをアニメーションさせて猫を表示する | |
TextureAsset(U"cat").resized(100 + Periodic::Sine0_1(1s) * 20).drawAt(catPos); | |
// マウスカーソルに追従する半透明の赤い円を描く | |
Circle(Cursor::Pos(), 50).draw(ColorF(1, 0, 0, 0.5)); | |
// [A] キーが押されたら | |
if (KeyA.down()) | |
{ | |
// Hello とデバッグ表示する | |
Print << U"Hello!"; | |
} | |
// ボタンが押されたら | |
if (SimpleGUI::Button(U"Move the cat", Vec2(600, 20))) | |
{ | |
// 猫の座標を画面内のランダムな位置に移動する | |
catPos = RandomVec2(Scene::Rect()); | |
} | |
} | |
void Main() | |
{ | |
// 背景を水色にする | |
Scene::SetBackground(ColorF(0.8, 0.9, 1.0)); | |
// 大きさ 60 のフォントを用意 | |
FontAsset::Register(U"Default", 60); | |
// 猫のテクスチャを用意 | |
TextureAsset::Register(U"cat", Emoji(U"🐈")); | |
emscripten_set_main_loop(&MainLoop, 0, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment