2
\$\begingroup\$

I am creating a game using a relatively new platform called "codenameOne", but I'm actually a software engineer, so this question might be rather basic or odd, but I'm unsure what to do.

The game is targeting mobile phones and tablets (codenameOne has the advantage of being close to WORA) and I'm unclear on how to correctly update the "logic" and the "view".

At the moment, both update 60 times per second, but this feels wrong. This means that if I decrease the update speed of the game, the elements will also slow down (such as applying the current acceleration to the velocity, to the position,...)

This comes down to two questions:

1) Should they have separate update frequencies?

2) If so, which ones are conventionel for mobile applications?

EDIT: It might actually be worth noting that the game works (some bugs but it renders fine and it's playable). If you want to take a look at the source it's here: https://github.com/DylanMeeus/CNOGame

\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

Usually we call "logic" "update" and "view" "draw".

Ideally the view would only want to redraw when the logic has changed. It's true that if you slow down the update speed, everything will be slower. This is why we used fixed time steps.

With a fixed time step, update should always be consistent. The only time it wouldn't be is:

  • You change the time step at run time( don't do this. )
  • Update is running extremely slow( 99% of the time, drawing should be the thing lagging behind. )

If draw is making the whole application slow, logic update will still be on time. If the user doesn't see a few frames, that's okay. If updates don't happen, that's not okay. That actually changes the game.

If you're using a well competent 3rd part library for this, then it should have this covered for you.

So, basically, everything is still based off time. View can be updated as much as possible, logic can only be updated if a certain amount of time has passed.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks! There is no 3rd party library yet, but I'll do it this way :) \$\endgroup\$ Commented Apr 26, 2014 at 12:07
  • 1
    \$\begingroup\$ @DylanMeeus It is important to note that you don't need to update everything every single frame. It is not required. Only visual aspects need to be updated every frame (motion + animation). Good luck with your project. \$\endgroup\$
    – AturSams
    Commented Apr 26, 2014 at 12:16
0
\$\begingroup\$

I think both approaches are valid if done correctly. In your case a delta value should be passed to the logic telling it how much time has passed since the last update. After that every logic part would update according to it so changing a coord for instance could be something along the lines of x += velocity*delta.

\$\endgroup\$
1
  • \$\begingroup\$ This is an incredibly tedious way to update everything. This also becomes less and less accurate as an update takes longer. \$\endgroup\$
    – user30331
    Commented Apr 26, 2014 at 10:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .