gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > HAM Text Help

#90335 - Split - Thu Jun 29, 2006 7:30 pm

I am using VHAM. I know this problem is very easy for most of you but I just started doing this. My problem is this. In my program I have text didplayed then when you push a button different text appears. I can do ll of that except eraseing the text from before. How would I go about doing that?

Also Is there a way to center the text as well?

#90337 - KeithE - Thu Jun 29, 2006 7:33 pm

To erase text, you can draw some spaces, like this

Code:
ham_DrawText(X,Y,"      ");


To center the text, you need to enter the appropriate X coordinate for the starting location so that the text appears centered.

#90341 - Split - Thu Jun 29, 2006 8:01 pm

Doesn't work the text just flashes

#90356 - tepples - Thu Jun 29, 2006 9:14 pm

Is your program reaching the end of the 'main' function?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#90361 - Split - Thu Jun 29, 2006 10:22 pm

Heres my code. when I hold down A(Z Key in VBA) it flashes


Code:
#include "mygba.h"
MULTIBOOT

int main(void)
{
    ham_Init();
    //initialize the text system
    ham_InitText(0);
    while(1)
    {
        //Display opening text
        ham_DrawText(1,2,"Welcome to the Stupid Game");
        ham_DrawText(1,4,"Created by Steven Innis");
        ham_DrawText(1,6,"Press A to Begin");
        // check A button
        if (F_CTRLINPUT_A_PRESSED)
        ham_DrawText(1,2,"                          ");


    }
    return 0;
}

#90366 - gauauu - Thu Jun 29, 2006 10:37 pm

Since the code to write the opening text is also in your while loop, whenever you press the button, it clears the text, then reaches the top of your for loop, and immediately redraws the text in question.

You could move the opening text drawing lines outside the for-loop, and try again.

#90373 - Split - Thu Jun 29, 2006 11:44 pm

Ok I got this now but it wont work. Its not that it gets an error just when you run it the text wont show up at all. when I comment out the other function it works fine. Did i call the function wrong? If I did what do I need to fix?

Code:
#include "mygba.h"
MULTIBOOT

int main(void)
{
    ham_Init();
    //initialize the text system
    while(1)
    {
        //Display opening text
        ham_DrawText(1,2,"Welcome to the Stupid Game");
        ham_DrawText(1,4,"Created by Steven Innis");
        ham_DrawText(1,6,"Press A to Begin");
        CheckForA();
    }
    return 0;
}

void CheckForA(void)
{
    //initialize the text system
    ham_InitText(0);
    while(1)
    {
        // check A button
        if (F_CTRLINPUT_A_PRESSED)
        ham_DrawText(1,2,"                          ");
    }
}


Here are the warnings I got

main.c: In function `main':
main.c:14: warning: implicit declaration of function `CheckForA'
main.c: At top level:
main.c:20: warning: type mismatch with previous implicit declaration
main.c:14: warning: previous implicit declaration of `CheckForA'
main.c:20: warning: `CheckForA' was previously implicitly declared to return `int'

#90481 - Azenris - Fri Jun 30, 2006 12:38 pm

I've never used Ham before but this might work, reason for calling the function bad is its being called before being declared

Code:

#include "mygba.h"
MULTIBOOT

void CheckForA(void)
{   
    while(1)
    {
        // check A button
        if (F_CTRLINPUT_A_PRESSED)
        ham_DrawText(1,2,"                          ");
    }
}

int main(void)
{
    ham_Init();
    //initialize the text system
    ham_InitText(0);
    while(1)
    {
        //Display opening text
        ham_DrawText(1,2,"Welcome to the Stupid Game");
        ham_DrawText(1,4,"Created by Steven Innis");
        ham_DrawText(1,6,"Press A to Begin");
        CheckForA();
    }
    return 0;
}



Note: If you want the function CheckForA to be below the main (although the main is usually at the bottom) you will need to make a prototype at the top of the file.

#include "mygba.h"
MULTIBOOT

// prototye
void CheckForA(void);

// main
int main(void) (
can call CheckForA() in here now
}

// function
void CheckForA(void) {
(...)
}

#90537 - Cearn - Fri Jun 30, 2006 6:20 pm

What he said.

And just to address the next problem you'll probably run into: yes, the text won't flash anymore but you're stuck in the loop in CheckForA(). At that point you could a] use that loop as the main loop (which is probably not what you had in mind), or b] break it off when you hit A, which will only put you back it the situation you started at. I think that gauauu has something like this in mind:

Code:
int main(void)
{
    ham_Init();
    //initialize the text system
    ham_InitText(0);

     //Display opening text
     ham_DrawText(1,2,"Welcome to the Stupid Game");
     ham_DrawText(1,4,"Created by Steven Innis");
     ham_DrawText(1,6,"Press A to Begin");

     while(1)
     {
        // check A button
        if (F_CTRLINPUT_A_PRESSED)
        {
            ham_DrawText(1,2,"                          ");
            break;
        }
    }

    // rest of code

    return 0;
}


Also, I have a feeling you might benefit from Finite State Engines. Don't have a nice example to show you here though. I'm sure the others can provide.