Cheap early-out if it's not time to spawn a wave yet. Note: These are estimated times, these will vary between classes. or at a coarser frequency if you prefer, since it changes state infrequently. Greenfoot - Creating a Jumping Game - 1 hour. Call this periodically, say once per frame update, NextWaveSpawnTime = System.nanoTime() + 1000000000 That might look something like this: // Call this at the start of your level. Instead, what you really want to do is call this function periodically, and each time check if it's time to spawn a new wave, rather than hold the CPU hostage until it's time. So, don't put a wait loop inside your game loop. i is still less than 3, so we're stil not allowing the CPU to move on yet! Back to step 3 we go, and burn another second doing nothing. I tried playing around with the brackets and I restarted Greenfoot. We hit the end of the while loop and check the condition again. 1 asked at 19:41 0 votes 0 answers 143 views Java Greenfoot error in class with no error indication Greenfoot tells me there is an error in the code, but doesn't show me any indication of an error, so it can't be a syntax issue. You've effectively stalled your game here.įinally, an eternity of wasted CPU time later, we've managed to burn a second of time and our inner if condition finally passes. This is called a " busy-wait" or "spinning" - the processor is kept busy checking the clock then looping then re-checking the clock, so it's never allowed to exit this loop, return from this function, update the rest of your game state, process player input, or draw a frame. (World, Actor, GreenfootImage, Greenfoot and MouseInfo) / Write a description of class CrabWorld here. We keep doing this BILLIONS of times, because we do so little work inside the loop each time, nanoTime isn't much bigger each time we loop around. i need help getting my endgame screen and it's saying 'cannot find symbol- variable getwidth' i heres my world code and i have a class for the image and i get the game to stop already. i is still less than 3, so we re-enter the loop and go back to step 3. We hit the end of the while loop, and check the condition again. The latest topic in my Java end-of-term revision video series: a. We check if the current time is 1 second later than begin time yet, but of course it isn't! We've barely executed two instructions since begin time. Each year, we make a highlight reel of the video games created in class by the grade 11. We check the while loop's condition, and i is indeed less than 3, so we enter the loop. Let's walk through this code, pretending that nanoTime = 0 at the start for simplicity.
0 Comments
Leave a Reply. |