亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch6.htm

?? 21天學會用java開發網絡游戲 這對于 想學java編程的人會很有用
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
sort of like another dimension-like a Z axis. You can think of
sprites moving around on the screen in the XY axis. Similarly,
the Z axis can be thought of as another axis projected into the
screen that determines how the sprites overlap each other. To
put it another way, Z-order determines a sprite's depth within
the screen. By making use of a Z axis, you might think that Z-ordered
sprites are 3D. The truth is that Z-ordered sprites can't be considered
3D because the Z axis is a hypothetical axis that is only used
to determine how sprite objects hide each other.
<P>
Just to make sure that you get a clear picture of how Z-order
works, let's go back for a moment to the good old days of traditional
animation. Traditional animators, such as those at Disney, used
celluloid sheets to draw animated objects. They drew on celluloid
sheets because the sheets could be overlaid on a background image
and moved independently. This was known as <I>cel animation</I>
and should sound vaguely familiar. (Cel animation is an early
version of sprite animation.) Each cel sheet corresponds to a
unique Z-order value, determined by where in the pile of sheets
the sheet is located. If a sprite near the top of the pile happens
to be in the same location on the cel sheet as any lower sprites,
it conceals them. The location of each sprite in the stack of
cel sheets is its Z-order, which determines its visibility precedence.
The same thing applies to sprites in cast-based animations, except
that the Z-order is determined by the order in which the sprites
are drawn, rather than the cel sheet location. This concept of
a pile of cel sheets representing all the sprites in a sprite
system will be useful later today when you develop the sprite
classes.
<H4><B>Collision Detection</B></H4>
<P>
No discussion of animation as it applies to games would be complete
without covering collision detection. <I>Collision detection</I>
is simply the method of determining whether sprites have collided
with each other. Although collision detection doesn't directly
play a role in creating the illusion of movement, it is tightly
linked to sprite animation and extremely crucial in games.
<P>
<I>Collision detection</I> is the process of determining whether
sprites have collided with each other.
<P>
Collision detection is used to determine when sprites physically
interact with each other. In an Asteroids game, for example, if
the ship sprite collides with an asteroid sprite, the ship is
destroyed. Collision detection is the mechanism employed to find
out whether the ship collided with the asteroid. This might not
sound like a big deal; just compare their positions and see whether
they overlap, right? Correct, but consider how many comparisons
must take place when lots of sprites are moving around; each sprite
must be compared to every other sprite in the system. It's not
hard to see how the overhead of effective collision detection
can become difficult to manage.
<P>
Not surprisingly, there are many approaches to handling collision
detection. The most simple approach is to compare the bounding
rectangles of each sprite with the bounding rectangles of all
the other sprites. This method is very efficient, but if you have
objects that are not rectangular, a certain degree of error occurs
when the objects brush by each other. This is because the corners
might overlap and indicate a collision when really only the transparent
areas are overlapping. The more irregular the shape of the sprites,
the more error typically occurs. Figure 6.1 shows how simple rectangle
collision works.
<P>
<A HREF="f6-1.gif" ><B>Figure 6.1 : </B><I>Collision detection using simple rectangle collision.</I></A>
<P>
In Figure 6.1, the areas determining the collision detection are
shaded. You can see how simple rectangle collision detection isn't
very accurate, unless you're dealing with sprites that are rectangular
in shape. An improvement on this technique is to shrink the collision
rectangles a little, which reduces the corner error. This method
improves things a little, but it has the potential of causing
error in the reverse direction by allowing sprites to overlap
in some cases without signaling a collision. Figure 6.2 shows
how shrinking the collision rectangles can improve the error on
simple rectangle collision detection. Shrunken rectangle collision
is just as efficient as simple rectangle collision because all
you are doing is comparing rectangles for intersection.
<P>
<A HREF="f6-2.gif" ><B>Figure 6.2 : </B><I>Collision detection using shrunken rectangle collision.</I></A>
<P>
The most accurate collision detection technique is to detect collision
based on the sprite image data, which involves actually checking
to see whether transparent parts of the sprite or the sprite images
themselves are overlapping. In this case, you get a collision
only if the actual sprite images are overlapping. This is the
ideal technique for detecting collisions because it is exact and
allows objects of any shape to move by each other without error.
Figure 6.3 shows collision detection using the sprite image data.
<P>
<A HREF="f6-3.gif" ><B>Figure 6.3 : </B><I>Collision detection using sprite image data.</I></A>
<P>
Unfortunately, the technique shown in Figure 6.3 requires far
more overhead than rectangle collision detection and is often
a major bottleneck in performance. Furthermore, implementing image
data for collision detection can get very messy. Considering these
facts, it's safe to say that you won't be worrying about image
data collision detection in this book. It might be an avenue worth
considering in the future if the just-in-time Java compilers can
squeeze enough additional performance out of Java, and if you
are willing to dig into the programming complexities involved
in pulling it off.
<H2><A NAME="ImplementingSpriteAnimation"><B><FONT SIZE=5 COLOR=#FF0000>Implementing
Sprite Animation</FONT></B></A></H2>
<P>
As you learned earlier in today's lesson, sprite animation involves
the movement of individual graphic objects called sprites. Unlike
simple frame animation, sprite animation involves considerably
more overhead. More specifically, it is necessary to develop not
only a sprite class, but also a sprite management class for keeping
up with all the sprites in the system. This is necessary because
sprites need to be able to interact with each other through a
common mechanism. Furthermore, it is useful to extract the background
behind the sprites into a class of its own.
<P>
In this section, you learn how to implement sprite animation in
Java by creating a suite of sprite classes. The primary sprite
classes are <TT><FONT FACE="Courier">Sprite</FONT></TT> and <TT><FONT FACE="Courier">SpriteVector</FONT></TT>.
However, there are also a few support classes that you will learn
about as you get into the details of these two primary classes.
The <TT><FONT FACE="Courier">Sprite</FONT></TT> class models a
single sprite and contains all the information and methods necessary
to get a single sprite up and running. However, the real power
of sprite animation is harnessed by combining the <TT><FONT FACE="Courier">Sprite</FONT></TT>
class with the <TT><FONT FACE="Courier">SpriteVector</FONT></TT>
class, which is a container class that manages multiple sprites
and their interaction with each other.
<H3><A NAME="TheSpriteClass"><B>The </B><TT><B><FONT SIZE=4 FACE="Courier">Sprite</FONT></B></TT><B><FONT SIZE=4>
Class</FONT></B></A></H3>
<P>
Although sprites can be implemented simply as moveable graphical
objects, you saw earlier that the sprite class developed here
will also contain support for frame animation. A frame- animated
sprite is basically a sprite with multiple frame images that can
be displayed in succession. The <TT><FONT FACE="Courier">Sprite</FONT></TT>
class you are about to see supports frame animation in the form
of an array of frame images and some methods for setting the current
frame image. Using this approach, you end up with a <TT><FONT FACE="Courier">Sprite</FONT></TT>
class that supports both fundamental types of animation and is
much more suitable for Java games.
<P>
Before jumping into the details of how the <TT><FONT FACE="Courier">Sprite</FONT></TT>
class is implemented, take a moment to think about the different
pieces of information that a sprite must keep up with. When you
understand the components of a sprite at a conceptual level, it
will be much easier to understand the Java code. So, exactly what
information should a <TT><FONT FACE="Courier">Sprite</FONT></TT>
class maintain? The following list contains the key information
that the <TT><FONT FACE="Courier">Sprite</FONT></TT> class needs
to include:
<UL>
<LI>Array of frame images
<LI>Current frame
<LI>XY position
<LI>Velocity
<LI>Z-order
<LI>Boundary
</UL>
<P>
The first component, an array of frame images, is necessary to
carry out the frame animations. Even though this sounds like you
are forcing a sprite to have multiple animation frames, a sprite
can also use a single image. In this way, the frame animation
aspects of the sprite are optional. The current frame keeps up
with the current frame of animation. In a typical frame- animated
sprite, the current frame is incremented to the next frame when
the sprite is updated.
<P>
The XY position stores the position of the sprite. You can move
the sprite simply by altering this position. Alternatively, you
can set the velocity and let the sprite alter its position internally.
<P>
The Z-order represents the depth of the sprite in relation to
other sprites. Ultimately, the Z-order of a sprite determines
its drawing order (more on that a little later).
<P>
Finally, the boundary of a sprite refers to the bounded region
in which the sprite can move. All sprites are bound by some region-usually
the size of the applet window. The sprite boundary is important
because it determines the limits of a sprite's movement.
<P>
Now that you understand the core information required by the <TT><FONT FACE="Courier">Sprite</FONT></TT>
class, it's time to get into the specific Java implementation.
Keep in mind that the <TT><FONT FACE="Courier">Sprite</FONT></TT>
class contains all the features necessary to implement sprites
in the sample games throughout the rest of the book. Let's begin
with the <TT><FONT FACE="Courier">Sprite</FONT></TT> class's member
variables, which follow:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public static final int&nbsp;SA_KILL
= 0,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SA_RESTOREPOS
= 1,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n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
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;frameTrigger;
<BR>
protected Rectangle&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;position,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;collision;
<BR>
protected int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zOrder;
<BR>
protected Point&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;velocity;
<BR>
protected Rectangle&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bounds;<BR>
protected int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;boundsAction;
<BR>
protected boolean&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hidden
= false;</FONT></TT>
</BLOCKQUOTE>
<P>
The member variables include the important sprite information
mentioned earlier, along with some other useful information. Most
notably, you are probably curious about the static final members
at the beginning of the listing. These members are constant identifiers
that define actions for the sprite. Two different types of actions
are supported by <TT><FONT FACE="Courier">Sprite</FONT></TT>:
sprite actions and bounds actions. <I>Sprite actions</I> are general
actions that a sprite can perform, such as killing itself or adding
another sprite. <I>Bounds actions</I> are actions that a sprite
takes in response to reaching a boundary, such as wrapping to
the other side or bouncing. Unlike sprite actions, bounds actions
are mutually exclusive, meaning that only one can be set at a
time.
<P>
After the actions, the <TT><FONT FACE="Courier">Component</FONT></TT>
member variable is the next member variable that you might be
curious about. It is necessary because an <TT><FONT FACE="Courier">ImageObserver</FONT></TT>
object is required to retrieve information about an image. But
what does <TT><FONT FACE="Courier">Component</FONT></TT> have
to do with <TT><FONT FACE="Courier">ImageObserver</FONT></TT>?
The <TT><FONT FACE="Courier">Component</FONT></TT> class implements
the <TT><FONT FACE="Courier">ImageObserver</FONT></TT> interface,
and the <TT><FONT FACE="Courier">Applet</FONT></TT> class is derived
from <TT><FONT FACE="Courier">Component</FONT></TT>. So, a <TT><FONT FACE="Courier">Sprite</FONT></TT>
object gets its image information from the Java applet itself,
which is used to initialize the <TT><FONT FACE="Courier">Component</FONT></TT>
member variable.
<P>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><B>Note</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
<TT><FONT FACE="Courier">ImageObserver</FONT></TT> is an interface defined in the <TT><FONT FACE="Courier">java.awt.image</FONT></TT> package that provides a means for receiving information about an image.
</BLOCKQUOTE>

</TD></TR>
</TABLE></CENTER>
<P>
<P>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色诱视频网站一区| 亚洲日本在线天堂| 自拍偷拍亚洲综合| 日本午夜精品视频在线观看| 国产91丝袜在线观看| 欧美三级韩国三级日本一级| 久久久国产精华| 日本美女一区二区三区视频| 99这里只有精品| 26uuu欧美| 日本在线不卡视频| 欧美日本视频在线| 一区二区三区日韩| 本田岬高潮一区二区三区| 日韩视频免费直播| 日本不卡一二三| 在线观看视频一区二区欧美日韩| 国产精品久久午夜| 国产成人av网站| 久久蜜桃一区二区| 国产中文字幕精品| 欧美一区二区三区在线| 天天色天天操综合| 欧美日韩午夜在线| 亚洲精品老司机| av激情亚洲男人天堂| 久久麻豆一区二区| 精品一区二区三区不卡| 欧美一区午夜精品| 亚洲国产一区视频| 欧美日韩1区2区| 亚洲国产另类av| 91成人在线精品| 亚洲综合小说图片| 欧美日韩免费电影| 人人超碰91尤物精品国产| 欧美一区二区日韩| 久久se精品一区二区| 精品三级av在线| 国产高清久久久久| 亚洲天堂免费在线观看视频| 91视频91自| 亚洲国产精品自拍| 日韩视频一区二区在线观看| 久久se精品一区精品二区| 精品久久久久久无| 国产白丝精品91爽爽久久| 国产精品无人区| 在线观看一区不卡| 麻豆成人在线观看| 国产日韩精品一区二区三区在线| 成人一道本在线| 亚洲一区免费观看| 91精品婷婷国产综合久久| 久久99国产精品久久99果冻传媒| 精品第一国产综合精品aⅴ| 国产 欧美在线| 亚洲一区在线视频观看| 91精品蜜臀在线一区尤物| 另类欧美日韩国产在线| 国产午夜精品美女毛片视频| 91视频在线看| 蜜桃av一区二区| 中文字幕欧美一区| 欧美日韩国产在线播放网站| 久久97超碰色| 亚洲自拍偷拍图区| 欧美精品一区二区三区视频| 不卡一区二区在线| 天堂一区二区在线免费观看| 久久精品一区二区| 欧美中文字幕不卡| 国产一区欧美一区| 亚洲午夜精品在线| 国产欧美一区二区三区网站| 欧美色成人综合| 懂色av噜噜一区二区三区av| 日日摸夜夜添夜夜添亚洲女人| 中文欧美字幕免费| 欧美一级片在线观看| 成人av资源在线观看| 日本不卡中文字幕| 成人欧美一区二区三区黑人麻豆 | 精品电影一区二区三区| 一本久久a久久免费精品不卡| 麻豆精品一区二区| 一区二区在线免费| 中文字幕欧美激情一区| 日韩亚洲欧美综合| 欧美日韩国产高清一区二区 | 中文字幕欧美三区| 日韩一区二区在线播放| 日本韩国欧美国产| 93久久精品日日躁夜夜躁欧美| 亚洲成人免费影院| 1000精品久久久久久久久| 日韩欧美在线一区二区三区| 欧美视频一区在线| 日本韩国欧美一区二区三区| 成人精品鲁一区一区二区| 久久成人免费日本黄色| 视频一区欧美精品| 亚洲午夜精品在线| 亚洲va在线va天堂| 亚洲国产日韩综合久久精品| 综合av第一页| 中文字幕一区二区三区av| 日本一区二区视频在线| 国产婷婷色一区二区三区在线| 日韩欧美国产不卡| 日韩欧美国产综合一区| 日韩一区二区影院| 欧美变态tickle挠乳网站| 欧美一级xxx| 日韩女优制服丝袜电影| 欧美一区二区三区公司| 在线播放视频一区| 欧美一区二区三区在线看| 欧美一区二区三区小说| 欧美成人在线直播| 亚洲精品在线观看网站| 久久综合色天天久久综合图片| 久久综合中文字幕| 欧美激情综合五月色丁香| 国产农村妇女毛片精品久久麻豆| 久久新电视剧免费观看| 国产欧美视频一区二区| 国产精品免费免费| 亚洲特级片在线| 亚洲高清视频中文字幕| 亚洲成人激情社区| 久久99热国产| 粉嫩在线一区二区三区视频| 91丨九色丨黑人外教| 精品视频1区2区| 精品国产污污免费网站入口 | 精品欧美乱码久久久久久1区2区| 久久影音资源网| 国产精品乱码人人做人人爱| 亚洲男人天堂av网| 日韩精品一二区| 国产福利91精品一区| 色哟哟在线观看一区二区三区| 欧美日韩亚洲丝袜制服| 久久久99久久精品欧美| 亚洲女爱视频在线| 亚洲午夜久久久久| 国产精品123| 欧洲精品一区二区三区在线观看| 精品三级av在线| 亚洲日本成人在线观看| 麻豆freexxxx性91精品| 97超碰欧美中文字幕| 精品少妇一区二区三区免费观看 | 精品区一区二区| 亚洲理论在线观看| 国产又黄又大久久| 91久久线看在观草草青青| 91精品综合久久久久久| 综合中文字幕亚洲| 蜜臀av一区二区三区| 91首页免费视频| 国产午夜精品一区二区三区四区| 亚洲午夜免费电影| av在线播放成人| 精品免费国产一区二区三区四区| 亚洲人亚洲人成电影网站色| 免费精品视频在线| 一本色道亚洲精品aⅴ| 久久新电视剧免费观看| 亚洲成av人影院| 日本电影亚洲天堂一区| 欧美国产日韩亚洲一区| 国内精品久久久久影院薰衣草| 色系网站成人免费| 国产亚洲一二三区| 久久 天天综合| 欧美精品在线观看播放| 一区二区三区小说| av在线播放不卡| 国产精品美女一区二区在线观看| 日本美女视频一区二区| 欧美日本视频在线| 亚洲成a人v欧美综合天堂下载| 99久久99久久精品免费看蜜桃| 久久青草欧美一区二区三区| 经典一区二区三区| 日韩视频免费观看高清完整版在线观看 | 精品国产123| 久久国产精品99久久久久久老狼 | 精品视频一区三区九区| 亚洲综合一区二区精品导航| 色综合色狠狠综合色| 日韩毛片在线免费观看| 一本久道久久综合中文字幕| 国产精品久久久久久久久免费丝袜 | 国产 日韩 欧美大片| 国产婷婷色一区二区三区在线| 狠狠v欧美v日韩v亚洲ⅴ| 日韩欧美亚洲国产精品字幕久久久|