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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:34:41+00:00 2026-06-01T14:34:41+00:00

I am trying to make a onTouchEvent to create a missile that will launch

  • 0

I am trying to make a onTouchEvent to create a missile that will launch from my character sprite and forward.
I have this working using

        if (missdraw = true){
            canvas.drawBitmap(missile,missilex,missileY,null);
            missilex = missilex + 14;
            missdraw = false;
        }

in my onDraw method, but the problem is it will only create one at a time.
I tried to create a class to deal with this, but this just causes an error and crashes when i try to fire.
here is what i use for the class: (this is in the ondraw in my gameview)

        for (Batcher missile : missiles ){
            missile.onDraw(canvas);
        }

this is in the class

public Batcher(List<Batcher> temps, ScreenActivity newView, float x,
        float y, Bitmap missile){

    this.x = 1;
    this.y = 2;
    this.missile = missile;

}

public void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    canvas.drawBitmap(missile, x,y, null);

}

I would appreciate any help, but also if you could explain how it would work, instead of just code, as im quite new to programming, and really need to understand what im doing and why im doing it, rather than just copying peoples code because it works.

Cheers Phil.

  • 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-01T14:34:43+00:00Added an answer on June 1, 2026 at 2:34 pm

    Your concepts are pretty good, actually. There are a few things I don’t quite understand about the code samples you posted up, I’ll try to translate into what I’d do and you can tell me if I’m doing it wrong 🙂

    in your game class you need (and it looks like you have) a list of Missiles:

    LinkedList<Batcher> missiles;
    

    In your onTouch(), however a missile is created –

    missiles.add(new Batcher(missilex, missiley, missile));
    

    you now have a collection of missiles. Note that I didn’t include the list in the constructor of your batcher, because an object should never need to know that it’s a part of a collection. All it needs to know is how to draw itself and where. Since I assume that all of your missiles will be added to or removed from the screen frequently, while only having a few on screen at a time, I’ve used a LinkedList, which is fast for adding and removing, but slow for accessing a specific missile. If you needed to access specific items in the collection and the collection didn’t change very much, you would use an ArrayList instead. on to onDraw – as you have it the missile draws itself, which is fine, but I prefer to let the View do the drawing, with the missile telling it where it should be drawn –

    for (Batcher missile : missiles ){
      missile.setX(missile.getX() + 14); // to make it move
      if (missile.getX() > canvas.gedWidth()) { //check if it's left the screen
        missiles.remove(missile); // Remove it
      }
      else { //perform drawing
        canvas.drawBitmap(missile.getBitmap(), missile.getX(), missile.getY(), null);
      }
    }
    

    Hopefully that’ll do it for you, but feel free to let me know if there’s anything you’d like me to explain more!

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

Sidebar

Related Questions

im trying make one replace in string from a array but this dont work
Trying to make simple jQuery function to create a scrollToTop button that fades in
I'm trying make this code which is from a Dictionary of Arrays (CODE) from
Trying to make a custom :confirm message for a rails form that returns data
trying to make a page which will recursively call a function until a limit
Trying to make a simple program to catalogue books. Something like this, for example:
Trying to make a simple program to catalogue books. Something like this, for example:
Trying to make simple minesweeper game in python, but have one problem. I have
Trying to make a toggle button that hides/shows the right window/pane. Here is a
I'm trying make a static text which if too long for the sizer, will

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.