使用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.*; // construct an animation with no canvas. public animatedimage( image[] images ){; // construct an animation with a null clip list. public animatedimage( canvas canvas, image[] // construct an animation. the canvas can be null, public animatedimage( canvas canvas, image[] images, if( images != null && cliplist != null ){; if( images != null && images.length > 0 ){; // move to the next frame, wrapping if necessary. public void advance( boolean repaint ){; if( repaint && canvas != null && canvas.isshown() // draw the current image in the animation. if public void draw( graphics g ){; int which = current; if( cliplist == null cliplist[which] == null int[] list = cliplist[which]; for( int i = 0; i + 3 <= list.length; i += g.setclip( cx, cy, cw, ch ); // moves the animation's top left corner. public void move( int x, int y ){; // invoked by the timer. advances to the next frame public void run(){; advance( true ); |
你实例化一个animatedimage对象的时候你必须给animatedimage类的构造方法传一个image对象数组,该数组代表动画的每一帧。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器