<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    游戲策劃咨訊
    做一個游戲并不難,難的是做一個好游戲;完美在于積累!
    使用MIDP(Mobile Information Device Profile)的開發人員經常會抱怨用些什么辦法才可以在一個MIDlet上顯示動畫。MIDP 1.0 沒有直接提供對動畫的支持(正在開發中的MIDP 2.0支持),但真要是自己去實現,其實也并非是一件很難的事。

    任何動畫的最基本的前提,是要在足夠快的時間內顯示和更換一張張的圖片,讓人的眼睛看到動的畫面效果。圖片必須按照順序畫出來。從一張圖片到下一張圖片之間的變化越小,效果會越好。

    首先要做的,是使用你的圖片處理軟件(比如ps或者firework)創建一系列相同大小的圖片來組成動畫。每張圖片代表動畫一幀。

    你需要制作一定數量的禎--越多的幀會讓你的動畫看上去越平滑。制作好的圖片一定要保存成PNG(Portable Network Graphics) 格式,MIDP唯一支持的圖片格式;(有兩個辦法讓你剛做好的圖片在MIDlet上變成動畫。第一,把圖片都放到一個web服務器上,讓MIDlet下載他們,MIDP內置的HTTP支持。第二個辦法更簡單,把圖片用MIDlet打包成jar文件。如果你使用的是J2ME開發工具,把PNG文件放在你的項目文件里面就可以了。

    動畫的過程其實更像帳本記錄:顯示當前幀,然后適當地更換到下一幀。那么使用一個類來完成這個工作應該是很恰當的,那好,我們就先定義一個AnimatedImage類:

    import java.util.*;
    import javax.microedition.lcdui.*;
    // 定義了一個動畫,該動畫其實只是一系列相同大小的圖片
    // 輪流顯示,然后模擬出的動畫
    public class AnimatedImage extends TimerTask {;
    private Canvas canvas;
    private Image[] images;
    private int[][] clipList;
    private int current;
    private int x;
    private int y;
    private int w;
    private int h;

    // Construct an animation with no canvas.

    public AnimatedImage( Image[] images ){;
    this( null, images, null );
    };

    // Construct an animation with a null clip list.

    public AnimatedImage( Canvas canvas, Image[]
    images ){; this( canvas, images, null );
    };

    // Construct an animation. The canvas can be null,
    // but if not null then a repaint will be triggered
    // on it each time the image changes due to a timer
    // event. If a clip list is specified, the image is
    // drawn multiple times, each time with a different
    // clip rectangle, to simulate transparent parts.

    public AnimatedImage( Canvas canvas, Image[] images,
    int[][] clipList ){;
    this.canvas = canvas;
    this.images = images;
    this.clipList = clipList;

    if( images != null && clipList != null ){;
    if( clipList.length < images.length ){;
    throw new IllegalArgumentException();
    };
    };

    if( images != null && images.length > 0 ){;
    w = images[0].getWidth();
    h = images[0].getHeight();
    };
    };

    // Move to the next frame, wrapping if necessary.

    public void advance( boolean repaint ){;
    if( ++current >= images.length ){;
    current = 0;
    };

    if( repaint && canvas != null && canvas.isShown()
    ){;
    canvas.repaint( x, y, w, h );
    canvas.serviceRepaints();
    };
    };

    // Draw the current image in the animation. If
    // no clip list, just a simple copy, otherwise
    // set the clipping rectangle accordingly and
    // draw the image multiple times.

    public void draw( Graphics g ){;
    if( w == 0 || h == 0 ) return;

    int which = current;

    if( clipList == null || clipList[which] == null
    ){;
    g.drawImage( images[which], x, y,
    g.TOP | g.LEFT );
    }; else {;
    int cx = g.getClipX();
    int cy = g.getClipY();
    int cw = g.getClipWidth();
    int ch = g.getClipHeight();

    int[] list = clipList[which];

    for( int i = 0; i + 3 <= list.length; i +=
    4 ){;
    g.setClip( x + list[0], y + list[1],
    list[2], list[3] );
    g.drawImage( images[which], x, y,
    g.TOP | g.LEFT );
    };

    g.setClip( cx, cy, cw, ch );
    };
    };

    // Moves the animation's top left corner.

    public void move( int x, int y ){;
    this.x = x;
    this.y = y;
    };

    // Invoked by the timer. Advances to the next frame
    // and causes a repaint if a canvas is specified.

    public void run(){;
    if( w == 0 || h == 0 ) return;

    advance( true );
    };
    };

    posted on 2005-02-17 20:04 藍色雪焰 閱讀(348) 評論(0)  編輯  收藏 所屬分類: 編程技術
     
    主站蜘蛛池模板: 亚洲国产综合专区在线电影 | 国产成人3p视频免费观看| 亚洲色大成WWW亚洲女子| 亚洲国产香蕉人人爽成AV片久久| 久久不见久久见免费影院www日本| 久久久久亚洲精品日久生情 | 亚洲免费福利视频| 亚洲成A人片在线观看无码3D| 两个人看的www免费| 亚洲综合欧美色五月俺也去| 亚洲欧洲精品成人久久曰影片 | 亚洲人成网亚洲欧洲无码久久| 成人福利免费视频| 一级毛片在线播放免费| 亚洲午夜精品国产电影在线观看| 亚洲av区一区二区三| 51视频精品全部免费最新| 黄色免费在线网址| 亚洲w码欧洲s码免费| 亚洲日韩乱码中文无码蜜桃臀网站 | 免费视频精品一区二区三区| 亚洲精品无码成人片久久不卡 | 亚洲w码欧洲s码免费| 精品国产综合成人亚洲区| 超pen个人视频国产免费观看 | 无码视频免费一区二三区| 国产免费一区二区三区在线观看| 婷婷国产偷v国产偷v亚洲| 亚洲视频在线观看不卡| 亚洲精品亚洲人成人网| 国产成人免费网站在线观看| 91免费国产在线观看| 黄色免费在线网站| 特色特黄a毛片高清免费观看| 亚洲中文字幕无码久久| 中文字幕亚洲综合精品一区| 亚洲自偷自偷在线制服| 亚洲国产高清在线一区二区三区| 人成午夜免费视频在线观看| 人妻无码一区二区三区免费| 岛国岛国免费V片在线观看|