📄 ch4.htm
字号:
used too much in games. On the other hand, <I>video-captured graphics</I>,
which rely on a very similar concept, have been used a great deal;
these graphics were used in DOOM. Using video-captured graphics
involves setting up a video camera and grabbing frames of video
of an object as bitmapped images. Video-captured graphics differ
from video sequences in that video-captured graphics are used
to generate snapshots of different views of an object, and not
a real-time animation.
<P>
This technique is useful primarily because it enables you to create
real-world models of the objects in your game and then convert
them to images automatically. The primary problem with video capturing
is that the resulting images have a broad range of colors that
usually have to be dithered down to the 256-color GIF format.
However, sometimes an optimized palette can help yield better
results.
<P>
<I>Dithering</I> is a process in which the colors in an image
are reduced to a lesser amount of colors. This is carried out
by using different patterns of the lesser colors to represent
the colors lost. Many graphics editors provide dithering features.
<P>
The only other problem with video capturing is that it usually
involves having to build a small video studio with lighting and
a backdrop, not to mention buying the video camera and video hardware
that supports NTSC (National Television Standards Committee) video
input. You also have to be able to somehow construct physical
models of the game objects. However, if you are willing to go
the extra step and do these things, the results certainly are
worth the trouble.
<P>
<I>NTSC video</I> is the type of video signal used by many televisions,
VCRs, and video cameras. To be able to retrieve images in this
format, you need to have graphics hardware that supports NTSC
input.
<H3><A NAME="BackgroundGraphicsandTextures"><B>Background Graphics
and Textures</B></A></H3>
<P>
<I>Background graphics</I> are any graphics that appear behind
the main objects in the game, such as walls, forests, clouds,
and so on.
<P>
Many background graphics, such as walls, benefit from textured
bitmap images.
<P>
A <I>texture</I> is an image that models a piece of a graphical
surface that can be tiled without notice.
<P>
Textures are very useful primarily because they take up relatively
little space; this is because they are tiled repeatedly to create
a larger image at runtime. I highly recommend using textures whenever
possible. You've no doubt already seen many textures at work as
backgrounds in Web pages.
<P>
There are libraries of royalty-free textures that often serve
as a good resource. Of course, you are free to draw your own textures,
but be warned that drawing a textured image so that it can be
tiled correctly with the edges blending smoothly is pretty tricky.
Although textures are nice for creating tiled backgrounds, you
can also draw the background graphics as complete images; just
remember that the size of the images will usually increase. You
can find much texture artwork at The Clip Art Connection Web site,
which you learn about a little later today in the "Finding
Graphics" section.
<H3><A NAME="AnimatedGraphics"><B>Animated Graphics</B></A></H3>
<P>
Although you don't learn about the details of animation until
later this week, it's okay now to look at the graphical requirements
of animated graphics. Because animation typically involves a series
of images, most animated graphics will be in the form of a series
of animation frame images.
<P>
The animation frames for an object in a game sometimes are referred
to as <I>phases</I> of the object. The phases depict the movements
that the object goes through independent of positional motion.
The phase animations usually mean different things for different
objects. A fire object might have four frames of animation that
depict the movement of the flames, for example. On the other hand,
a tank's phases in a battle game might consist of the rotations
of the tank. Figure 4.6 shows these two types of animation frames.
<P>
<A HREF="f4-6.gif" ><B>Figure 4.6 : </B><I>Animation frames for a fire and a tank.</I></A>
<P>
It also is possible for objects to change phase in more than one
way. In this case, you will have a two-dimensional array of animation
frames rather than a horizontal strip. An example would be a crawling
soldier with different animations reflecting the crawling motion.
You might have eight rotations for the soldier along with two
different frames to show the leg and arm crawling movement. Figure
4.7 shows how these animations might look.
<P>
<A HREF="f4-7.gif" ><B>Figure 4.7 : </B><I>Animation frames for a crawling soldier.</I></A>
<P>
Practically speaking, you would need more frames of animation
than these examples show, especially when it comes to rotation.
Four frames is hardly enough to depict smooth rotation of an object.
I recommend a minimum of eight frames when you are showing an
object rotating, unless the object is very small, in which case
four frames might work.
<P>
I mentioned earlier that the GIf89a image format supports animation
by enabling you to include multiple frame images in a single GIF
image. Unfortunately, the current release of Java doesn't support
animated GIF images, so you'll have to implement Java animations
using multiple separate GIF images. You learn much more about
this later this week on <A HREF="ch6.htm" >Day 6</A>, "Sprite
Animation."
<H2><A NAME="FindingGraphics"><B><FONT SIZE=5 COLOR=#FF0000>Finding
Graphics</FONT></B></A></H2>
<P>
If you've decided that creating game graphics isn't for you, you
have a few options. The first is to try to find royalty-free art.
This isn't always a very viable option, because games typically
require very unique graphics. However, you might be able to find
interesting clip art that will work for your game graphics. The
last thing I want to do is to discourage you from trying a possibly
useful outlet for obtaining graphics.
<P>
A good starting point for finding existing clip-art graphics is
The Clip Art Connection Web site, which is located at <TT><A HREF="http://www.acy.digex.net/~infomart/clipart/index.html">http://www.acy.digex.net/~infomart/clipart/index.html</A></TT>.
The Clip Art Connection contains links to many different clip-art
sites, as well as sites to artists and commercial stock art collections.
This site is definitely worth checking out! Figure 4.8 shows what
The Clip Art Connection Web site looks like.
<P>
<A HREF="f4-8.gif" ><B>Figure 4.8 : </B><I>The Clip Art Connection Web site.</I></A>
<P>
Another option, and the one I suggest when you don't have the
ability to create your own graphics, is to hire an artist to draw
or render the graphics for you. You might be surprised by how
inexpensive it can be; some people might even be willing to draw
the graphics for free just to be involved in a Java game (just
don't forget to give them full credit, a free copy of the end
product, and probably a nice thank-you card or e-mail).
<P>
The best place to look for artists is on the Internet or online
services such as CompuServe. Finding artists through one of these
channels has an additional benefit; the artists are probably already
comfortable with computers and software drawing tools. This will
ease the communication gap between you and them. Additionally,
they probably will already have a scanner and can handle any image
conversions. Some of the art-related forums on CompuServe are
the Artist Forum (ARTIST), Computer Art Forum (COMART), and the
Computer Animation Forum (COMANI). On the Internet, you can either
search for artists using one of the popular search engines, such
as Yahoo!, or you can start with the artist list provided at The
Clip Art Connection Web site.
<P>
Before you contact an artist, be sure to have a very solid idea
of what you want. It's a good idea to write down all your thoughts
on the game and what it should look like, including sketches or
written descriptions of the graphics. The better the communication
between you and the artist, the more likely he or she will deliver
graphics to your liking. You might want to ask for some samples
of the artist's work to check out the style and see whether it
matches what you have in mind. The last step is to work up a formal
agreement with the artist, outlining exactly what is expected
on both ends of the deal, along with a due date that is agreeable
to both parties.
<H2><A NAME="Summary"><B><FONT SIZE=5 COLOR=#FF0000>Summary</FONT></B></A>
</H2>
<P>
Today's lesson covered the basics of creating graphics for games.
Along with establishing what is required of game graphics, you
learned about some specific techniques for creating them. Unfortunately,
I don't have the space (or the qualifications!) to try to teach
you art, which is exactly what game graphics are. If you are weak
in the art area, you might want to hire an artist to draw or render
the graphics for your game.
<P>
The main goal today was to give you enough background information
about game graphics to give you a better idea of what you will
need to create graphics for your own games. As fun as creating
graphics can be, the real joy is seeing them in action. Tomorrow's
lesson gets into the specifics of using graphics in Java.
<H2><A NAME="QA"><B><FONT SIZE=5 COLOR=#FF0000>Q&A</FONT></B></A>
<BR>
</H2>
<TABLE>
<TR VALIGN=TOP><TD WIDTH=50><B>Q</B></TD><TD><B>Does Java support any image formats other than GIF?</B>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=50><B>A</B></TD><TD>Yes. Java also supports the JPEG image format, which is geared more toward photographic images.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=50><B>Q</B></TD><TD><B>If the GIF format supports only 256 colors, what do I do about images using more than 256 colors?</B>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=50><B>A</B></TD><TD>The reality is that you can have a maximum of 256 colors in GIF images, and therefore a maximum of 256 colors in your game graphics. However, you can side-step this limitation a little by using a graphics
utility to dither images that have more colors down to 256-color GIF images.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=50><B>Q</B></TD><TD><B>I have no artistic abilities, I haven't found any interesting graphics on the Web, and I don't know if I can afford hiring an artist. Is there anything I </B>can do?
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=50><B>A</B></TD><TD>Yes! In this case, your best bet is to buy a color scanner and start looking for interesting artwork everywhere you go. The best source is to look in bookstores for stock art books. I have a little confession to
make: Much of the artwork used for games in this book was scanned from stock art books and then resized, colored, and cleaned up using a graphics editor. I'm not incredibly artistic, just resourceful!
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=50><B>Q</B></TD><TD><B>I have a game idea that has graphics consisting of lines, rectangles, and other simple graphics primitives. Do I still need to create images?</B>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=50><B>A</B></TD><TD>Absolutely not. If your game needs only graphics primitives, you can easily use the Java awt graphics features to generate the graphics at runtime. This is cool because it completely eliminates the delays
associated with transferring images over the Internet.
</TD></TR>
</TABLE>
<P>
<H2><A NAME="Workshop"><B><FONT SIZE=5 COLOR=#FF0000>Workshop</FONT></B></A>
</H2>
<P>
The Workshop section provides questions and exercises to help
you get a better feel for the material you learned today. Try
to answer the questions and at least peruse the exercises before
moving on to tomorrow's lesson. You'll find the answers to the
questions in appendix A, "Quiz Answers."
<H3><A NAME="Quiz"><B>Quiz</B></A></H3>
<OL>
<LI>Who created the GIF image format and why?
<LI>What is interlacing?
<LI>What is dithering?
<LI>What is a phased graphical object?
<LI>What things should you consider when hiring an artist?
</OL>
<H3><A NAME="Exercises"><B>Exercises</B></A></H3>
<OL>
<LI>Play a few commercial games and pay special attention to the
style of the graphics used in different scenes.
<LI>Find a cool graphics editor and learn how to use its basic
features.
<LI>Get on the Web and check out some of the clip-art graphics
archives. See anything that might be useful in a game?
<LI>Connect to the Imaging Machine Web site and try it out on
some of the clip-art graphics you found.
</OL>
<P>
<HR WIDTH="100%"></P>
<CENTER><P><A HREF="ch3.htm"><IMG SRC="pc.gif" BORDER=0 HEIGHT=88 WIDTH=140></A><A HREF="index.htm"><IMG SRC="hb.gif" BORDER=0 HEIGHT=88 WIDTH=140></A><A HREF="#CONTENTS"><IMG SRC="cc.gif" BORDER=0 HEIGHT=88 WIDTH=140></A><A HREF="ch5.htm"><IMG
SRC="nc.gif" BORDER=0 HEIGHT=88 WIDTH=140></A></P></CENTER>
<P>
<HR WIDTH="100%"></P>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -