We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › custom Image class
Page Index Toggle Pages: 1
custom Image class? (Read 633 times)
custom Image class?
May 26th, 2009, 2:56pm
 
I made an abstract class Thing that has properties for xpos, ypos, rate, and heading. It has methods for moving and bouncing off the side of the screen.

Subclasses to the Thing class include a Dot class and a Tile class, which add properties for size and hue and an update() method for actually doing the drawing. (I believe "subclass" is the right word? I'm still new to OOP.)

I want to add a Image class that would extend Thing and allow PImages to bounce and move like their sibling Dots and Tiles. First off, is creating an Image class to extend Thing the right way to go about this? If so, how do I pass the file name to the Image constructor?
Re: custom Image class?
Reply #1 - May 27th, 2009, 12:52am
 
Yes, subclass is a common term.
And your approach seems good.
I am not too sure about your last question, about what is confusing you.
Perhaps that's because Thing has already a constructor
You can make a constructor (or even several!) specific to Image, with whatever parameters you want/need. It just have to call super() .
I just found a page explaining that quite clearly: More About Constructors.
Re: custom Image class?
Reply #2 - May 27th, 2009, 8:51pm
 
Ah so, PImage is a datatype, and Thing and Image are both datatypes. I understand that my Image class will have a PImage attribute (in addition to the rate and heading attributes inherited from Thing).

Is it possible to create the PImage with each new object? I'm trying to send, say, "sailboat.png" as a String to the Image constructor and have the constructor load sailboat.png as a PImage, but for some reason this isn't working.
Re: custom Image class?
Reply #3 - May 28th, 2009, 2:31am
 
Quote:
Is it possible to create the PImage with each new object?
Yes.

Quote:
for some reason this isn't working.
Perhaps a bug in your code? Wink
Page Index Toggle Pages: 1