Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8566397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:38:45+00:00 2026-06-11T17:38:45+00:00

I’ve recently tried making an inventory system in allegro 5, where I draw a

  • 0

I’ve recently tried making an inventory system in allegro 5, where I draw a grid of squares 20×20 and drag-drop items around. The problem is, I can see the item sprite going under the actual grid that I drew, which is an unwanted effect. Here’s my code:

if(draw)
        {
            draw = false;
            al_draw_bitmap(image, item.posx, item.posy, 0);

            if(mouseKey)
               {
                   grab = true;
                   item.posx = mouse.posx - (item.boundx-5);
                   item.posy = mouse.posy - (item.boundy-5);
               }

            else if(mouseKey == false && grab == true)
            {
                for(int i = 0; i < mouse.posx; i += 20)
                {
                    if(i < mouse.posx)
                        item.posx = i;
                }
                for(int j = 0; j < mouse.posy; j += 20)
                {
                    if(j < mouse.posy)
                    {
                        item.posy = j;
                    }
                }
                grab = false;
            }

            for(int i = 0; i <= width; i += 20)
            {
                al_draw_line(i, 0, i, height, al_map_rgb(0, 0, 0), 1);
                al_draw_line(0, i, width, i, al_map_rgb(0, 0, 0), 1);
            }

            al_flip_display();
            al_clear_to_color(al_map_rgb(40,40,40));
        }

(I know it’s terribly written and un-optimized but I wrote it in about 10 minutes simply as a test)

How can I make it so the item sprite does not display the lines over it? Here’s an example of my problem if I was too vague:

My problem

I’m using Codeblocks IDE on windows XP

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:38:46+00:00Added an answer on June 11, 2026 at 5:38 pm

    Unless you fiddle with OpenGL settings, you’re going to always get the things you draw last on top. So in this case, simply move al_draw_bitmap(image, item.posx, item.posy, 0); to be directly above al_flip_display().

    Note that you will have some problems because you are manipulating item.posx and item.posy in that section, so you’d have to first cache the results:

    int x = item.posx;
    int y = item.posy;
    
    // ... 
    
    al_draw_bitmap(image, x, y, 0);
    al_flip_display();
    

    However, that’s just a bandaid over the larger problem: you shouldn’t be changing anything inside your drawing block. The entire if/else block should be elsewhere. i.e.:

    if (event timer is a game tick)
    {
      do all logic stuff
      draw = true
    }
    
    if (draw)
    {
      do all drawing stuff
      draw = false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.