Sign in to follow this  
Marko T

Draw sprite in object class and return to main class

Recommended Posts

Marko T    110

Im trying to make a simple game. I have the basic understanding of spreadsheet and the coding itself, but im havign problems now and then.
Can i place the drawImage function in my object class so that i can return it anywhere i want. example. Boar.java has a line

if(boss.isVisible())
   boss.drawBoss();

adn the Boss.java has this
 

public Image drawBoss(){
     Graphics g
     Graphics2D g2d = (Graphics2D)g;
     return g2d.drawImage(.....)
}

 

So how to i make this work???

 

Share this post


Link to post
Share on other sites
Glass_Knife    8636

The Graphics objects comes from Swing.  If you have a swing component, such as a JPanel, is will contain a paint method that will be called and passed a graphics object:

 

public class MyClass extends JPanel {

   public void paint( Graphics g ) {
      // use graphics object here
   }

}

 

 

Take a look at this to get started:

 

http://www.gamedev.net/page/resources/_/technical/general-programming/java-games-active-rendering-r2418

Share this post


Link to post
Share on other sites
Glass_Knife    8636

So, as i understand, all the painting must be done int that one function, but i can send all the attributes to it.

 

Something like that.  Try it out and see what happens.

Share this post


Link to post
Share on other sites
Marko T    110

Sending the attributes isnt a problem. i just want to animate the movement and i had an idea with the frame switching, but it had to be built in the object. Now i need to think up a differetn way to change frames.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this