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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ch6.htm

?? 有關(guān)于游戲開發(fā)的教程我閱讀后感覺不錯所以就拿出來與大家共享。
?? 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>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲综合色婷婷| 色天天综合久久久久综合片| 日韩色视频在线观看| 亚洲成年人网站在线观看| 在线这里只有精品| 亚洲va在线va天堂| 日韩欧美在线综合网| 久久国产欧美日韩精品| 久久综合久久鬼色| 高清av一区二区| 国产精品嫩草久久久久| 91老师片黄在线观看| 一区二区三区四区视频精品免费| 一本到三区不卡视频| 亚洲国产精品一区二区久久恐怖片| 欧美日韩在线直播| 青青草国产精品97视觉盛宴| 日韩精品一区二区三区在线播放| 久久99热国产| 中文字幕亚洲一区二区va在线| 色八戒一区二区三区| 日韩电影在线免费看| 精品国产一区二区精华| a美女胸又www黄视频久久| 亚洲国产你懂的| 精品日韩99亚洲| 成人app软件下载大全免费| 一区二区三区日韩欧美| 日韩欧美在线网站| av在线播放成人| 奇米精品一区二区三区四区| 国产日产欧美一区| 欧美性高清videossexo| 黄色小说综合网站| 一区二区三区久久久| 日韩精品一区二区三区在线观看| 99久久久无码国产精品| 日韩综合小视频| 国产精品久久99| 欧美一区二区成人| 91在线观看下载| 日产欧产美韩系列久久99| 欧美国产一区二区| 欧美福利一区二区| 不卡一卡二卡三乱码免费网站| 婷婷综合另类小说色区| 中文av一区特黄| 日韩欧美国产电影| 欧美优质美女网站| 成人久久18免费网站麻豆| 免费在线看一区| 一区二区三区在线视频观看| 国产欧美中文在线| 精品国产乱码91久久久久久网站| 91国产视频在线观看| 成人激情av网| 激情成人综合网| 免费在线观看一区| 亚洲成人一区二区在线观看| 国产精品麻豆一区二区| 精品国产乱子伦一区| 欧美色区777第一页| www.亚洲精品| 国产成人精品亚洲午夜麻豆| 韩国三级在线一区| 久久成人免费网站| 免费不卡在线视频| 亚洲va国产天堂va久久en| 中文字幕一区二区三区不卡 | 亚洲女人小视频在线观看| 久久网站最新地址| 精品久久人人做人人爰| 欧美剧情电影在线观看完整版免费励志电影 | 经典三级一区二区| 性感美女久久精品| 亚洲综合无码一区二区| 亚洲视频一区在线观看| 国产精品国产三级国产普通话99 | 亚洲欧洲中文日韩久久av乱码| 国产精品三级久久久久三级| 久久精品欧美一区二区三区不卡| 久久综合久久综合亚洲| 久久久一区二区三区| 久久久一区二区| 国产拍欧美日韩视频二区| 亚洲国产精品v| 中文字幕日本不卡| 亚洲丝袜制服诱惑| 亚洲综合在线视频| 午夜欧美大尺度福利影院在线看| 亚洲一区日韩精品中文字幕| 亚洲综合色丁香婷婷六月图片| 亚洲成人动漫在线免费观看| 日韩电影在线一区二区| 国模冰冰炮一区二区| 国产伦精品一区二区三区免费迷 | 99精品国产热久久91蜜凸| 色综合久久久久综合99| 欧洲一区二区三区免费视频| 欧美精品一卡两卡| 精品久久免费看| 国产精品网站导航| 一区二区三区久久久| 日韩 欧美一区二区三区| 国产精品亚洲а∨天堂免在线| 成人做爰69片免费看网站| 91理论电影在线观看| 欧美色视频一区| 精品久久人人做人人爰| 国产精品国产精品国产专区不蜜 | 国产日韩精品一区二区三区| 亚洲情趣在线观看| 日韩不卡一区二区三区| 国产成人精品免费| 在线观看免费成人| 精品国产91乱码一区二区三区| 国产精品女主播av| 天天综合天天做天天综合| 国产一区高清在线| 在线一区二区三区四区五区 | 久久亚洲精精品中文字幕早川悠里 | 91精品国产入口| 国产精品美女一区二区三区| 亚洲一级在线观看| 大桥未久av一区二区三区中文| 在线视频欧美精品| 久久久久久久性| 亚洲美女视频一区| 久久99久久久久| 91精彩视频在线观看| 精品欧美乱码久久久久久1区2区| 国产精品乱码一区二三区小蝌蚪| 日韩精品电影在线| 99re成人在线| 精品国产乱码久久久久久夜甘婷婷| 亚洲精品五月天| 精品一区二区三区免费毛片爱| 91麻豆国产在线观看| 久久这里只有精品视频网| 亚洲电影在线播放| 99久久综合精品| 久久亚洲精品小早川怜子| 日本一区中文字幕| 欧美中文字幕一区二区三区| 久久久青草青青国产亚洲免观| 午夜久久久久久电影| 99国产精品久久久久久久久久久| 欧美成人一区二区三区| 爽好多水快深点欧美视频| 日本精品一区二区三区高清| 中文无字幕一区二区三区| 日韩高清电影一区| 欧美色欧美亚洲另类二区| 日韩理论电影院| 成人黄色综合网站| 国产精品视频看| 国产999精品久久久久久绿帽| 日韩免费一区二区| 日本中文在线一区| 欧美区在线观看| 亚洲国产精品嫩草影院| 欧美无人高清视频在线观看| 中文字幕一区二区三区乱码在线 | 一区二区国产盗摄色噜噜| a亚洲天堂av| 亚洲欧洲av另类| 99综合影院在线| 亚洲欧美日韩国产手机在线| av在线不卡电影| 亚洲男同性恋视频| 日本道在线观看一区二区| 亚洲你懂的在线视频| 色天使色偷偷av一区二区| 亚洲三级久久久| 日本道在线观看一区二区| 亚洲午夜私人影院| 欧美另类变人与禽xxxxx| 日韩av在线发布| 精品日韩一区二区三区免费视频| 极品美女销魂一区二区三区免费| 日韩精品一区二区三区三区免费 | 日韩国产欧美在线观看| 69p69国产精品| 免费xxxx性欧美18vr| 欧美成人免费网站| 国产美女娇喘av呻吟久久| 国产精品美女久久久久高潮| 91尤物视频在线观看| 亚洲不卡在线观看| 日韩一区二区在线免费观看| 国产精品亚洲午夜一区二区三区| 亚洲国产精品高清| 欧美视频一区二区三区在线观看| 午夜一区二区三区在线观看| 日韩一区二区三区精品视频| 国产成人av电影在线| 亚洲最大的成人av| 精品国偷自产国产一区| 成人免费视频国产在线观看| 亚洲综合色区另类av|