Allegro Help Needed!

This is a discussion on Allegro Help Needed! within the C++ Programming forums, part of the General Programming Boards category; Hey there. I'm currently programming a small 2D, RPG game and today I have included a function which opens up ...

  1. #1
    Registered User godly 20's Avatar
    Join Date
    Jan 2011
    Location
    Italy
    Posts
    29

    Exclamation Allegro Help Needed!

    Hey there. I'm currently programming a small 2D, RPG game and today I have included a function which opens up an inventory.
    Code:
    void OpenInventory()
    {
         if(key [KEY_I])
         {    
                draw_sprite(backbuffer, inventory, 500, 250);
                readkey();
         }
    }
    So the problem is that whenever I press any key, the inventory closes. Is there a way to avoid this and allow the user to interact with the inventory window as long as it is open?
    "A Computer in every desk and in every home, running Microsoft software."

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    I rather think that before anyone is going to take you very seriously you're going to need to clean up your avatar and your signature...

    That's some pretty offensive stuff.

  3. #3
    Registered User godly 20's Avatar
    Join Date
    Jan 2011
    Location
    Italy
    Posts
    29
    Done. Thanks for pointing it out. Didn't realise that it could be offensive to someone.
    "A Computer in every desk and in every home, running Microsoft software."

  4. #4
    Registered User
    Join Date
    Dec 2010
    Posts
    48
    I'm not sure.. but in the examples I was learning with, the readkey comes at the end(I assumed to exit) So maybe when you press I, it calls readkey and immediately shuts down?

  5. #5
    Registered User godly 20's Avatar
    Join Date
    Jan 2011
    Location
    Italy
    Posts
    29
    Quote Originally Posted by MattJ812 View Post
    I'm not sure.. but in the examples I was learning with, the readkey comes at the end(I assumed to exit) So maybe when you press I, it calls readkey and immediately shuts down?
    It shuts down immediately, yes, but it does that with any key while it's only supposed to open/close when the "I" key is pressed. However I've solved this problem by making a fixed sidebar in which the inventory is always open and it swithces to the skills interface if you press the "S" key.
    "A Computer in every desk and in every home, running Microsoft software."

  6. #6
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    readkey() blocks once you press a key it goes past that and returns from the function.... if you want it to stay up and have keys for interaction I would put it in a loop and check key against 'q' and 'Q' or some such as an escape character... redraw to buffer each loop and blit to screen. Do not put blocking commands in the loop as it will cause performance issues if you are doing anything in the background.

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. problem in allegro with sprite leaving trail
    By Leeman_s in forum C++ Programming
    Replies: 18
    Last Post: 09-13-2002, 03:04 PM
  4. double buffering for allegro
    By Leeman_s in forum C++ Programming
    Replies: 6
    Last Post: 09-12-2002, 02:45 PM
  5. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM

Tags for this Thread


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