Easyx教程(一)——下载及创建窗口

本文介绍了Easyx,一个适用于C++的图形库,用于简化2D游戏编程。文章详细讲解了Easyx的下载、安装步骤,并通过创建窗口的示例代码,帮助读者快速上手。适合C++初学者和想要进行2D游戏开发的程序员。
摘要由CSDN通过智能技术生成

关于用C++做2D游戏,C++并没有提供专门的库,但是我们可以借助第三方库来实现2D游戏的制作。例如:cocos2d、Easyx、OpenGL……今天就给大家推荐其中一个我认为最简单、最好用的2D游戏引擎——Easyx。

一、Easyx简介

EasyX 是针对 C/C++ 的图形库,可以帮助使用C/C++语言的程序员快速上手图形和游戏编程。

比如,可以用 VC++ EasyX 很快的用几何图形画一个房子,或者一辆移动的小车,可以编写俄罗斯方块、贪吃蛇、黑白棋等小游戏,可以练习图形学的各种算法,等等。

  • 中文名称

    EasyX

  • 外文名称

    EasyX

  • 目标

    C/C++的图形库

  • 用途

    帮助使用C/C++语言的程序员进行图形编程

  • 操作系统版本

    Windows 2000 及以上系统

以上内容来自 360百科

二、Easyx的下载及安装

首先,肯定要到官网下载。官网网址:EasyX Graphics Library for C++

然后点击“下载EasyX”,就能获取Easyx安装程序。

接着运行Easyx安装程序,如下图所示:

 

点击“下一步”。

 

然后点击“安装”。它的安装速度很快,如果安装成功,他会提示你。

注意:这个安装程序仅支持Visual C++。

 来测试一下代码吧!

#include <graphics.h>		// 引用 EasyX 绘图库头文件
#include <conio.h>
int main(){
	initgraph(640, 480);	// 创建绘图窗口,分辨率 640x480
	circle(320, 240, 100);	// 画圆,圆心 (320, 240),半径 100
	_getch();				// 按任意键继续
	closegraph();			// 关闭图形界面
	return 0;
}

如果效果如下图,就说明安装成功了!

三、窗口创建

 首先导入easyx库。代码如下:

#include <graphics.h>  //#include <easyx.h> 也可以

窗口创建代码:

initgraph(800, 500)  //其中800是宽,500是高

为了后续更方便地操作窗口,我们可以获取窗口句柄:

HWND hwnd = GetHWnd();

然后我们可以创建一个主循环,方便后续的绘图、控制图像等操作。完整代码如下:

#include <graphics.h>
int main(){
	initgraph(800, 500);
    HWND hwnd = GetHWnd();
    while (1){  //主循环
        //代码
    }
	return 0;
}

好了,今天的教程就到这里了,我们下次再见!

  • 5
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
/****************************************************** * EasyX Library for C++ (Ver:20151015(beta)) * http://www.easyx.cn * * graphics.h * 基于 EasyX.h,实现在 VC 下实现简单绘图。 * 同时,为了兼容 Turbo C/C++ 和 Borland C/C++ 等一系 * 列开发环境中的 BGI 绘图库函数,做了相应扩展。 ******************************************************/ #pragma once #include <easyx.h> // 兼容 initgraph 绘图模式的宏定义(无实际意义) #define DETECT 0 #define VGA 0 #define VGALO 0 #define VGAMED 0 #define VGAHI 0 #define CGA 0 #define CGAC0 0 #define CGAC1 0 #define CGAC2 0 #define CGAC3 0 #define CGAHI 0 #define EGA 0 #define EGALO 0 #define EGAHI 0 // BGI 格式的初始化图形设备,默认 640 x 480 HWND initgraph(int* gdriver, int* gmode, char* path); void bar(int left, int top, int right, int bottom); // 画无边框填充矩形 void bar3d(int left, int top, int right, int bottom, int depth, bool topflag); // 画有边框三维填充矩形 void drawpoly(int numpoints, const int *polypoints); // 画多边形 void fillpoly(int numpoints, const int *polypoints); // 画填充的多边形 int getmaxx(); // 获取最大的宽度值 int getmaxy(); // 获取最大的高度值 COLORREF getcolor(); // 获取当前绘图前景色 void setcolor(COLORREF color); // 设置当前绘图前景色 void setwritemode(int mode); // 设置前景的二元光栅操作模式 /////////////////////////////////////////////////////////////////////////////////// // 以下函数仅为兼容早期 EasyX 的接口,不建议使用。请使用相关新函数替换。 // #if _MSC_VER > 1200 #define _EASYX_DEPRECATE(_NewFunc) __declspec(deprecated("This function is deprecated. Instead, use this new function: " #_NewFunc ". See http://www.easyx.cn/help?" #_NewFunc " for details.")) #define _EASYX_DEPRECATE_OVERLOAD(_Func) __declspec(deprecated("This overload is deprecated. See http://www.easyx.cn/help?" #_Func " for details.")) #else #define _EASYX_DEPRECATE(_NewFunc) #define _EASYX_DEPRECATE_OVERLOAD(_Func) #endif // 设置当前字体样式(该函数已不再使用,请使用 settextstyle 代替) // nHeight: 字符的平均高度; // nWidth: 字符的平均宽度(0 表示自适应); // lpszFace: 字体名称; // nEscapement: 字符串的书写角度(单位 0.1 度); // nOrientation: 每个字符的书写角度(单位 0.1 度); // nWeight: 字符的笔画粗细(0 表示默认粗细); // bItalic: 是否斜体; // bUnderline: 是否下划线; // bStrikeOut: 是否删除线; // fbCharSet: 指定字符集; // fbOutPrecision: 指定文字的输出精度; // fbClipPrecision: 指定文字的剪辑精度; // fbQuality: 指定文字的输出质量; // fbPitchAndFamily: 指定以常规方式描述字体的字体系列。 _EASYX_DEPRECATE(settextstyle) void setfont(int nHeight, int nWidth, LPCTSTR lpszFace); _EASYX_DEPRECATE(settextstyle) void setfont(int nHeight, int nWidth, LPCTSTR lpszFace, int nEscapement, int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut); _EASYX_DEPRECATE(settextstyle) void setfont(int nHeight, int nWidth, LPCTSTR lpszFace, int nEscapement, int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut, BYTE fbCharSet, BYTE fbOutPrecision, BYTE fbClipPrecision, BYTE fbQuality, BYTE fbPitchAndFamily); _EASYX_DEPRECATE(settextstyle) void setfont(const LOGFONT *font); // 设置当前字体样式 _EASYX_DEPRECATE(gettextstyle) void getfont(LOGFONT *font); // 获取当前字体样式 // 以下填充样式不再使用,新的填充样式请参见帮助文件 #define NULL_FILL BS_NULL #define EMPTY_FILL BS_NULL #define SOLID_FILL BS_SOLID // 普通一组 #define BDIAGONAL_FILL BS_HATCHED, HS_BDIAGONAL // /// 填充 (对应 BGI 的 LTSLASH_FILL) #define CROSS_FILL BS_HATCHED, HS_CROSS // +++ 填充 #define DIAGCROSS_FILL BS_HATCHED, HS_DIAGCROSS // xxx 填充 (heavy cross hatch fill) (对应 BGI 的 XHTACH_FILL) #define DOT_FILL (BYTE*)"\x80\x00\x08\x00\x80\x00\x08\x00" // xxx 填充 (对应 BGI 的 WIDE_DOT_FILL) #define FDIAGONAL_FILL BS_HATCHED, HS_FDIAGONAL // \\\ 填充 #define HORIZONTAL_FILL BS_HATCHED, HS_HORIZONTAL // === 填充 #define VERTICAL_FILL BS_HATCHED, HS_VERTICAL // ||| 填充 // 密集一组 #define BDIAGONAL2_FILL (BYTE*)"\x44\x88\x11\x22\x44\x88\x11\x22" #define CROSS2_FILL (BYTE*)"\xff\x11\x11\x11\xff\x11\x11\x11" // (对应 BGI 的 fill HATCH_FILL) #define DIAGCROSS2_FILL (BYTE*)"\x55\x88\x55\x22\x55\x88\x55\x22" #define DOT2_FILL (BYTE*)"\x88\x00\x22\x00\x88\x00\x22\x00" // (对应 BGI 的 CLOSE_DOT_FILL) #define FDIAGONAL2_FILL (BYTE*)"\x22\x11\x88\x44\x22\x11\x88\x44" #define HORIZONTAL2_FILL (BYTE*)"\x00\x00\xff\x00\x00\x00\xff\x00" #define VERTICAL2_FILL (BYTE*)"\x11\x11\x11\x11\x11\x11\x11\x11" // 粗线一组 #define BDIAGONAL3_FILL (BYTE*)"\xe0\xc1\x83\x07\x0e\x1c\x38\x70" // (对应 BGI 的 SLASH_FILL) #define CROSS3_FILL (BYTE*)"\x30\x30\x30\x30\x30\x30\xff\xff" #define DIAGCROSS3_FILL (BYTE*)"\xc7\x83\xc7\xee\x7c\x38\x7c\xee" #define DOT3_FILL (BYTE*)"\xc0\xc0\x0c\x0c\xc0\xc0\x0c\x0c" #define FDIAGONAL3_FILL (BYTE*)"\x07\x83\xc1\xe0\x70\x38\x1c\x0e" #define HORIZONTAL3_FILL (BYTE*)"\xff\xff\x00\x00\xff\xff\x00\x00" // (对应 BGI 的 LINE_FILL) #define VERTICAL3_FILL (BYTE*)"\x33\x33\x33\x33\x33\x33\x33\x33" // 其它 #define INTERLEAVE_FILL (BYTE*)"\xcc\x33\xcc\x33\xcc\x33\xcc\x33" // (对应 BGI 的 INTERLEAVE_FILL)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值