Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

draw method

 
anthony cosgrave
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think this is more an applet question than a gaming question - but i apologise to the moderators if it does need to be moved.

my question is this:

I have a Sprite class that will be the super class for any moveable object within my applet: is it possible to code a draw method (for it that will draw the various images that a Sprite may need based on the current action of the sprite, moving up, moving down etc) within the Sprite class, instead of doing the drawing in the Applet class?

i.e.

in the Applet's draw method i could write:

...



sorry if i'm not being totally clear on this, but its been wrecking my head a bit for the last day or so.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anthony,

Welcome to JavaRanch!

Yes, that's a perfectly fine thing to do. There's nothing magic about the paint() or paintComponent() methods -- you can pass the Graphics object to other methods and let them contribute to the drawing.

Now, note that there's a standard way to do this: by making the Sprites themselves "lightweight components" -- i.e., inherit from Component, and override paint() themselves. But you don't have to do it this way if you don't want to.
 
anthony cosgrave
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for the information - i'll try it both was, without make the sprites Components and with them as Components - its all coding experience!

thanks again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic