Computer Science Canada Problem with Font.Draw |
Author: | Ninja [ Sat Jun 10, 2006 11:17 am ] | ||
Post subject: | Problem with Font.Draw | ||
Hey guys. Im making the final project for my comsci class (Grade 11). What im trying to do here is import a file called welcome.txt and have it displayed on the intro screen with Font.Draw command. Everytime i try to do that, it takes the text and puts it on the screen but its overlapping on top of every word. Is it even possible to use Font.Draw with reading from a file, or should i just type the whole "welcome" message out manually. Thanx
|
Author: | Cervantes [ Sat Jun 10, 2006 1:41 pm ] | ||||
Post subject: | |||||
Of course it's going to overlap. Look carefully at this line:
The (x, y) coordinates that you're drawing at is (100, 100). It's constant. It never changes. Instead, you should decrease the y coordinates as you move through all your lines.
200 - 16 * y will move you down by 16 pixels each line. Assuming your font is size 14, that's a good amount to move down each line. Note that you do not need your array, number. You could read the line in from the file and draw it immediately. Also, your array, number has a hardcoded range of 1 .. 14. This is a terrible habit. You know the number of lines in your welcome file. If you changed it, or if you wanted this code to work with any other welcome file, your code would not work. |
Author: | Ninja [ Sun Jun 11, 2006 6:27 pm ] | ||
Post subject: | |||
thanx bro. i got it workin now, heres the modified code ![]()
|
Author: | Bored [ Sun Jun 11, 2006 8:36 pm ] | ||
Post subject: | |||
Your still harcoding the number of lines.
What if you changed the welcome file and added a 8th line, you would get an error. Now that's ok just change the number array to 8. But what if you wanted this to work with any welcome file, and they all had different amounts of lines. Well there's two soloutions as Cervantes mentioned. The first, considering you only use the lines in one spot is to replace the number array with a single variable and write the number as soon as you read it. This would also reduce the amount of code as you remove the for loop and put the code in the loop above. the other answer is a flexible array. You could then each loop increas the size by onw and have the for loop run from 1 to upper (number). |