javafx粒子系统之烟雾模拟

javafx粒子系统之烟雾模拟

功能说明: 用图片纹理模拟烟雾生成,香港服务器,烟雾可以随风飘散。

在线运行

源码下载

程序讲解:

1、粒子对象定义: 定义Particle对象继承Parent。 定义以下属性:

//烟雾图片Image image;//x坐标DoubleProperty x = new SimpleDoubleProperty();//y坐标DoubleProperty y = new SimpleDoubleProperty();//粒子半径double raidus;//水平速度double vx;//垂直速度double vy;//加速度DoubleProperty acc = new SimpleDoubleProperty();//粒子存在时长DoubleProperty timer = new SimpleDoubleProperty();

2、粒子创建 用图片纹理创建烟雾

private void create() {ImageView view = new ImageView(image);view.xProperty().bind(this.x);view.yProperty().bind(this.y);view.opacityProperty().bind(this.timer.divide(100));getChildren().add(view);}

3、粒子创死亡判断 timer属性的值判断粒子是否死亡。

public boolean isDead() {return timer.get() < 0;}

4、粒子更新 粒子运动方向根据acc的大小来改变。

private void update() {Particle p = new Particle(image, 84, 164,0.3 * random.nextGaussian(),0.3 * random.nextGaussian() – 1, 100);p.acc.bind(acc);particles.add(p);Iterator it = particles.iterator();while (it.hasNext()) {Particle tempParticle = it.next();tempParticle.update();if (tempParticle.isDead()) {it.remove();}}float fps = com.sun.javafx.perf.PerformanceTracker.getSceneTracker(stage.getScene()).getInstantFPS();fpsLable.setText(“FPS:” + fps);}

效果图:

在线运行

源码下载

,美国空间,虚拟主机相信成功的信念比成功本身更重要,

javafx粒子系统之烟雾模拟

相关文章:

你感兴趣的文章:

标签云: