This site requires JavaScript, please enable it in your browser!
Greenfoot back
Upupzealot
Upupzealot wrote ...

2011/11/21

What's Wrong?I want the GreenfootImage Class

Upupzealot Upupzealot

2011/11/21

#
public class GreaterGreenfootImage extends GreenfootImage
mjrb4 mjrb4

2011/11/21

#
What are you trying to do? Extending the GreenfootImage class is probably not what you want to do, but we won't know without a lot more information!
Upupzealot Upupzealot

2011/11/23

#
mjrb4 wrote...
What are you trying to do? Extending the GreenfootImage class is probably not what you want to do, but we won't know without a lot more information!
I'm tring to add a "setTransparencyAt()" function now I wrote a class called GreaterGreenfootImage, which has a GreenfootImage itself But, you know, It's boring to write something like getWidth() How can I change GreenfootImage itself, instead of wirting a new class
bourne bourne

2011/11/23

#
You can have a method that does this setTransparencyAt function on a given GreenfootImage
public void setTransparencyAt(GreenfootImage pic, int transparency, int x, int y)
{
	Color c = pic.getColorAt(x, y);
	pic.setColorAt(x, y, new Color(c.getRed(), c.getGreen(), c.getBlue(), transparency);
}
Upupzealot Upupzealot

2011/11/24

#
bourne wrote...
You can have a method that does this setTransparencyAt function on a given GreenfootImage
public void setTransparencyAt(GreenfootImage pic, int transparency, int x, int y)
{
	Color c = pic.getColorAt(x, y);
	pic.setColorAt(x, y, new Color(c.getRed(), c.getGreen(), c.getBlue(), transparency);
}
yes,that's the same method I used in my program My problem is how can I write this into the GreenfootImage class You know, I can't edit the GreenfootImage class.
mjrb4 mjrb4

2011/11/24

#
Well in this case you *could* extend the GreenfootImage class - there's no technical reason AFAIK why you can't! You would need to provide the appropriate constructors though on your subclass, perhaps that's where you're going wrong? You didn't show us any code so it's hard to say at the moment. In all honesty though I probably wouldn't bother subclassing unless there's a bunch of methods you want to write on it.
davmac davmac

2011/11/24

#
Upupzealot: What code did you try, and what error message did you get?
You need to login to post a reply.