Created
May 20, 2018 18:55
-
-
Save jessefreeman/af449c9dcde71c3c754a5362d4e8b463 to your computer and use it in GitHub Desktop.
PV8 example of drawing a score to the display.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local score = 0 | |
| local scoreDisplay = -1 | |
| local pos = NewVector(101, 123) | |
| function DrawScore() | |
| -- Update score | |
| if(scoreDisplay ~= score) then | |
| local diff = math.floor((score - scoreDisplay) / 4) | |
| if(diff < 1) then | |
| scoreDisplay = score | |
| else | |
| scoreDisplay = scoreDisplay + diff | |
| end | |
| if(scoreDisplay < 0) then | |
| scoreDisplay = 0 | |
| end | |
| DrawRect(pos.x, pos.y, 48, 8, BackgroundColor(), DrawMode.TilemapCache) | |
| DrawText(string.format("%06d", scoreDisplay), pos.x, pos.y, DrawMode.TilemapCache, "default", 0, 0) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment