无论如何,您必须在图形对象和游戏实体之间建立联系。因为否则您将无法将用户事件(如鼠标单击)从场景转换为逻辑。
所以我建议在你的模型和视图之间引入连接。而且,恕我直言,不是通过创建一个完美的 MVC 来隐藏一个,因为它会在开发的开始阶段增加太多的麻烦。只需向游戏实体添加指向图形对象的链接(或者,更好的是,与您想要对图形执行的操作的接口)应该适合您。
它可能如下所示:
interface UnitView {
void add(Point position);
void move(Point position);
void remove(Point position);
void setOnClick(Runnable callback);
}
class GlUnit implements UnitView extends GLSceneObjectOrWhateverItCalled {
//this class implements all drawin and animation; and handles calls from model
//through UnitView interface
}
class Unit {
void setView(UnitView view); // this method is called by manager which generated scene
// here is your implementation of unit logic
}