Jump to content

  • Log In with Google      Sign In   
  • Create Account

Draw sprite in object class and return to main class


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 vastrolorde   Members   -  Reputation: 110

Like
0Likes
Like

Posted 25 April 2013 - 12:19 PM

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??

 



Sponsor:

#2 Glass_Knife   Moderators   -  Reputation: 5056

Like
0Likes
Like

Posted 25 April 2013 - 12:33 PM

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


I think, therefore I am. I think? - "George Carlin"
Indie Game Programming

#3 vastrolorde   Members   -  Reputation: 110

Like
0Likes
Like

Posted 25 April 2013 - 02:03 PM

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



#4 Glass_Knife   Moderators   -  Reputation: 5056

Like
0Likes
Like

Posted 25 April 2013 - 08:11 PM

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.


I think, therefore I am. I think? - "George Carlin"
Indie Game Programming

#5 vastrolorde   Members   -  Reputation: 110

Like
0Likes
Like

Posted 26 April 2013 - 12:49 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS