Dragonfly Q&A

drawString() only drawing the last character

0 like 0 dislike
My drawString() function only draws the last character. There are blank spaces to the left of the character it does draw where each of the characters before it should be.

 

So for instance, running drawString() with the string "Test String" will result in having:

"          g"

drawn to the screen, while switching the string to "Test Strin" will result in:

"         n"

and so on. I've made sure the for loop is set up correctly, so I can't see what the problem is.

 

Thanks.
asked Sep 21, 2014 in Engine Development by sswallach

2 Answers

0 like 0 dislike

Are you moving the position over each time when drawing?  For example, you sill start a Position p, then using the GraphicsManager drawCh() method, do something like:

drawch(p, str[0])

p.setX(p.getX() + 1)

drawCh(p, str[1])

p.setX(p.getX() + 1)

...

Make sure you are not putting all the characters at one spot.

answered Sep 21, 2014 by claypool
Yes, I have it in a for loop and it's x position is p.getX()+i.
and the number of blank spaces to the left of the character printed seems to always be equal to the number of characters in the string.
If you've checked what you can think of, why don't you zip up all your code and send it to the staff list and we can take a look.  Move on to other development in the meantime.
0 like 0 dislike

For closure on this question in case anyone else is doing the same ...

You have a call to werase() at the start of your drawCh() method. This erases any previous characters, which is why you only see the last character of the string.  You don't want to be erasing anything in drawCh().

answered Sep 22, 2014 by claypool
More information about Dragonfly can be found on the Dragonfly Home Page.
...