在 FSM 中设置状态
我第一次使用基于类的 FSM,我对设置初始状态的最佳实践有点困惑。
我已将 FSM 添加到我的 Screen
类中,我想用它来处理(大部分)转换。传统上我会做这样的事情:
function update(frameTime : Number) : void
{
switch(_currentState)
{
case STATE_TRANSITIONING_IN:
slideTheButtonsIn();
if(buttonsInPlace == true)
changeState(STATE_ACTIVE);
break;
case STATE_ACTIVE:
if(buttonClicked() == true)
changeState(STATE_TRANSITIONING_OUT)
break;
case STATE_TRANSITIONING_OUT:
slideButtonsOut();
if(buttonsInPlace == true)
removeThisScreen();
break;
}
}
我认为这是一个非常标准的方法。
所以我的新状态的问题是,谁负责创建屏幕上的所有对象?我的 Screen 应该创建所有按钮和内容,然后将它们传递给 MainMenuTransitionInState 类,还是 MainMenuTransitionState 类创建按钮然后传递它们还是我完全错过了目标?
在这里感谢您的明智建议。谢谢!
I'm using an class based FSM for the first time and I'm a little confused on what the best practice is to set-up the initial state.
I've added a FSM to my Screen
class that I want to use to handle (mostly) transitions. Traditionally I'd do something like this:
function update(frameTime : Number) : void
{
switch(_currentState)
{
case STATE_TRANSITIONING_IN:
slideTheButtonsIn();
if(buttonsInPlace == true)
changeState(STATE_ACTIVE);
break;
case STATE_ACTIVE:
if(buttonClicked() == true)
changeState(STATE_TRANSITIONING_OUT)
break;
case STATE_TRANSITIONING_OUT:
slideButtonsOut();
if(buttonsInPlace == true)
removeThisScreen();
break;
}
}
I think that's a pretty standard approach.
So my problem with my new states are, WHO is responsible for creating all the objects on screen? Should my Screen
create all the buttons and stuff and then pass them to the MainMenuTransitionInState
class or should the MainMenuTransitionState
class create the buttons and then pass them around or have I missed the mark entirely?
Appreciate your sage advice here. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
模型-视图-控制器模式可能会有所帮助这里。
MainMenuScreen
(视图)这将显示您的模型。在这里处理所有与 UI 相关的对象。直接查询模型以初始化或更新它们。
MainMenuFsm
(控制器)这是视图的事件处理程序。每当用户与您的视图交互时,请将操作转换为模型的更新。
MainMenuState
(模型)在此处存储您的状态。
A model-view-controller pattern might help here.
MainMenuScreen
(View)This is what will display your model. Work with all your UI related objects here. Query the model directly to initialize or update them.
MainMenuFsm
(Controller)This is your view's event handler. Whenever the user interacts with your view, translate the actions into updates to your model.
MainMenuState
(Model)Store your state here.