Posted: 1st Dec 2011 8:05
Hello!

I'm working with XCode T2 4.x and I have a problem with 'GetSpriteHit' and 'GetPointerPressed'.

When I try to use these commands from a 'do ... while' loop from a different file than main.cpp (for example), it seems that this commands do not work (Sync () included in the do-while loop) if are not called from the loop of the main application.

I need to use the do-while loops to avoid making constant calls to the main loop of the application, in cases such as message windows, etc..

Am I doing something wrong? Could be a bug?

Thanks in advance.
Posted: 1st Dec 2011 9:55
As far as I know, you can only Sync() within app::Loop
Posted: 1st Dec 2011 12:13
Hi bjadams

Nop, it can be done anywhere you need.

For example, in my game I have a menu that makes a scroll to be displayed or not. Its placedthis in a separate .cpp file and the only precaution is to include the header file agk.h.

Here the code:

+ Code Snippet

// (3) SHOWS THE UPPER MENU GAME (UP/DOWN) tit_sound_upper_gm_mnu


void do_show_upper_menu_01()
{

    
#ifdef MIDEBUG

    
    agk::Print("do_show_upper_menu_01() ");


#endif
 

   
    
    float m, n, k;

 
   
    if (flip_flop_menu_sup == TRUE) // Up the Menu 
    {

        m = agk::GetSpriteY( menu_sup_p1_Bckgrd_ID  );
        n = agk::GetSpriteY( tit_exit_game_menu_ID  );
        k = agk::GetSpriteY( tit_opts_pause_ID      );
 
       
        do {
  
          
            agk::SetSpritePosition ( menu_sup_p1_Bckgrd_ID,          0,  m     );
            agk::SetSpritePosition ( tit_save_gm_from_upper_gm_menu, 5,  n + 1 );
            agk::SetSpritePosition ( tit_restart_upper_menu_gm,      23, n -1  ); 
            agk::SetSpritePosition ( tit_sound_upper_gm_mnu,         63, n     );
            agk::SetSpritePosition ( tit_exit_game_menu_ID,          46, n     );
            agk::SetSpritePosition ( tit_cancel_upper_gm_mnu,        81, n + 1 );
            agk::SetSpritePosition ( tit_opts_pause_ID,              76, k     );            
                        

 
            m = m - 1;
            n = n - 1;
            k = k - 1;
 
 
          
            agk::Sync ();  // <<<<<<<

 
           
        } while (m >= -17);
 
       
        // Delete Pause title

                
        int z = 255;

        
        for (int f = 0; z > 0; f++)
        {

            agk::SetSpriteColor ( tit_pause_ID, 255, 255, 255, z ); 

            
            z = z - 30;
 
           
            agk::Sync();  // <<<<<<<<<< 

 
        };

        
        agk::DeleteImage ( tit_pause_ID  );
        agk::DeleteSprite( tit_pause_ID  );

?.

?.

?.




As you can see I made two calls to agk::Sync () with no problems. My problem is that in do-while loops run all commands but those two ...
Posted: 1st Dec 2011 12:30
Are you missing an include?
Posted: 1st Dec 2011 12:37
Hi baxslash

No... And there are a lot of agk commands in the same file and work fine. But watching the debuger, it reads GetPointerX and Y ok, reads the GetSpriteHit and jumps the 'if' it must read!

Later I'll post the code (I deleted It!!)
Posted: 1st Dec 2011 13:47
Hello again

I rewrote the code that generates the problem. Here it is:

+ Code Snippet


// This two functions are in a separated .cpp file


// THIS FUNCTION IS CALLED FROM THE MAIN APP LOOP
// AND WORKS FINE

void do_CheckInputMainScreen()
{ 
    
...

... 
    
    // Check if one of the options is clicked or pressed

   
    float x = agk::GetPointerX();
    float y = agk::GetPointerY();

       
    float hitsprite = agk::GetSpriteHit(x, y);

	       
    if (agk::GetPointerPressed( ) == 1 and hitsprite == tit_exit_app_mainscr_ID)
    { 
 
        do_click();                 

        
        // Paints the exit msg window of the Main menu with 
	// 'Yes' and 'Cancel' button opts.

        
        do_create_exit_wnd_from_main(); // (3) Local function


	// Ok, the window and the two buttons are painted.
        // Now we call another local function to check the two btns.
	// created by the last function.


	do_check_exit_window_from_main(); 


	// The function is defined down 
...

...
    
 };



// THIS FUNCTION IS CALLED FROM THE UPPER FUCNTION
// AND FAILS. IF THIS FUNCTION IS CALLED FROM THE MAIN LOOP
// INSTEAD OF ANOTHER FUNCTION, IT WORKS FINE! 


void do_check_exit_window_from_main()
{
    
    int i = 0; // TO EXIT OF THE LOOP

    
    do {
        
        float x = agk::GetPointerX()             ;
        float y = agk::GetPointerY()             ;
        float hitsprite = agk::GetSpriteHit(x, y);

       

	// GetPointerX and GetPointerY gets the correct values.
	// hitsprite gets the correct ID sprite.
	// BUT THIS 'IF' IS READED BUT NOT EXECUTED!

       
        if ( agk::GetPointerPressed( ) == 1 and hitsprite == tit_yes_btn_wnd_exit_frm_main)
        {  

            do_click(); // Its a local function playing a click

                                    
            i = 1; // Index to exit of the 'do'
                        
        };
        
                
        // GetPointerX and GetPointerY gets the correct values.
	// hitsprite gets the correct ID sprite.
	// BUT THIS 'IF' IS READED BUT NOT EXECUTED!

               
        if (agk::GetPointerPressed( ) == 1 and hitsprite == tit_cancel_btn_exit_wnd_from_main)
        {  

            do_click();
                        
        };

        
        agk::Sync();

        
    } while (i == 0);


    // END do_check_exit_window_from_main 

};





I hope you can help me. Greetings!
Posted: 2nd Dec 2011 15:43
In tier 2 you must avoid do while loops that wait on user input, since the input commands are updated by the device which can't do anything until you return from the loop. Also spending a long time looping in App.Loop() or App.Begin() without returning may cause the device to terminate your app thinking it is not responding.

Note this does not apply to tier 1 as the interpreter handles all the returning to device automatically.
Posted: 3rd Dec 2011 0:03
Tier 1 are lucky! Thank you very much for the information Paul. I think I'll have to make several important changes in the structure of my program.

A question. It may be silly but, is it possible to deceive the device by creating a sub process while waiting for user input?

regards
Posted: 8th Dec 2011 0:06
In T2, you can do a lot of deceiving, depending on your C++ skills. As a native application, you can hack in pretty much anything you can dream up - at your own risk
Posted: 8th Dec 2011 10:03
Sorry guys but I cannot understand why you want to be limiting yourself to T1 when the T2 command set is practically identical!
Posted: 8th Dec 2011 19:04
Thanks Paul.

@Lee, I said, a silly question? I think at that time I had my mind wandering through cyberspace.

Well... really the matter is that it is curious that these commands do not work in a 'do - while' (called from a function, otherwise I have not tried) even having loaded all the logic and variables to run an 'if'. Tracking in the XCode debugger, it is hooked in the asm. I say, a curiosity.

In my opinion this is not a bug but a logical consequence. If in T2 you exit the loop 'app:' some commands remain on a siding. The solution is simple: bring them back to the main loop.

@bjadams You're absolutely right. In my case I used T1 only for a week in order to test it. Then I go immediately to T2, which leverages the power of both languages.

I do not remember where I read that AppGameKit team explicitly stated that T1 is a language of initiation, but to get the best performance had to work with T2. The reality is that between T1 and T2 there is a big difference in performance. Although I'm seeing here that the companions of T1 are doing great jobs!

Regards

.
Posted: 8th Dec 2011 19:26
I never tested T1 myself, I started with T2 from day 1.

I am developing 2 games. Framerate is at 60fps on iphone 3gs (doesn't use any physics though). Can't seem to throw enough data to AppGameKit to make it slow down!!!!
Posted: 8th Dec 2011 20:19
Yes! I think T2 is its natural environment. 60 fps are very very good results. I'm working on an adventure game and I can assure you that when I did the first test in the IPad I was amazed.

Please keep me informed of your two games!

regards


.