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

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

?? the java game programming tutorial part iv.htm

?? 不錯的JAVA書
?? HTM
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0057)http://www.intergate.bc.ca/personal/iago/javatut/jtp4.htm -->
<HTML><HEAD><TITLE>The Java Game Programming Tutorial: Part IV</TITLE>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<META content="Garry Morse" name=Author>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR>
<META content="An expanding tutorial on Java 2D/3D game programming" 
name=Description>
<META 
content=Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java 
name=KeyWords></HEAD>
<BODY aLink=#ff0000 bgColor=#ffdfdf link=#0000ee text=#000000 vLink=#551a8b>
<H1><A href="http://www.intergate.bc.ca/personal/iago/javatut/index.htm"><IMG 
align=ABSCENTER border=0 height=85 
src="The Java Game Programming Tutorial Part IV_ficheiros/coffee.gif" 
width=116></A><FONT color=#804040><FONT size=+2><A 
href="http://www.intergate.bc.ca/personal/iago/javatut/index.htm">The Java Game 
Programming Tutorial</A></FONT></FONT></H1>
<H1>
<HR width="100%">
</H1>
<H2>Part IV:&nbsp;What about Double Buffering?</H2>
<UL>
  <P>Now we have images loaded and doing something the next topic<BR>on the 
  agenda is flicker. Although simplistic animations or<BR>slideshows run fairly 
  well, as more drawing is done to the<BR>viewing window in advanced applets, 
  one can begin to see the<BR>screen refresh causing a flicker. </P></UL>
<UL>
  <P>I would say this is the bane of the animator or game developer<BR>because 
  many solutions exist on a variety of platforms to speed<BR>up rendering. 
  Either built into the hardware or programmed in<BR>the software, the most 
  common solution is double buffering. </P>
  <P>Double buffering is the process of storing a copy of the screen<BR>in a 
  section of memory and doing all drawing to this canvas as<BR>if it were the 
  screen. Since all drawing is being done off the<BR>screen, the only drawing 
  onscreen is the actual copying of the<BR>buffer to the screen which can be 
  timed to avoid the refresh. </P>
  <P>Some systems or environments have automatic buffering which<BR>means little 
  or no programming. My experience in low level<BR>DOS has taught me this can 
  mean extensive coding for speedy<BR>animation. Thankfully, in Java it is 
  really only a matter of<BR>redirection from what we've doing so far. </P>
  <P>These lessons are compressed to be building blocks for bigger<BR>and better 
  applets. Otherwise, there might be ten versions of<BR>Hello world (yikes!) and 
  I refuse to insult your intelligence<BR>this way. At this juncture, I must 
  cram more information about<BR>sprite images relevant to the example. </P>
  <P>A good thing about gif files is that you can make transparent<BR>gifs quite 
  easily using many paint programs and image utilities.<BR>This fact allows gif 
  images which aren't rectangular to keep<BR>their fine figure and blend in with 
  whatever background we like. </P>
  <P>In <A href="http://www.intergate.bc.ca/personal/iago/javatut/jtp3.htm">Part 
  3</A>, an image array was created to load in each sketch<BR>or picture. This 
  is alright for a slideshow of variable images<BR>but bad in the case of small 
  identical images. Bad because each<BR>image requires an established HTTP 
  connection which can be slow.<BR>A good solution is to store your images side 
  by side like so: </P>
  <UL>
    <P><IMG height=40 
    src="The Java Game Programming Tutorial Part IV_ficheiros/guy.gif" 
    width=64></P></UL>
  <P>Only a single image connection is required for this image strip<BR>which 
  can be drawn easily with a slight adjustment. Since the<BR>previous tutorial 
  sections cover applet structure and graphics<BR>techniques, I will just 
  elaborate on new or changed code. </P><PRE>  <B>Image offscreenImage;
  Graphics offscreenGraphics;</B></PRE>
  <P>These two objects are added to the applet to implement double<BR>buffering. 
  The first is the familiar image object which serves<BR>as the image buffer 
  itself. The second is a graphics context<BR>or handle for reference to the 
  image buffer. </P><PRE>  <B>Image imageBackground; 
  Image spriteStrip;</B></PRE>
  <P>These are just less important images for drawing. The first is<BR>a 
  background image to make a backdrop for the sprite. The next<BR>is the sprite 
  image strip. I've decided to omit explaining the<BR>init method. Image loading 
  was discussed in <A 
  href="http://www.intergate.bc.ca/personal/iago/javatut/jtp3.htm">Part 3</A>. 
  </P><PRE>    <B>offscreenImage = createImage(this.size().width,
                                 this.size().height);
    offscreenGraphics = offscreenImage.getGraphics();</B></PRE>
  <P>This conditional initialization code is added to the paint method.<BR>The 
  method createImage is used to create an offscreen buffer image<BR>the size of 
  the applet window. The image method getGraphics is used<BR>to get a graphics 
  context. This is excellent because we can draw to<BR>the double buffer exactly 
  as if it were the screen. </P><PRE>    <B>spriteWidth = spriteStrip.getWidth(this) / spriteCount;
    spriteHeight = spriteStrip.getHeight(this);</B></PRE>
  <P>Here, the variable spriteCount is used to calculate the 
  independent<BR>image width, assuming each is the same width. The height is 
  the<BR>same as the strip height because it is a row of images. </P><PRE>    <B>offscreenGraphics.drawImage(imageBackground,0,0,this);</B></PRE>
  <P>This is the same method used in <A 
  href="http://www.intergate.bc.ca/personal/iago/javatut/jtp3.htm">Part 3</A> 
  but note how our own graphics<BR>context is used. We could draw lines or 
  circles, etc. In this case,<BR>our background image is copied into the 
  offscreen buffer. Redrawing<BR>the background every frame is rather 
  inefficient but I'll go over a<BR>better design later. For this purpose, it's 
  okay. </P><PRE>   <B>offscreenGraphics.clipRect(spriteX,spriteY,
                              spriteWidth,spriteHeight);</B></PRE>
  <P>This code above makes a clipping window in our offscreen buffer in<BR>the 
  position of our sprite image. We want it to be the size of only<BR>a single 
  image frame. This way, the picture we want is drawn and not<BR>the entire 
  image strip. </P><PRE>    <B>offscreenGraphics.drawImage(spriteStrip,
                                spriteX+(-spriteIndex * spriteWidth),
                                spriteY,this);</B></PRE>
  <P>Drawing the sprite is the same as drawing any image. Note above that<BR>the 
  only difference is the x coordinate. We are shifting the strip of<BR>images 
  left to get the image we want. If we didn't create a clipping<BR>rectangle 
  first, the image would just move left. The image strip is<BR>like a large 
  banner being carried back and forth behind a small window.<BR>Considering the 
  image download speed increases, this is worthwhile. </P><PRE>    <B>g.drawImage(offscreenImage,0,0,this);</B></PRE>
  <P>And finally, here is the only call to the screen graphics context 
  which<BR>draws the updated offscreen buffer just like any normal image. </P>
  <P>Here's the HTML parameters:</P></UL>
<UL>
  <UL>
    <P><B>&lt;APPLET CODE="DBuffer.class" WIDTH=104 HEIGHT=64&gt;<BR>&lt;PARAM 
    NAME="SPRITEDELAY" VALUE="200"&gt;<BR>&lt;PARAM NAME="SPRITEX" 
    VALUE="45"&gt;<BR>&lt;PARAM NAME="SPRITEY" VALUE="20"&gt;<BR>&lt;PARAM 
    NAME="SPRITECOUNT" VALUE="4"&gt;<BR>&lt;PARAM NAME="SPRITENAME" 
    VALUE="guy"&gt;<BR>&lt;PARAM NAME="BACKGROUNDNAME" 
    VALUE="skullbg"&gt;<BR>&lt;/APPLET&gt;</B></P></UL>
  <P>The example applet parameters allow you to insert your own 
  background<BR>image and animated character at an (x,y) position within the 
  applet<BR>window. If you alter the applet, you can make your character 
  walk<BR>around in front of a logo by changing spriteX and spriteY in 
  the<BR>run method infinite loop. Below is the entire Java code. Enjoy! </P><PRE><B>// DBuffer.java
// by Garry Morse

import java.awt.*;
import java.applet.*;

public class DBuffer extends Applet implements Runnable {

  Thread spriteThread;
  MediaTracker tracker;

  Image offscreenImage;
  Graphics offscreenGraphics;

  Image imageBackground;
  Image spriteStrip;

  int spriteDelay=0, spriteCount=0, spriteIndex=0;
  int spriteWidth=0,spriteHeight=0;
  int spriteX=0,spriteY=0;

  String paramString;

  public void init() {

    // create a media tracker object for this applet
    tracker = new MediaTracker(this);

    // get parameter for wait spriteDelay between images
    paramString = getParameter("SPRITEDELAY");
    spriteDelay = Integer.parseInt(paramString);

    // get parameter for number of separate images in strip
    paramString = getParameter("SPRITECOUNT");
    spriteCount = Integer.parseInt(paramString);

    // get parameter for x position of sprite
    paramString = getParameter("SPRITEX");
    spriteX = Integer.parseInt(paramString);

    // get parameter for y position of sprite
    paramString = getParameter("SPRITEY");
    spriteY = Integer.parseInt(paramString);

    // get parameter for sprite image file and load strip
    paramString = getParameter("SPRITENAME");
    spriteStrip = getImage(getCodeBase(),paramString + ".gif");

    // get parameter for background image file and load image
    paramString = getParameter("BACKGROUNDNAME");
    imageBackground = getImage(getCodeBase(),paramString + ".gif");

    // add images to monitored images with IDs
    tracker.addImage(spriteStrip,0);
    tracker.addImage(imageBackground,1);

    // load images into memory
    tracker.checkID(0,true);
    tracker.checkID(1,true);

    repaint();
  }

  public void start() {
    if(spriteThread==null) {
      spriteThread = new Thread(this);
      spriteThread.start();
    }
  }

  public void stop() {
    if(spriteThread!=null) {
      spriteThread.stop();
      spriteThread = null;
    }
  }

  public void update(Graphics g) {
    paint(g);
  }

  public void paint(Graphics g) {

    // if images not loaded yet, inform user
    if(!tracker.checkAll()) {
      g.drawString("loading images...",
                   20,this.size().height/2);
    }
    else {

      if(offscreenImage==null) {
        // set up double buffer
        offscreenImage = createImage(this.size().width,
                                     this.size().height);
        offscreenGraphics = offscreenImage.getGraphics();
      }

      // get dimensions of sprite
      spriteWidth = spriteStrip.getWidth(this) / spriteCount;
      spriteHeight = spriteStrip.getHeight(this);

      // draw background and sprite in offscreen buffer
      offscreenGraphics.drawImage(imageBackground,0,0,this);
      offscreenGraphics.clipRect(spriteX,spriteY,
                                 spriteWidth,spriteHeight);
      offscreenGraphics.drawImage(spriteStrip,
                                  spriteX+(-spriteIndex * spriteWidth),
                                  spriteY,this);

      // copy offscreen buffer to screen
      g.drawImage(offscreenImage,0,0,this);
    }

  }

  public void run() {
    while(true) {
      
      repaint();

      // reloop through list of images to display
      if(++spriteIndex &gt;= spriteCount) spriteIndex=0;

      // try to shut down spriteThread for milliseconds
      try {
        spriteThread.sleep(spriteDelay+1);
      }
      catch(InterruptedException e) { }

    }
  }

}</B></PRE></UL>
<P><FONT size=+1><A 
href="http://www.intergate.bc.ca/personal/iago/javatut/dbuffer.htm">Click here 
to see the Double Buffer applet in action!</A></FONT></P>
<P><FONT color=#ffb5b5><FONT size=-2>The Java Game Programming Tutorial and all 
tutorials within are created by Garry Morse, Copyright 1997</FONT></FONT></P>
<P><BR></P></BODY></HTML>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本中文在线一区| 中文字幕在线播放不卡一区| 天天综合日日夜夜精品| 欧美性一区二区| 亚洲一区二区四区蜜桃| 在线免费观看一区| 亚洲小说欧美激情另类| 欧美午夜精品理论片a级按摩| 亚洲综合一二三区| 欧美日韩一区小说| 美女视频一区二区三区| 精品久久免费看| 激情综合网最新| 久久久久久久久97黄色工厂| 国产成人午夜视频| 亚洲人成小说网站色在线 | 1区2区3区精品视频| 91在线一区二区三区| 夜夜操天天操亚洲| 欧美精品第1页| 97精品视频在线观看自产线路二| 亚洲素人一区二区| 欧美美女一区二区三区| 久久精品国产一区二区| 久久久久国产精品麻豆| 粉嫩欧美一区二区三区高清影视| 亚洲四区在线观看| 欧美精品丝袜久久久中文字幕| 久久精品国产**网站演员| 国产亚洲欧美在线| 成人高清免费在线播放| 亚洲成在人线在线播放| 欧美精品一区男女天堂| 一本久道久久综合中文字幕| 天堂影院一区二区| 国产精品日产欧美久久久久| 欧美午夜理伦三级在线观看| 国产毛片精品国产一区二区三区| 中文在线一区二区| 91精品国产综合久久久久久| 国产91高潮流白浆在线麻豆| 亚洲成人中文在线| 国产性色一区二区| 欧美欧美欧美欧美| 成人av综合在线| 亚洲gay无套男同| 久久久久久久电影| 欧美精品第1页| thepron国产精品| 九九视频精品免费| 亚洲午夜免费电影| 中文字幕一区视频| 精品蜜桃在线看| 欧美挠脚心视频网站| 精品日韩欧美在线| 欧美主播一区二区三区美女| 国产电影精品久久禁18| 奇米色777欧美一区二区| 亚洲欧美怡红院| 2023国产一二三区日本精品2022| 色狠狠av一区二区三区| 不卡电影一区二区三区| 国产一区欧美一区| 美女在线观看视频一区二区| 亚洲国产成人91porn| 国产精品毛片无遮挡高清| 日韩欧美一区二区久久婷婷| 欧洲另类一二三四区| 99热精品一区二区| 国产乱码精品一品二品| 五月婷婷综合激情| 亚洲伦在线观看| 国产欧美日韩综合| 久久久国产午夜精品| 91精品国产91久久综合桃花| 在线精品国精品国产尤物884a| 成人h精品动漫一区二区三区| 国产在线播放一区| 捆绑紧缚一区二区三区视频| 亚洲成av人片在线观看| 亚洲三级免费观看| 成人免费一区二区三区在线观看| 国产精品入口麻豆原神| 欧美激情自拍偷拍| 久久久久久影视| 国产色一区二区| 久久精品视频免费| 欧美韩日一区二区三区四区| 国产网站一区二区三区| www国产亚洲精品久久麻豆| 精品国产第一区二区三区观看体验| 日韩一区二区精品| 欧美精品一区二区三区蜜桃| 久久影音资源网| 国产欧美精品区一区二区三区 | 91麻豆国产精品久久| 99re在线精品| 欧美亚洲精品一区| 欧美日本视频在线| 日韩三级视频在线看| 久久久亚洲精品一区二区三区| 国产三级一区二区| 国产精品久久久久影院亚瑟| 免费成人你懂的| 国产一区二区三区香蕉| 99久久久久久| 欧美午夜在线观看| 日韩欧美在线影院| 国产日韩欧美一区二区三区乱码| 综合色中文字幕| 亚洲成人tv网| 激情图区综合网| 成人app在线| 欧美日韩高清一区| 欧美zozo另类异族| 亚洲欧美在线aaa| 日本欧美在线观看| 国产精品一二三四| 一本色道亚洲精品aⅴ| 在线播放视频一区| 国产婷婷一区二区| 亚洲在线视频网站| 国产一区二区三区免费| 色综合久久天天| 欧美一级免费大片| 国产精品黄色在线观看| 性做久久久久久| 成人综合激情网| 欧美日韩1区2区| 中文在线资源观看网站视频免费不卡| 亚洲男人的天堂av| 国内精品免费**视频| 91福利精品第一导航| 26uuu国产在线精品一区二区| 亚洲精品高清视频在线观看| 久久爱www久久做| 在线观看av一区| 国产欧美精品一区二区色综合| 亚洲一区二区五区| 高清不卡一区二区| 欧美一区二区在线观看| 亚洲欧美一区二区久久| 国产精品888| 日韩午夜激情电影| 一区二区理论电影在线观看| 高清不卡在线观看av| 欧美tickling网站挠脚心| 一区二区高清视频在线观看| 成人在线视频一区| 精品国产成人系列| 日韩精品色哟哟| 欧美亚州韩日在线看免费版国语版| 日本一区二区免费在线观看视频| 日韩av在线发布| 欧美日韩精品一区二区在线播放| 亚洲欧美自拍偷拍色图| 国产激情视频一区二区三区欧美| 91精品国产黑色紧身裤美女| 亚洲成人动漫精品| 在线观看亚洲一区| 亚洲欧美激情在线| 97久久精品人人做人人爽| 国产日韩精品一区二区三区| 久久99精品久久久久久| 日韩精品中文字幕在线一区| 性做久久久久久免费观看欧美| 91精彩视频在线观看| 亚洲三级免费电影| 99免费精品视频| 中文字幕一区二区5566日韩| 国产成a人亚洲| 国产精品系列在线| 成人a级免费电影| 最新日韩av在线| 色综合久久中文综合久久97| 亚洲欧美色一区| 91激情五月电影| 亚洲一区二区av在线| 欧美日韩综合色| 午夜精品久久久久久不卡8050| 欧美亚洲国产怡红院影院| 亚洲第一主播视频| 91精品欧美福利在线观看| 日韩国产欧美视频| 日韩欧美黄色影院| 国产综合久久久久影院| 久久精品人人做人人爽人人| 成人免费视频视频在线观看免费| 国产精品理伦片| 91久久精品一区二区| 五月天亚洲精品| 日韩一区二区免费视频| 国产一区二区三区不卡在线观看 | 久久精品一区蜜桃臀影院| 国产精品456露脸| 1024国产精品| 欧美日韩国产高清一区二区三区 | 久久综合av免费| 成人精品在线视频观看| 亚洲美女屁股眼交3|