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 7663819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:08:46+00:00 2026-05-31T14:08:46+00:00

I have implemented tic tac toe game as it is from api samples.from that

  • 0

I have implemented tic tac toe game as it is from api samples.from that tic tac toe game i would like to draw a bitmap instead of lines.I have written a peace of code as follows at onTouchEvent:

 @Override
    public boolean onTouchEvent(MotionEvent event) {

     if (event.getAction() == MotionEvent.ACTION_DOWN) 
     {
    RectF rct=_logic.getPositionToFill(event.getX(), event.getY());

    if(rct!=null)
    {
     if(_drawX)
     {

         _bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.smile);

         _canvas.drawBitmap(_bitmap, 0.0f, 0.0f, _paint);

        /* _canvas.drawLine(rct.left, rct.top,
                 rct.right, rct.bottom, _paint);


         _canvas.drawLine(rct.right, rct.top,
                 rct.left, rct.bottom, _paint);*/

     }
     else
     {

           _bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.sad);

         _canvas.drawBitmap(_bitmap, 0.0f, 0.0f, _paint);

     //          _canvas.drawOval(rct, _paint);

     }
     _drawX=!_drawX;

     invalidate();

    }
    }
    return true;
    }

I have inserted some code at if block instead of drawLine.

  • 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-31T14:08:47+00:00Added an answer on May 31, 2026 at 2:08 pm

    I don’t know why are you drawing the lines in the onTouchEvent method. In the on onTouchEvent method you just only need to take the cordinates of the touch and draw the picture into onDraw method.

    bitampCross = BitmapFactory.decodeResource(getResources(),R.drawable.cross);
          protected void onDraw(Canvas canvas) {
        Paint background = new Paint();
        background.setColor(Color.WHITE);
        canvas.drawRect(0, 0, getWidth(), getHeight(), background);
        canvas.drawBitmap(backgroundGrid, 10, 0, null);
    
                  if (pos == 1) {
                          canvas.drawBitmap(bitampCross, bitampCross.getWidth() + 20,
                                bitampCross.getHeight() + 15, null);
                                 }
                     if (pos == 2) {
                          canvas.drawBitmap(bitmapCircle, bitmapCircle.getWidth() + 20,
                                          bitmapCircle.getHeight() + 15, null);
                  }
                        }//end of onDraw
    ----------
    
         public boolean onTouchEvent(MotionEvent event) {
         int action = event.getAction();         
         if (action == MotionEvent.ACTION_DOWN) {
           return true;} 
          }else if(action == MotionEvent.ACTION_UP){
           //Do your checks if want to draw the image.
          //For example your board can not take the whole screen 
          //return true or false in this block
         //For example:
          int x = (int) event.getX();
          int y = (int) event.getY();
    
         if(x<200 && y<200)
            return true;
         else
         return false;
    }
    invalidate();
    return false; 
    }//end of onTouchEvente`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am going to develop a Tic-Tac-Toe game using Java(or maybe other OO Languages).
Background: I recently completed a tic-tac-toe game in AS3, using some simple function-based code
I have implemented a simple linked list class and I would now like to
I'm working on a tic tac toe game and am wanting to implement an
I have implemented a simple appmod that handle WebSockets and echo back the messages.
I have implemented the database as follows from google.appengine.ext import db from google.appengine.ext import
We have implemented a drag and drop feature that shows a nice simple representation
I have implemented a version of Rush Hour (the puzzle board game) in Python
I have implemented the Url Helper extensions that Kazi Manzur has suggested in his
I have implemented a custom designer class which inherits from DocumentDesigner. The standard Form

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.