Created
April 2, 2017 13:07
-
-
Save azaika/0916daf30d811aa6ceda810134f21865 to your computer and use it in GitHub Desktop.
Siv3DでDxLibのLoadDivGraph関数っぽいやつ
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> | |
// image を大きさ size の画像に分割 | |
Array<Texture> makeDividedTexture(const Image& image, const Size& size) { | |
// 分割数 | |
const Size numDiv{ image.size.x / size.x, image.size.y / size.y }; | |
Array<Texture> result; | |
result.reserve(numDiv.x * numDiv.y); | |
for (auto&& p : step(numDiv)) | |
result.emplace_back(image.clipped(size * p, size)); | |
// RVO で消える | |
return result; | |
} | |
void Main() { | |
auto&& textures = makeDividedTexture(Image(L"Example/Earth.jpg"), { 256, 256 }); | |
int currentIdx = 0; | |
while (System::Update()) { | |
// 左クリックで画像推移 | |
if (Input::MouseL.clicked) | |
++currentIdx; | |
if (currentIdx >= textures.size()) | |
currentIdx = 0; | |
textures[currentIdx].drawAt(Window::Center()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment