我正在使用javafx开发游戏。我以前用awt编写了一些游戏,所以我对游戏的运作方式有基本的了解。 (我使用过bufferedimages)然而,有了javafx api中的所有新内容,我质疑我的旧游戏架构是否仍然适用于javafx。这是我游戏的当前逻辑:
这是我的渲染工作方式:
List<Entity> entities= new ArrayList<Entity>;
GraphicsContext gc; ///imagine that I created a new GraphicsContext object
在render方法中,它基本上看起来像这样:
for(Entity e : entities)
{
gc.drawImage(e.getX(),e.getY(),e.getImage());
}
然而,由于javafx有这么多新功能,我想知道这种方法是否过时或效率低下。我应该移动这些实体还是应该自己移动图像?我正在研究太空射击游戏,Interpolate()和Transition会改进我的游戏吗?
目前还没有很多具体的javafx游戏教程,所以我必须在这里寻求帮助...... 谢谢!
答案 0 :(得分:2)
你在做的方式是我认为最好的方法,我做了类似的事情并使用了这样的实体: package jumpNRun.gameObjects;
import java.util.List;
import javafx.scene.image.Image;
import javax.xml.bind.annotation.XmlRootElement;
import jumpNRun.gameObjects.entitys.Solid;
@XmlRootElement
public class Entity {
protected Image entityImage;
protected double gravity = 0;
protected int height = 0, width = 0;
protected int x = 0, y = 0;
protected int id = 0;
/**
* Class speciefed informations
*/
protected String extraInfo;
protected boolean killed = false;
public String getExtraInfo() {
return extraInfo;
}
public void setExtraInfo(String extraInfo) {
this.extraInfo = extraInfo;
}
......等等 绘图可以这样完成:
gc.drawImage(backround, 0, 0);
for (Entity e : entitys) {
gc.drawImage(e.getEntityImage(), e.getX(), e.getY());
}