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

  • Home
  • SEARCH
  • 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 6192289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:55:05+00:00 2026-05-24T02:55:05+00:00

I am trying to draw an image over another image when a user touches

  • 0

I am trying to draw an image over another image when a user touches the screen. But the image only appears when the user touches and then disappears when they let go of the screen.

This is my if method:

int RED = 0;
int GREEN = 1;
Graphics g = game.getGraphics();
int len = touchEvents.size();

if (RED == 0) {
    ready = Assets.readybtntwo;
}

for(int i = 0; i < len; i++) {
    TouchEvent event = touchEvents.get(i);

    if(event.type == TouchEvent.TOUCH_UP){
        updateWaiting(touchEvents);
        RED +=1;

        if (RED == 0)
            ready = Assets.readybtntwo;

        if(RED == 1)
            ready = Assets.readybtngreentwo;
    }

    g.drawPixmap(ready, 0, 0);
}

Sorry I’m using a framework built from the book beginning android games. But it shouldn’t matter, I want the image to stay forever and terminate the if loop.

  • 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-05-24T02:55:06+00:00Added an answer on May 24, 2026 at 2:55 am

    You have a logic error here. It looks like the variable RED is local to your method if the above code is all inside the touch event handler. This means that when the user touches the screen each time it’s reset to 0 and then becomes 1 again. This probably isn’t what you want.

    The reason that it’s only rendered is that g.drawPixmap will either be submitting an element to a draw queue or rendering it immediately. This method to draw the button is only ever being drawn when you have a touch event!

    Instead, you could have a boolean drawGreenReadyButton value as a class member, i.e.

    private boolean drawGreenReadyButton = false;
    

    Then you can change that inner if statement to the following:

    if(event.type == TouchEvent.TOUCH_UP){
        updateWaiting(touchEvents);
        drawGreenReadyButton = true;
    }
    

    And inside your main rendering loop rather than in the touch event handler put:

    if(drawGreenReadyButton) {
        g.drawPixmap(Assets.readybtngreentwo, 0, 0);
    } else {
        g.drawPixmap(Assets.readybtntwo, 0, 0);
    }
    

    Also, consider using TouchEvent.TOUCH_DOWN rather than TouchEvent.TOUCH_UP, so that the button is shown green as soon as they touch the screen, not when they lift their finger up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to draw an image in an ImageView, but i want it to
I'm trying to draw over the whole screen by using the desktop canvas and
I'm trying to draw a line (Red line in the image) over multiple panels,
I'm trying to draw an image to the screen in a UIView subclass I'm
I am trying to draw a transparent (alpha) PNG image using CxImage, but it
I'm trying to draw a transparent.png image over a TV signal (so blending before
I'm using MFC, and I'm trying to draw an image to the screen. I've
I'm trying to draw a semi-transparent shape over an image. I've got a UIView
Working in Visual Studio 2008. I'm trying to draw on a PNG image and
I am trying to draw a series of rectangles using OpenGL but some of

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.