开发者

How do game events work?

开发者 https://www.devze.com 2022-12-17 18:20 出处:网络
I\'v always wondered how this works. Does having more slow down the game? for example how would one represent checking if a car has flipped. It could be seen as:

I'v always wondered how this works. Does having more slow down the game? for example how would one represent checking if a car has flipped. It could be seen as:

if (player.car.angle.y == 180)
{
do something
}
开发者_运维百科

The parts that puzzle me is, when would the game check for it? The way I see it, every thing that can happen in the game seems to evolve an if. I'm just wondering how these are handled.

Also, since the game runs through a loop, what if the car is flipped for more than 1 frame, would a Boolean really be used to check if the event has been fired

Thanks


In most general terms, any object in an engine has a state - if it changes state (e.g. not flipped to flipped), that is a transition.
From a transition you can fire an event or not, but as the transition does only occur when changing state the event won't be fired more then once.

As for the conditions that trigger the transitions, they have to be coded somewhere of course. Sometimes they are more explicitly coded, but mostly they are parameterized so that scripts or some sort of configuration can change them easily.

How it is implemented in the end differs broadly, it depends on the libraries that are used as well the engine design itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消