java水波特效_谁能给我一个水波特效的手机Java代码呢?最好能讲解下哦

展开全部

这个里面有一个方法,就是那个32313133353236313431303231363533e78988e69d8331333239303766比较复杂的那个,很容易用的

看下下就知道了

package Begin;

import DreamBubbleMidlet;

import java.io.IOException;

import java.util.Timer;

import java.util.TimerTask;

import javax.microedition.lcdui.Graphics;

import javax.microedition.lcdui.Image;

import javax.microedition.lcdui.game.GameCanvas;

import javax.microedition.lcdui.game.Sprite;

public class WaveAnimate extends GameCanvas implements Runnable {

private DreamBubbleMidlet dreamBubbleMidlet;

private int screenWidth;

private int screenHeight;

private int screenHalfWidth;

private int screenHalfHeight;

private Graphics g;

private Image BG;

private Image logo;

private Image img;

private int imgWidth;

private int imgHeight;

private int height;

private long time;

private Timer timer;

private boolean isEnd;

public WaveAnimate(DreamBubbleMidlet dreamBubbleMidlet) {

super(true);

this.setFullScreenMode(true);

this.dreamBubbleMidlet = dreamBubbleMidlet;

screenWidth = getWidth();

screenHeight = getHeight();

screenHalfWidth = screenWidth >> 1;

screenHalfHeight = screenHeight >> 1;

g = getGraphics();

try {

BG = Image.createImage("/Begin/StartBG.png");

logo = Image.createImage("/Begin/logo.png");

img = Image.createImage("/Begin/1.png");

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

imgWidth = img.getWidth();

imgHeight = img.getHeight();

}

public void showMe() {

new Thread(this).start();

this.dreamBubbleMidlet.show(this);

}

public void run() {

while (!isEnd) {

long beginTime = System.currentTimeMillis();

if (height + 1 < imgHeight) {

height += 3;

} else {

timer = new Timer();

timer.schedule(new TimerTask() {

public void run() {

showNextScreen();

}

}, 1500);

}

g.drawImage(BG, screenHalfWidth, screenHalfHeight, Graphics.VCENTER

| Graphics.HCENTER);

g.drawImage(logo, screenHalfWidth, screenHalfHeight,

Graphics.VCENTER | Graphics.HCENTER);

g.setClip(0, 0, screenWidth, screenHeight);

g.drawRegion(img, 0, 0, imgWidth, height, Sprite.TRANS_NONE,

screenHalfWidth, screenHalfHeight, Graphics.HCENTER

| Graphics.BOTTOM);

this.drawImage(g, img, true, 0.2, 0, 0, imgWidth, height,

screenHalfWidth, screenHalfHeight, Graphics.HCENTER

| Graphics.TOP);

flushGraphics();

long endTime = System.currentTimeMillis();

if (endTime - beginTime < 50)

try {

Thread.sleep(50 - (endTime - beginTime));

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

public void showNextScreen() {

this.isEnd = true;

timer.cancel();

timer = null;

try {

Thread.sleep(50);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

this.dreamBubbleMidlet.beforeMenu.showMe();

}

public void drawImage(Graphics g, Image img, boolean inverted,

double power, int x_src, int y_src, int width, int height,

int x_dest, int y_dest, int anchor) throws IllegalArgumentException {

switch (anchor) {

case Graphics.TOP | Graphics.LEFT:

case Graphics.TOP | Graphics.RIGHT:

case Graphics.TOP | Graphics.HCENTER:

case Graphics.BOTTOM | Graphics.LEFT:

case Graphics.BOTTOM | Graphics.RIGHT:

case Graphics.BOTTOM | Graphics.HCENTER:

case Graphics.VCENTER | Graphics.LEFT:

case Graphics.VCENTER | Graphics.RIGHT:

case Graphics.VCENTER | Graphics.HCENTER:

break;

default:

throw new IllegalArgumentException();

}

if (power < 0 || power > 1) {

throw new IllegalArgumentException();

}

if (x_src < 0 || y_src < 0 || width < 0 || height < 0

|| x_src + width > img.getWidth()

|| y_src + height > img.getHeight()) {

throw new IllegalArgumentException();

}

int swing = height >> 3;

int offsetX = -((anchor & Graphics.RIGHT) != 0 ? width

: (anchor & Graphics.HCENTER) != 0 ? width >> 1 : 0);

int offsetY = -((anchor & Graphics.BOTTOM) != 0 ? height

: (anchor & Graphics.VCENTER) != 0 ? height >> 1 : 0);

time++;

for (int n = 0, offset; n < height; n++) {

offset = (int) ((swing * (n + 20)

* Math.sin((double) swing * (height - n) / (n + 1) + time) / height) * power);

if (n + offset < 0) {

offset = -n;

} else if (n + offset >= height) {

offset = height - n - 1;

}

g.setClip(x_dest + offsetX, y_dest + offsetY + n, width, 1);

if (inverted) {

g.drawImage(img, x_dest + offsetX - x_src, y_dest + offsetY

- y_src - height + 1 + (n << 1) + offset, Graphics.LEFT

| Graphics.TOP);

} else {

g.drawImage(img, x_dest + offsetX - x_src, y_dest + offsetY

- y_src - offset, Graphics.LEFT | Graphics.TOP);

}

}

}

}

本回答由提问者推荐

2Q==

已赞过

已踩过<

你对这个回答的评价是?

评论

收起

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值