You are not logged in.

#1 2008-08-24 14:44:44

totoro
Member

dont understand behaviour of (simple) program

hello,

Making some littles tests using this lib, I got some strange behaviour.
the program should display a counter increasing by one every seconds from 0 to 10, but I'm getting
something more like 2, 5, 4, 7, 6, 9, 10, 9, 1, 0, 3, 2,...

here is the program , if somebody can understand what the problem is...

smile


====================================================================
#include "main.h"

#define STEP_MENU        0
#define STEP_GAME        1
#define STEP_QUIT        2


int main()
{
    VIDEO_Init();
    WPAD_Init();
    WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
    GRRLIB_InitVideo();
    GRRLIB_Start();

    WPAD_ScanPads();
    WPAD_IR(WPAD_CHAN_0, &currentCursorLocation);

    gameStage = STEP_MENU;
    txHand = GRRLIB_LoadTexture(hand);
    txGrab = GRRLIB_LoadTexture(grab);

    while( gameStage != STEP_QUIT )
    {
        WPAD_ScanPads();
        WPAD_IR(WPAD_CHAN_0, &currentCursorLocation);

        switch( gameStage )
        {
            case STEP_MENU:
                runMenu();
                break;
            default:
                break;
        }

    }
    WPAD_Shutdown();
  return 0;
}


void runMenu()
{

    int cpt_x=0;
    int j=0;
    char debugtxt[20];
    txFont=GRRLIB_LoadTexture(GRRLIB_font1);

    GRRLIB_FillScreen(0xFF000000);
    while (WPAD_ButtonsHeld(WPAD_CHAN_0) & (WPAD_BUTTON_A)) WPAD_ScanPads();
    while ( !(WPAD_ButtonsHeld(WPAD_CHAN_0) & (WPAD_BUTTON_A)) )
    {
        WPAD_ScanPads();
        WPAD_IR(WPAD_CHAN_0, &currentCursorLocation);

        GRRLIB_FillScreen(0xFF000000);
        sprintf (debugtxt,"cpt_x=%d, j=%d",cpt_x,j);
        GRRLIB_Printf(10, 10, txFont, 0xFFFFFFFF,2, debugtxt);
        GRRLIB_Render();

        usleep(1000000);
        ++cpt_x; if (cpt_x >10) cpt_x=0;

    }

    if( (WPAD_ButtonsHeld(WPAD_CHAN_0) & WPAD_BUTTON_HOME) )
        gameStage = STEP_QUIT;
}
====================================================================

Offline

 

Board footer

Powered by FluxBB