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

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

?? ch6.htm

?? 21天學會用java開發網絡游戲 這對于 想學java編程的人會很有用
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
The <TT><FONT FACE="Courier">frameInc</FONT></TT> member variable
is used to provide a means to change the way that the animation
frames are updated. For example, in some cases you might want
the frames to be displayed in the reverse order. You can easily
do this by setting <TT><FONT FACE="Courier">frameInc</FONT></TT>
to <TT><FONT FACE="Courier">-1</FONT></TT> (its typical value
is <TT><FONT FACE="Courier">1</FONT></TT>). The <TT><FONT FACE="Courier">frameDelay</FONT></TT>
and <TT><FONT FACE="Courier">frameTrigger</FONT></TT> member variables
are used to provide a means of varying the speed of the frame
animation. You'll see how the speed of animation is controlled
when you learn about the <TT><FONT FACE="Courier">incFrame</FONT></TT>
method later today.
<P>
Another member variable that you might be curious about is <TT><FONT FACE="Courier">collision</FONT></TT>,
which is a <TT><FONT FACE="Courier">Rectangle</FONT></TT> object.
This member variable is used to support rectangle collision detection,
in which a rectangle is used in collision detection tests. You'll
see how <TT><FONT FACE="Courier">collision</FONT></TT> is used
later in today's lesson when you learn about the <TT><FONT FACE="Courier">setCollision</FONT></TT>
and <TT><FONT FACE="Courier">testCollision</FONT></TT> methods.
<P>
The last member variable, <TT><FONT FACE="Courier">hidden</FONT></TT>,
is a boolean flag that determines whether or not the sprite is
hidden. When you set this variable to true, the sprite is hidden
from view. Its default setting is true, meaning that the sprite
is visible.
<P>
The <TT><FONT FACE="Courier">Sprite</FONT></TT> class has two
constructors. The first constructor creates a <TT><FONT FACE="Courier">Sprite</FONT></TT>
without frame animations, meaning that it uses a single image
to represent the sprite. The code for this constructor is as follows:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public Sprite(Component comp, Image img,
Point pos, Point vel, int z,<BR>
&nbsp;&nbsp;int ba) {<BR>
&nbsp;&nbsp;component = comp;<BR>
&nbsp;&nbsp;image = new Image[1];<BR>
&nbsp;&nbsp;image[0] = img;<BR>
&nbsp;&nbsp;setPosition(new Rectangle(pos.x, pos.y, img.getWidth(comp),
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;img.getHeight(comp)));<BR>
&nbsp;&nbsp;setVelocity(vel);<BR>
&nbsp;&nbsp;frame = 0;<BR>
&nbsp;&nbsp;frameInc = 0;<BR>
&nbsp;&nbsp;frameDelay = frameTrigger = 0;<BR>
&nbsp;&nbsp;zOrder = z;<BR>
&nbsp;&nbsp;bounds = new Rectangle(0, 0, comp.size().width, comp.size().height);
<BR>
&nbsp;&nbsp;boundsAction = ba;<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
This constructor takes an image, position, velocity, Z-order,
and boundary action as parameters. The second constructor takes
an array of images and some additional information about the frame
animations. The code for the second constructor is as follows:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public Sprite(Component comp, Image[]
img, int f, int fi, int fd,<BR>
&nbsp;&nbsp;Point pos, Point vel, int z, int ba) {<BR>
&nbsp;&nbsp;component = comp;<BR>
&nbsp;&nbsp;image = img;<BR>
&nbsp;&nbsp;setPosition(new Rectangle(pos.x, pos.y, img[f].getWidth(comp),
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;img[f].getHeight(comp)));<BR>
&nbsp;&nbsp;setVelocity(vel);<BR>
&nbsp;&nbsp;frame = f;<BR>
&nbsp;&nbsp;frameInc = fi;<BR>
&nbsp;&nbsp;frameDelay = frameTrigger = fd;<BR>
&nbsp;&nbsp;zOrder = z;<BR>
&nbsp;&nbsp;bounds = new Rectangle(0, 0, comp.size().width, comp.size().height);
<BR>
&nbsp;&nbsp;boundsAction = ba;<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
The additional information required of this constructor includes
the current frame, frame increment, and frame delay.
<P>
The <TT><FONT FACE="Courier">Sprite</FONT></TT> class contains
a number of access methods, which are simply interfaces to get
and set certain member variables. These methods consist of one
or two lines of code and are pretty self-explanatory. Check out
the code for the <TT><FONT FACE="Courier">getVelocity</FONT></TT>
and <TT><FONT FACE="Courier">setVelocity</FONT></TT> access methods
to see what I mean about the access methods being self-explanatory:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public Point getVelocity() {<BR>
&nbsp;&nbsp;return velocity;<BR>
}<BR>
<BR>
public void setVelocity(Point vel)<BR>
{&nbsp;<BR>
&nbsp;&nbsp;velocity = vel;<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
More access methods exist for getting and setting other member
variables in <TT><FONT FACE="Courier">Sprite</FONT></TT>, but
they are just as straightforward as <TT><FONT FACE="Courier">getVelocity</FONT></TT>
and <TT><FONT FACE="Courier">setVelocity</FONT></TT>. Rather than
spending time on those, let's move on to some more interesting
methods!
<P>
The <TT><FONT FACE="Courier">incFrame</FONT></TT> method is the
first <TT><FONT FACE="Courier">Sprite</FONT></TT> method with
any real substance:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">protected void incFrame() {<BR>
&nbsp;&nbsp;if ((frameDelay &gt; 0) &amp;&amp; (--frameTrigger
&lt;= 0)) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Reset the frame trigger<BR>
&nbsp;&nbsp;&nbsp;&nbsp;frameTrigger = frameDelay;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Increment the frame<BR>
&nbsp;&nbsp;&nbsp;&nbsp;frame += frameInc;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if (frame &gt;= image.length)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;frame = 0;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;else if (frame &lt; 0)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;frame = image.length - 1;
<BR>
&nbsp;&nbsp;}<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
<TT><FONT FACE="Courier">incFrame</FONT></TT> is used to increment
the current animation frame. It first checks the <TT><FONT FACE="Courier">frameDelay</FONT></TT>
and <TT><FONT FACE="Courier">frameTrigger</FONT></TT> member variables
to see whether the frame should actually be incremented. This
check is what allows you to vary the frame animation speed for
a sprite, which is done by changing the value of <TT><FONT FACE="Courier">frameDelay</FONT></TT>.
Larger values for <TT><FONT FACE="Courier">frameDelay</FONT></TT>
result in a slower animation speed. The current frame is incremented
by adding <TT><FONT FACE="Courier">frameInc</FONT></TT> to <TT><FONT FACE="Courier">frame</FONT></TT>.
<TT><FONT FACE="Courier">frame</FONT></TT> is then checked to
make sure that its value is within the bounds of the image array,
because it is used later to index into the array when the frame
image is drawn.
<P>
The <TT><FONT FACE="Courier">setPosition</FONT></TT> methods set
the position of the sprite. The following is their source code:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">void setPosition(Rectangle pos) {<BR>
&nbsp;&nbsp;position = pos;<BR>
&nbsp;&nbsp;setCollision();<BR>
}<BR>
<BR>
public void setPosition(Point pos) {<BR>
&nbsp;&nbsp;position.move(pos.x, pos.y);<BR>
&nbsp;&nbsp;setCollision();<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
Even though the sprite position is stored as a rectangle, the
<TT><FONT FACE="Courier">setPosition</FONT></TT> methods allow
you to specify the sprite position as either a rectangle or a
point. In the latter version, the position rectangle is simply
moved to the specified point. After the position rectangle is
moved, the collision rectangle is set with a call to <TT><FONT FACE="Courier">setCollision</FONT></TT>.
<TT><FONT FACE="Courier">setCollision</FONT></TT> is the method
that sets the collision rectangle for the sprite. The source code
for <TT><FONT FACE="Courier">setCollision</FONT></TT> is as follows:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">protected void setCollision() {<BR>
&nbsp;&nbsp;collision = position;<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
Notice that <TT><FONT FACE="Courier">setCollision</FONT></TT>
sets the collision rectangle equal to the position rectangle,
which results in simple rectangle collision detection. Because
there is no way to know what sprites will be shaped like, you
leave it up to derived sprite classes to implement versions of
<TT><FONT FACE="Courier">setCollision</FONT></TT> with specific
shrunken rectangle calculations. Therefore, to implement shrunken
rectangle collision, you just calculate a smaller collision rectangle
in <TT><FONT FACE="Courier">setCollision</FONT></TT>.
<P>
This <TT><FONT FACE="Courier">isPointInside</FONT></TT> method
is used to test whether a point lies inside the sprite. The source
code for <TT><FONT FACE="Courier">isPointInside</FONT></TT> is
as follows:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">boolean isPointInside(Point pt) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;return position.inside(pt.x, pt.y);<BR>
}</FONT></TT>
</BLOCKQUOTE>
<P>
This method is very handy for determining whether the user has
clicked on a certain sprite. A good example of this is a board
game in which the user drags pieces around with the mouse. You
could implement the pieces as sprites and use the <TT><FONT FACE="Courier">isPointInside</FONT></TT>
method to see whether the mouse has clicked on one of the pieces.
<P>
The method that does most of the work in <TT><FONT FACE="Courier">Sprite</FONT></TT>
is the <TT><FONT FACE="Courier">update</FONT></TT> method, which
is shown in Listing 6.1.
<HR>
<BLOCKQUOTE>
<B>Listing 6.1. The </B><TT><B><FONT FACE="Courier">Sprite</FONT></B></TT><B>
class's </B><TT><B><FONT FACE="Courier">update</FONT></B></TT><B>
method.<BR>
</B>
</BLOCKQUOTE>
<BLOCKQUOTE>
<TT><FONT FACE="Courier">public BitSet update() {<BR>
&nbsp;&nbsp;BitSet action = new BitSet();<BR>
<BR>
&nbsp;&nbsp;// Increment the frame<BR>
&nbsp;&nbsp;incFrame();<BR>
<BR>
&nbsp;&nbsp;// Update the position<BR>
&nbsp;&nbsp;Point pos = new Point(position.x, position.y);<BR>
&nbsp;&nbsp;pos.translate(velocity.x, velocity.y);<BR>
<BR>
&nbsp;&nbsp;// Check the bounds<BR>
&nbsp;&nbsp;// Wrap?<BR>
&nbsp;&nbsp;if (boundsAction == Sprite.BA_WRAP) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if ((pos.x + position.width) &lt; bounds.x)
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.x = bounds.x + bounds.width;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;else if (pos.x &gt; (bounds.x + bounds.width))
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.x = bounds.x - position.width;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if ((pos.y + position.height) &lt; bounds.y)
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.y = bounds.y + bounds.height;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;else if (pos.y &gt; (bounds.y + bounds.height))
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.y = bounds.y - position.height;
<BR>
&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;// Bounce?<BR>
&nbsp;&nbsp;else if (boundsAction == Sprite.BA_BOUncE) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;boolean bounce = false;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;Point&nbsp;&nbsp;&nbsp;vel = new Point(velocity.x,
velocity.y);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if (pos.x &lt; bounds.x) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bounce = true;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.x = bounds.x;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vel.x = -vel.x;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;else if ((pos.x + position.width) &gt;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(bounds.x + bounds.width))
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bounce = true;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.x = bounds.x + bounds.width
- position.width;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vel.x = -vel.x;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if (pos.y &lt; bounds.y) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bounce = true;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.y = bounds.y;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vel.y = -vel.y;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;else if ((pos.y + position.height) &gt;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(bounds.y + bounds.height))
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bounce = true;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos.y = bounds.y + bounds.height
- position.height;<BR>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色综合久久久久久久久久久| 国产精品亚洲第一| 亚洲天堂网中文字| 欧美国产精品中文字幕| 国产日产欧产精品推荐色 | 自拍偷在线精品自拍偷无码专区| 久久麻豆一区二区| 国产亚洲精品bt天堂精选| 国产亲近乱来精品视频| 中文字幕欧美国产| 亚洲欧美在线另类| 一区二区三区中文字幕| 亚洲国产精品久久久久婷婷884| 洋洋成人永久网站入口| 五月综合激情网| 日韩电影免费在线| 韩国精品主播一区二区在线观看| 国产福利视频一区二区三区| av色综合久久天堂av综合| 91视频免费播放| 欧美色网一区二区| 日韩欧美国产麻豆| 欧美国产97人人爽人人喊| 亚洲视频 欧洲视频| 亚洲v中文字幕| 国产一区二区三区电影在线观看| 粗大黑人巨茎大战欧美成人| 91免费看视频| 日韩欧美一二区| 国产精品亲子伦对白| 日韩成人免费在线| 国产麻豆精品视频| 在线看日本不卡| 日韩免费在线观看| 亚洲欧美日韩人成在线播放| 丝袜亚洲另类丝袜在线| 伊人夜夜躁av伊人久久| 欧美三级欧美一级| 亚洲另类色综合网站| 成a人片国产精品| 精品va天堂亚洲国产| 亚洲精品乱码久久久久| 99在线视频精品| 久久99久久久久| 欧美日韩另类一区| 免费在线成人网| 99精品视频免费在线观看| 制服丝袜激情欧洲亚洲| 亚洲人成伊人成综合网小说| 狠狠网亚洲精品| 91精品国产综合久久久久久久久久| 国产日韩欧美电影| 久久精品国产99| 欧美日韩中字一区| 亚洲婷婷综合色高清在线| 国产一区二区免费在线| 欧美精品自拍偷拍| 亚洲精品欧美在线| 99在线精品一区二区三区| 国产色91在线| 国产乱码精品一区二区三| 欧美一区二区日韩| 日本伊人色综合网| 欧美剧情片在线观看| 亚洲一二三级电影| 欧美亚洲国产一区二区三区va | 久久婷婷综合激情| 另类小说色综合网站| 91精品国产全国免费观看| 亚洲国产精品久久人人爱| 色www精品视频在线观看| 中文字幕一区在线观看视频| 国产91清纯白嫩初高中在线观看| 久久久久久免费| 国产1区2区3区精品美女| 久久久综合激的五月天| 国产原创一区二区三区| 精品国产伦一区二区三区观看体验| 午夜欧美2019年伦理 | 亚洲一区二区三区四区不卡| 成人动漫精品一区二区| 国产精品久久久久9999吃药| 国产精品一二三区| 国产精品乱码一区二区三区软件| 成人一道本在线| 亚洲激情图片小说视频| 欧美日韩免费视频| 日日夜夜免费精品| 精品国产网站在线观看| 国产精品18久久久久久久久久久久| 国产亚洲美州欧州综合国| 成人精品高清在线| 亚洲一区二区三区不卡国产欧美| 欧美群妇大交群的观看方式| 日本强好片久久久久久aaa| 国产亚洲精久久久久久| 91蜜桃在线观看| 视频精品一区二区| 久久中文字幕电影| 99久久99久久免费精品蜜臀| 亚洲精品免费在线| 欧美大片一区二区三区| jlzzjlzz欧美大全| 视频一区中文字幕国产| 欧美激情综合在线| 欧美肥胖老妇做爰| 国产精品小仙女| 五月婷婷另类国产| 亚洲国产精品传媒在线观看| 欧美精品久久天天躁| 不卡的av在线播放| 奇米一区二区三区| 亚洲激情图片qvod| 久久精品亚洲精品国产欧美| 欧美日韩久久不卡| 99视频一区二区| 久久精品国产999大香线蕉| 樱桃国产成人精品视频| 久久一区二区三区国产精品| 欧美日韩国产另类一区| 岛国av在线一区| 免费看欧美女人艹b| 亚洲区小说区图片区qvod| 久久影音资源网| 欧美一区二区三区人| 色婷婷av一区二区三区gif| 国产一区欧美一区| 日韩福利电影在线观看| 亚洲日本在线天堂| 中文字幕乱码亚洲精品一区| 日韩精品一区二区三区swag| 欧美性高清videossexo| 91视频在线看| 丁香啪啪综合成人亚洲小说| 国产一区在线观看麻豆| 免费欧美高清视频| 视频一区二区三区在线| 亚洲一区二区中文在线| 亚洲精品少妇30p| 国产精品国产精品国产专区不片| 国产婷婷色一区二区三区| 欧美一区二区三区影视| 欧美久久久久久蜜桃| 欧美视频日韩视频在线观看| 色婷婷精品久久二区二区蜜臂av| 9色porny自拍视频一区二区| www.成人在线| 成人黄色国产精品网站大全在线免费观看 | 天天综合天天综合色| 亚洲国产日日夜夜| 亚洲小少妇裸体bbw| 亚洲一区二区在线视频| 亚洲香肠在线观看| 亚洲成人免费av| 视频一区二区欧美| 另类小说一区二区三区| 国产一区啦啦啦在线观看| 国内精品第一页| 国产成人免费9x9x人网站视频| 国产69精品一区二区亚洲孕妇| 国产成人8x视频一区二区 | 午夜精品一区在线观看| 午夜精品久久一牛影视| 麻豆国产精品官网| 精品在线播放免费| 丁香桃色午夜亚洲一区二区三区| 成人激情免费电影网址| 欧美综合亚洲图片综合区| 欧美精品色一区二区三区| 99精品久久免费看蜜臀剧情介绍| 99久久综合狠狠综合久久| 91美女在线观看| 欧美一级在线视频| 国产亚洲综合在线| 一区二区欧美国产| 蜜臀av一区二区在线免费观看 | 在线观看亚洲精品视频| 制服丝袜亚洲网站| 国产婷婷色一区二区三区四区| 亚洲欧美日韩系列| 另类小说综合欧美亚洲| 97久久精品人人做人人爽50路| 884aa四虎影成人精品一区| 久久精品人人做人人爽人人| 亚洲精品美腿丝袜| 麻豆国产欧美一区二区三区| 成人久久视频在线观看| 在线电影欧美成精品| 中文字幕 久热精品 视频在线 | 国产精品一级片在线观看| 欧美主播一区二区三区| 精品国产99国产精品| 亚洲另类在线制服丝袜| 国产精品系列在线观看| 91精品婷婷国产综合久久竹菊| 国产三级精品视频| 日韩经典一区二区| 99精品国产91久久久久久| 精品成人在线观看| 视频一区欧美精品|