Easy2d 文档教程之Game类与Window类

Game游戏类

init

初始化游戏,返回值为Bool,可以用于判断游戏是否初始化成功。
用法:

//最简单的初始化,init参数中默认
if (Game::init()) {/*初始化成功*/}
if (Game::init(L"Hello", 640, 480, L"")){/*初始化成功*/}

原型:

static bool init(
		const String& title = L"Easy2D",	/* 窗口标题 */
		int width = 640,					/* 窗口宽度 */
		int height = 480,					/* 窗口高度 */
		const String& mutexName = L""		/* 进程互斥体名称 */
	);

建议初学者直接不要填写最后一个参数,因为涉及进程互斥体的知识。
init的前三个参数分别代表窗口标题,宽度和高度。
Window类也可实现类似效果(下文)。
注意,这里的title从意义上来说也是游戏的唯一标识(AppName)。

start

启动游戏,一般是写好场景后开始
例子:

if (Game::init()) {
		auto scene = new Scene;
		auto text = new Text(L"hello");
		SceneManager::enter(scene);
		scene->addChild(text);
		Game::start();
	}

用法:

Game::start();

原型:

static void start();

pause

暂停游戏,当游戏暂停时,菜单Menu依然工作。
不太推荐初学者学习,因为涉及MenuButton
用法:

Game::pause();

原型

static void pause();

resume

继续游戏,搭配pause使用。
不太推荐初学者学习,因为涉及MenuButton
用法:

Game::resume();

原型:

static void resume();

quit

退出游戏,适合搭配KeyCodeButton类使用。
用法

Game::quit();

原型:

static void quit();

destroy

回收游戏资源,相当于清除缓存,适合搭配quit使用
用法:

Game::destroy();

原型:

static void destroy();

reset

重置游戏内部计时,原文档未给出相关获取内部计时的资料,如果有同学发现了可以在评论区提出
用法:

Game::reset();

原型:

static void reset();

isPaused

检测游戏是否暂停,配合pauseresume使用,返回值为Booltrue为暂停中,false为不处暂停中。
用法:

bool a = Game::isPaused();

原型:

static bool isPaused();

getName

获取游戏标题,返回String类型。
注意,这里String可以不加string头文件,因为String包含在easy2d头文件中。
StringS要大写。
用法:

String a = Game::getName();

原型:

static String getName();

Window窗口类

setSize和setTitle

分别设置宽高和标题。
注意这里的setTitle只是单纯的标题,而不是唯一标识符AppName,默认下将标题作为AppName
初学者只要知道他是设置标题就行了。

用法

Window::setSize(640, 480);//640是宽,480是高
Window::setTitle(L"你好");

原型:

	// 修改窗口大小
	static void setSize(
		int width,			/* 窗口宽度 */
		int height			/* 窗口高度 */
	);

	// 设置窗口标题
	static void setTitle(
		const String& title	/* 窗口标题 */
	);

各个参数意义都在注释中给出。

setIcon

设置图标。
用法:

Window::setIcon(IDR_ICON1);//将程序图标设置为IDR_ICON1的图标

原型:

// 设置窗口图标
	static void setIcon(
		int iconID
	);

这里的iconID,我们要去Visual Studio项目的资源文件中的rc文件中定义图标标识ID,如果有懂的同学请在评论区留言。

setCursor

设置鼠标指针样式

指针样式共有四种

Window::Cursor::Normal
Window::Cursor::Hand
Window::Cursor::No
Window::Cursor::Wait
Window::Cursor::ArrowWait

用法:

Window::setCursor(Window::Cursor::Normal);
Window::setCursor(Window::Cursor::Hand);
Window::setCursor(Window::Cursor::No);
Window::setCursor(Window::Cursor::Wait);
Window::setCursor(Window::Cursor::ArrowWait);

原型:

static void setCursor(
		Cursor cursor
	);

Cursor是Easy2d封装的一个鼠标指针类

getTitle

获取窗口标题,与Game::getName相似
返回值是String类型

用法

String title = Window::getTitle();

原型:

static String getTitle();

getWidth与getHeight

分别获取窗口宽高。
返回值皆为float,推荐使用double承接

用法:

double w = Window::getWidth();
double h = Window::getHeight();

原型

	// 获取窗口宽度
	static float getWidth();

	// 获取窗口高度
	static float getHeight();

getSize

获取窗口大小
此处不建议初学者使用,因为涉及Size类,Size类会在后面的文档中整合讲解。
用法

Size size = Window::getSize();

原型

static Size getSize();

getHWnd

此处不建议初学者使用,因为涉及hWnd窗口句柄部分。
获取窗口句柄,返回值为HWND类型

用法

HWND hWnd = Window::getHWnd();

原型:

static HWND getHWnd();

setTypewritingEnable

是否允许响应输入法,其第一参数决定true/false
程序默认设置为true,及允许响应输入法。
用法:

Window::setTypewritingEnable(false);//不允许
Window::setTypewritingEnable(true);//不允许

原型:

static void setTypewritingEnable(
		bool enable
	);

info、warning和error

是MessageBox的封装,
第一参数表示弹出文本,
第二参数表示窗口标题(默认为InformationWarningError
用法

Window::info(L"info", L"info");
Window::warning(L"warning", L"warning");
Window::error(L"error", L"error");

原型:

static void info(
	const String& text,					/* 内容 */
	const String& title = L"Infomation"	/* 窗口标题 */
);

// 弹出警告窗口
static void warning(
	const String& text,					/* 内容 */
	const String& title = L"Warning"	/* 窗口标题 */
);

// 弹出错误窗口
static void error(
	const String& text,					/* 内容 */
	const String& title = L"Error"		/* 窗口标题 */
);

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值