Sign in to follow this  
Meshboy

Dealy in function, not Thread.sleep()

Recommended Posts

I want to print some text unsing the Draw2D (MDX). I want to print just one letter at the time. so the result will be like using an old typewriter. At first i thought this would be easy for(int i =0;i<text.length-1;i++) { Thread.Sleep(100) draw2D(text.substring(0,i)) } But when i call this function in my gameloop everything is delayed, and when the function is finished the game continues with this sleep. How do i just slow down the function, and not the whole game? Any tip of how to best strucutre your code for intros/cutscenes whould be thankfull. booleans? triggers? classes with movement logic? right now i am using the third option...

Share this post


Link to post
Share on other sites
It's relatively simple to solve, as long as you know how much time the last frame took. You keep track of how many characters you need to draw, and how much time there's left to display the next one. Each frame, you lower the delay by the frame time. Once it's equal or less than 0, you up the character counter, and set the delay to it's initial value again, ready to count down for yet another character. Obviously, each frame you only render as many characters as the character counter allows.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this