#26235 - hakanyuksel - Fri Sep 10, 2004 12:40 am
I want to make a function that writes a string by using sprites. I need to take the string as a parameter. But I dont know how to make it. What kind of variable type shoud i use for this.
Code: |
void write_str( ? str, u8 x, u8 y)
{
.....
.....
....
}
|
my function will be like this and
Code: |
write_str("helloo",10,10);
|
I will call the function like this,
What should i write to ?.
_________________
--------------------
Hakan Yuksel
3TE GAmes
www.3tegames.com
#26238 - DiscoStew - Fri Sep 10, 2004 12:56 am
I'm assuming you don't know how to do strings in C/C++. There are documents on-line. Just look around. It takes too long to explain what you can do and what you shouldn't do, as it is dealing with pointers and memory.
_________________
DS - It's all about DiscoStew
#26240 - Krakken - Fri Sep 10, 2004 1:25 am
I wouldn't use strings myself. I avoid them at all costs if I can help it.
You can do this quite easily with a char pointer. When you supply an argument in quotes, all it does is create a pointer to the memory where that data is stored.
EG:
char* pcString = "Hello";
(pcString holds the meory location of the constant string "Hello")
From there you can reference each element of the string by treating the pointer as an array.
EG:
pcString[0]; // This is 'H'
pcString[1]; // This is 'e'
(and so on...)
To detect the end of a string, check for the character '\0' (don't forget single chars use single quotes and strings use double quotes).
So your function can be done like this:
void write_str(char* pcString, u8 x, u8 y) { }
And each of your elements can be accessed as above.
Hope this helps!
#26243 - tepples - Fri Sep 10, 2004 2:00 am
There are three steps: reading the characters (as Krakken explained), creating the glyph data (the actual images of each letter), and drawing the glyphs to the screen. Do you plan on using tiles, sprites, or bitmaps to draw each glyph?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#26246 - sajiimori - Fri Sep 10, 2004 2:53 am
It seems like nobody has answered the question. The type of a string literal (such as "heloo") in C is const char*.
#26255 - hakanyuksel - Fri Sep 10, 2004 10:50 am
tepples wrote: |
Do you plan on using tiles, sprites, or bitmaps to draw each glyph? |
Thanks for all of your answers. I succesfuly write text by using sprites.
_________________
--------------------
Hakan Yuksel
3TE GAmes
www.3tegames.com