Author Topic: Scroller Maths  (Read 4770 times)

0 Members and 1 Guest are viewing this topic.

Offline Phoenix

  • C= 64
  • **
  • Posts: 99
  • Karma: 4
    • View Profile
Scroller Maths
« on: May 19, 2006 »
Hi!

First off, I'd like to say that we need a forum for non-language specific coding, or a maths section, or both. C# questions shouldn't be posted in this forum, but C# very similiar to C/C++ so I'll post it here anyway.

Anyway, I've been trying to code a demo in C# for the past few days, and I haven't even gotten the scroller to work properly. In Blitz LoadAnimImage() loads the font into frames and everything is solved, though in languages that don't do that for you, it's harder. The problem is that it draws the letters, but instead of "test" it shows "qxyb" or something along those lines. I won't post a lot of code since this is a maths related issue, but here's some code:

Code: [Select]
new Rect( ((ascii) - ((row-1) * 9)) * 54,
                 (row) * 44,
                 (((ascii) - ((row-1) * 9)) * 54) + 54,
                 ((row) * 44) + 44 ) )

I can explain how the maths is supposed to work:
x1: Since we want to x position of the letter to draw, we take the ascii code (The position of the letter), and subtract the number of letters on the rows above (row-1) * 9. We multiply it with nine since there are 9 letters on each row, and 9*row would equal the number of letters on the previous rows.
y1: Nothing complicated, we take the row multiplied with 44 to get the y coordinate.
x2: The same as x1, except that we add 54 pixels so that the rect width doesn't become 0.
y2: Same principle as x2.

The above code is in a for loop which loops through every letter in the string to be drawn. There are two variables, ascii is the ascii code of the letter, subtracted by 32 since the font starts with "!". Row is the row number of the letter in the font. The Rect constructor takes x1,y1,x2,y2 respectively, and the font letter size is 54x44. It might be interesting to see the font:



It would be great if anyone could help me out here,

Phoenix

Offline relsoft

  • DBF Aficionado
  • ******
  • Posts: 3303
  • Karma: 47
    • View Profile
Re: Scroller Maths
« Reply #1 on: May 19, 2006 »
Shoots in the dark:

If you are using asc(char) then you prolly should subtract 31.

ie:  index = asc(char) - 31
Challenge Trophies Won:

Offline zparticle

  • Atari ST
  • ***
  • Posts: 168
  • Karma: 11
    • View Profile
    • ScottShaver2000
Re: Scroller Maths
« Reply #2 on: May 19, 2006 »
Well the first problem I see is with your font. You are missing:

Space
"
\
^

These are going to throw all of your calculations off. The calcs may be right but they won't match the font.

Offline Phoenix

  • C= 64
  • **
  • Posts: 99
  • Karma: 4
    • View Profile
Re: Scroller Maths
« Reply #3 on: May 19, 2006 »
I fixed it! The problem was that when calculating the row number I had typed 8 instead of 9, I hate those stupid mistakes... Though you're right, when I use other characters the text gets messed up, I'll fix it.

Offline Phoenix

  • C= 64
  • **
  • Posts: 99
  • Karma: 4
    • View Profile
Re: Scroller Maths
« Reply #4 on: May 20, 2006 »
It's working perfectly now, thanks for the help! Feel free to use the finished font, it can be downloaded at http://phoenixoft.com/font.png.