4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DXライブラリにあった自動で改行して描画してくれる関数

Posted at
DxLib.h
extern int DrawObtainsString(int x, int y, int AddY, const TCHAR *String, unsigned int StrColor, unsigned int StrEdgeColor = 0, int FontHandle = -1, unsigned int SelectBackColor = 0xffffffff, unsigned int SelectStrColor = 0, unsigned int SelectStrEdgeColor = 0xffffffff, int SelectStart = -1, int SelectEnd = -1); // 描画可能領域に収まるように改行しながら文字列を描画

SetDrawArea関数で決めた領域に合わせて文字列を描画してくれる関数です。

#サンプル

#include "DxLib.h"
#include <string>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	SetOutApplicationLogValidFlag(FALSE);
	ChangeWindowMode(TRUE);
	SetDrawScreen(DX_SCREEN_BACK);

	if (DxLib_Init() < 0)
		return -1;

	int Cr = GetColor(255, 255, 255);
	std::string str = "いろはにほへと ちりぬるを わかれよたそ つねならむ ういのおくやま けふこえて\nあさきゆめみし よいもせす";

	while (ProcessMessage() == 0)
	{
		ClearDrawScreen();

		DrawObtainsString(0, 0, GetFontSize(), str.c_str(), Cr);

		ScreenFlip();
	}

	DxLib_End();
	return 0;
}

無題.png
若干見切れていますけど、そこは勘弁……。
改行コード(\n)を途中で入れると、そこで改行してくれます。

サウンドノベルとかに使えそうですけど……実際どうでしょう?


余談ですが、文字列だけではなく図形verもあります。

extern int DrawObtainsBox(int x1, int y1, int x2, int y2, int AddY, unsigned int Color, int FillFlag ); // 描画可能領域に収まるように補正を加えながら矩形を描画
4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?