Allegro help-o

This is a discussion on Allegro help-o within the Game Programming forums, part of the General Programming Boards category; hey Vicious i tried this and works really well: Code: #include <allegro.h> int counter; int x = 300, left = ...

  1. #31
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    hey Vicious i tried this and works really well:

    Code:
    #include <allegro.h>
    
    
    int counter;
    int x = 300, left = 0, right = 0;
    
    void update_counter()
    {
         counter++;
    }
    END_OF_FUNCTION(update_counter);
    
    int main()
    {
       allegro_init();
       install_keyboard();
    
       LOCK_VARIABLE(counter);
       LOCK_FUNCTION(update_counter);
       install_int_ex( update_counter, BPS_TO_TIMER(60));
    
       set_color_depth(32);
       set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);
    
       BITMAP *ship = load_bitmap( "ship.bmp", NULL );
    
       draw_sprite ( screen, ship, x, 300 );  
       
       while ( !key[KEY_ESC] ) 
       {   
          
            while (counter > 0) { 
               if (left)  x-=5;
               if (right) x+=5;
               counter--; 
            }
          if ( x < 540 && key[KEY_RIGHT])
                right = 1;
            else 
                right = 0; 
            if ( x > 50 && key[KEY_LEFT])
                left = 1;
            else 
                left = 0; 
    
            vsync();
            clear_to_color (screen, 0);
            draw_sprite ( screen, ship, x, 300 );
            
       } 
    
    
       destroy_bitmap(ship);
       allegro_exit();
       return 0;
    }
    END_OF_MAIN();
    the only problem is that it messes up a tiny bit at the beginning and it leaves a trail once you move the bmp. however, there isn't any flickering at all right after the beginning.

  2. #32
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    yup, if you dont put in the buffer thingy it will leave a trail i think....

    it will work better than the clear(screen) or the clear_to_color...

    try it?
    What is C++?

  3. #33
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    I just tried the vsync() before you blit and it flickers way too much. My above code (well mostly yours actually ) works the best so far.

  4. #34
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    does you clear(screen) method leave a trail?
    What is C++?

  5. #35
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    replacing clear to color() with clear(screen) doesn't work as well in that example doesn't work as well.

  6. #36
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    how bad was the flicker when it didnt leave a trail?

    bad bad?

    screenshot?

    sorry, ill quit asking these stupid questions when i get to my computer
    What is C++?

  7. #37
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    It's bad enough that it would not be acceptable in a game. The trail is not nearly as bad as the flickering. I'm trying some things out right now.

    What I've been trying to do is to not blit the bmp but only blit the bmp when the bmp is moved. So if the bmp is not being moved there shouldn't be any flickering. But everytime I try this I mess everything up entirely.

  8. #38
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    have you tried

    Code:
    if ( keypressed() )
    {
        //do the vsync(), draw_sprite(), blit....
    }

    and what kind of trail we talkin bout? you mean like a blur? or an actual trail?
    What is C++?

  9. #39
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    yeah i tried that...basically anytime blit is involved there is a lot of flickering.

    the trail is just like a blur. it's not all that bad but of course you'd rather have it without a blur.

  10. #40
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    oh, that blur.... yah its just part optical part bright color moving fast against a black background



    its rally unavoidable if it is what im thinking
    What is C++?

  11. #41
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Oh well then that's awesome, and I'm sure you're right, too.

  12. #42
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    I have a question. If somebody uses your program on their computer and they don't have allegro installed what files will they need? I even had the person get the allegro40.dll file and my program still wouldn't work. he tried both in the folder of the program itself and in the windows/system folder. For some reason it would never work. I'm above 100% positive that it is not because of the program. The program works perfectly fine for me. Are there any other files that person needs in order to execute my program?

  13. #43
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    If you staticly link it, they do not need the files. And it is not the blit creating the flicker, it is the clearing of the screen. Just use two screen buffers. Draw to the back one, then when that is done, flip it to the front one (don't blit it) and it should not flicker.

  14. #44
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    I am downloading the latest version of Allegro, if I can get it working with C++ Builder I am gonna figure out the best way to move sprites without flicker.

  15. #45
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    tech... i used vsync() before that last blit and it did fine until i went up into lower y coords... (top of screen )
    What is C++?

Page 3 of 8 FirstFirst 12345678 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Allegro in C for a newb
    By Ideius in forum C Programming
    Replies: 5
    Last Post: 12-29-2005, 03:36 PM
  2. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 02:00 AM
  3. double buffering for allegro
    By Leeman_s in forum C++ Programming
    Replies: 6
    Last Post: 09-12-2002, 02:45 PM
  4. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM
  5. Allegro programming in a window
    By Person Man in forum Windows Programming
    Replies: 0
    Last Post: 11-16-2001, 02:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21