I am reading source codes written in a game. Some lines are written as follows:
0 ? player.y > global.screenHeight/2 : global.screenHeight/2 - player.y
Assume that player
is a sprite with position and global
is just an import from other files which contains some properties. What does the above code do? I thought the ternary operator will be something like this:
c ? a : b
where a
and b
are of the same type and c
is the condition.
But the game demo runs smoothly so the above code should be fine. I just don’t get the meaning of the code.
The code is extracted from here:
https://github.com/huytd/agar.io-clone/blob/master/src/client/js/app.js