JME基础教程代码分析4
package com.hello;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
/** Sample 4 - how to trigger repeating actions from the main update loop.
* In this example, we make the player character rotate. */
public class HelloLoop extends SimpleApplication {
public static void main(String[] args){
HelloLoop app = new HelloLoop();
app.start();
}
//被操作的几何体主体
protected Geometry player;
@Override
public void simpleInitApp() {
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
player = new Geometry("blue cube", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
player.setMaterial(mat);
rootNode.attachChild(player);
}
/* This is the update loop */
//又是一个重载方法,现在就知道它是由Application的update方法回调的,更新场景。以后再分析SimpleApplication和Application代码
//tpf可以理解为单位时间内的速度值
@Override
public void simpleUpdate(float tpf) {
// make the player rotate
player.rotate(0, 2*tpf, 0);
}
}
posted on 2011-08-12 11:26 苏桓(osbert) 阅读(285) 评论(0) 编辑 收藏 举报