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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:54:43+00:00 2026-06-01T07:54:43+00:00

In Java I have created the following class which extends ImageView to create a

  • 0

In Java I have created the following class which extends ImageView to create a character… I want to know if it is possible to add another image of the item my character is holding (see method “addWeapon()”) which will move when my character moves (see method “warriorMover(..)”). Basically, I was wondering if it is possible to make the “weapon image” sort of a “characteristic/part” of the main character?

public class WarriorEntity extends ImageView
{
private kingsColor kingColor;
private weapons weaponId;

private int kingSide;
private int warriorId;
private int nLeft;
private int nTop;

public WarriorEntity(Context context)
{
  super(context);
}

public void defineWarrior(kingsColor a1, weapons a2, int a3, int a4, int a5, int a6)
{
  kingColor = a1;
  weaponId = a2;
  kingSide = a3;
  warriorId = a4;
  nLeft = a5;
  nTop = a6;

  switch (kingColor)
  {
    case blue:
      this.setImageResource(R.drawable.bluewarrior);
      break;
    case green:
      this.setImageResource(R.drawable.greenwarrior);
      break;
    case purple:
      this.setImageResource(R.drawable.purplewarrior);
      break;
    case red:
      this.setImageResource(R.drawable.redwarrior);
      break;
    case white:
      this.setImageResource(R.drawable.whitewarrior);
      break;
    case yellow:
      this.setImageResource(R.drawable.yellowwarrior);
      break;
  }
  this.setId(warriorId);
  this.setOnClickListener(WarriorClick);
  setImagexy(this, nLeft, nTop, 20, 30);
}

public void addWeapon()
{
  switch (weaponId)
  {
     case bowandarrow :
        break;
     case mace :
        break;
     case spear :
        break;
     case sword :
         // - Here I would want some code to add the weapon image which as if it were part
              of the same image as the character... moves/reacts with the character.
        break;
  }
}

public void warriorMover(int leftX, int topY)
{
  setImagexy(this, leftX + 8, topY - 3, 20, 30);
}

“setImagexy” is a custom method which does exactly that… moves an image to a given location on the screen.

  • 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-01T07:54:44+00:00Added an answer on June 1, 2026 at 7:54 am

    Different approaches could be used :
    making a copy of the default sprite and drawing the sword on top of it (a good approach in case you don’t need to update the sprite too often

    or you could just render the sword on top of the sprite after you have drawn the character sprite:

    render_loop()
    _>draw_characterSprite()
    __>draw_equipment()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here I create a class in JAVA in which I have function (callback) which
I am using POI 3.8 to create Excel sheets using Java I have created
I have created a java application for Debian Linux. Now I want that that
I have created a java server, which takes screenshots, resizes them, and sends them
I have a simple Action class which I want to unit test: package com.gam.action.test;
I need to make a Class named TriangleShape which impliments java.awt.Shape. Now another Class
I have a java class which fires custom java events. The structure of the
I am using netbeans for developing java dextop application,I have created a JFilechooser which
I have a method that contains the following (Java) code: doSomeThings(); doSomeOtherThings(); doSomeThings() creates
I have created a java application and packed it into a jar file on

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.