Drawing & Animation I[1]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 sonicdater 的 blog

drawing & animation

using the win32 gdi #1

this three part tutorial first appeared some years ago on the old vbexplorer.com . since then several errors and bugs have been discovered by various users on the vbexplorer.com forums. this version reflects the changes made to overcome the bugs and erros. the text will note where a bug correction and / or update has been done, and of course also why. 
a big 'thank you' goes out to all the people reading and reporting the bugs in the previous version of this tutorial. please provide comments, questions, bug reports etc. at the vbexplorer.com forums in the graphics & game programming section.

graphics

one of the most important aspects of any game are the graphics. graphics provide a visual interface for game play and more importantly, the means to explore exciting and fantastical virtual worlds. this means that cool graphics and smooth animation are key issues you will need to consider if you hope to create the right atmosphere and environment for enjoyable game play. while certainly not the only issues, they are two of the main factors that will affect the popularity and possible commercial success of your game.

download sample programs here.

graphics programming in the world of windows and gdi is largely based on bitmaps. a bitmap is a structure, generally composed of a multitude of small dots, known as pixels, each being of a specific color. a bitmap file, with the extension bmp, is the file format that will be used throughout this book to store graphical elements. we will go a bit more into what a bitmap actually is and discuss various methods to manipulate them from both a programming and a design perspective.

the gdi system is part of the win32 api. the gdi system contains the functions that draw and manipulate the visual interface of windows. the gdi system is the system we, as game programmers, are most interested in.

there are many ways to display a bitmap in visual basic. let's look a one of the simplest which is the picture property.

a standard form has a picture property, which can be used to display a bitmap. the other two controls most often used for presenting graphics in visual basic, are the image control and the picture box. of these two, the picture box is the control you are likely to use most often as a game programmer.

the main reason for using the picturebox control, instead of the image control, is that it has a hdc property. this hdc property is used when we draw bitmaps to and from our drawing areas using an api function, which we will discuss next.

an hdc is also known as a device context, or more correctly it is the handle to a device context. a device context is a win32 object, which we create in memory, which will be used to draw graphics to and from. a dc also many other associated attributes, besides the graphics attribute. among these attributes are the font, brush, pen, drawing mode which we'll discuss a little later. 

 

drawing a bitmap

most games with graphics must be able to rapidly draw several graphics repeatedly from a source context onto the destination, which would be the actual gaming area. the need for this is quite obvious, since few games are compromised of a single graphic file with no animation. certainly none that would interest a famous future game developer like you. so in order to make our games more interesting we need a way to draw a bitmap (or parts of it) from one place (the source), to another place (the destination).

the win32 api is a collection of functions, contained in various dll's, which form the backbone of windows. they include all the functions the operating system uses to handle memory, disk operations and anything else it may be called to accomplish. even though visual basic controls encapsulate a lot of this functionality, thus hiding a lot of the complexity, there is usually a performance penalty to be paid for this lack of complexity. there are also some things that you just can't do without accessing the api directly.

本文关键:Drawing & Animation
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top