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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:58:09+00:00 2026-06-13T14:58:09+00:00

Probably a very basic Java problem but I have two variables in a entity

  • 0

Probably a very basic Java problem but I have two variables in a entity class:

public class Entity {

int posX;
int posY;

public Entity(int posX, int posY){
    this.posX = posX;
    this.posY = posY;
}

public void update(){

}

public void draw(Graphics2D g2d){

}

}

My player and enemy class extend it and then render off of the two variables. Like so:

public void draw(Graphics2D g2d) {
    g2d.drawImage(getPlayerImg(), posX, posY, null);
    if (showBounds == true) {
        g2d.draw(getBounds());
    }
}

I need to access these variables like this (This is in my enemy class):

public static void moveFemale(){
    if(posX <= Player.posX){
        //do AI code
    }
}

posX And Player.posX throw an error saying I need to change the modifier of posX in Entity.java to static. But when I change it to static, my renderer for the enemy class stops working and the enemies no longer show up on screen. How could I go about creating a variable that allowed me to do this:

public static void moveFemale(){
    if(posX <= Player.posX){
        //do AI code
    }
}

And still render my enemies? Sorry for the wall of text and any answers would help a lot!

  • 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-13T14:58:10+00:00Added an answer on June 13, 2026 at 2:58 pm

    The moveFemale method is static so it needs to know which female to move. Either pass in a reference to the palyer or find a may to make the move methods non-static member methods of the player.

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

Sidebar

Related Questions

OK, this is probably very basic, but I can't find the problem. I'm trying
Problem : This is a probably a very basic question, but how do I
I have a probably very basic problem with PIL's crop function: The cropped image's
I realize that this is probably a very basic question, but I have spent
Probably a very basic beginner question. Imagine the following situation: I have an ASP.NET
Okay, this is probably a very basic question; but, I'm just getting back in
I'm probably missing something very basic but I cannot figure out why I get
This is probably very basic stuff, but please bear in mind I am completely
This is probably something very basic, but my Erlang installation is doggedly rejecting my
This is probably very basic, but it's giving me a headache, and I'm not

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.