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

2012/1/19

Drawing Problems

Mikeson Mikeson

2012/1/19

#
Why is it in greenfoot if i use the code; Public void drawRect() { GreenfootImage img = getImage(); img.clear(); img.drawRect(0,0,100,100); } i get a top and left line and nothing else. and the width and height is not 100px its more like 10 and the window size is 400,400,1. thou if i put in (0,0,5,5) i get a small rect I can can scale this to make it bigger but In another program (small basics) I put in the (0,0,100,100) I get a full rectange to the specified size.
danpost danpost

2012/1/19

#
First, try renaming the method to something like 'drawRectangle()'; it may be trying to call itself on 'img.drawRect(0, 0, 100, 100);'.
nccb nccb

2012/1/19

#
If I understand the original post correctly, you're trying to draw a 100*100 rectangle on a 10*10 image? That would cause it to draw the top and left lines seemingly in the right place (but extending off the image by 90 pixels), and you wouldn't see the bottom and right lines because they are 90 pixels off the sides of the image. You might want to do something like this:
GreenfootImage img = new GreenfootImage(200,200);
img.drawRect(0,0,100,100);
setImage(img);
davmac davmac

2012/1/19

#
danpost:
First, try renaming the method to something like 'drawRectangle()'; it may be trying to call itself on 'img.drawRect(0, 0, 100, 100);'.
This can't be the case. Firstly, in 'img.drawRect(0, 0, 100, 100)', the method is qualified with the 'img' reference which is of type GreenfootImage - therefore the method will be found in the GreenfootImage class (or a subclass, if img refers to a subclass instance). Secondly, in 'img.drawRect(0, 0, 100, 100)', there are four parameters, but the drawRect declared has none; therefore a different version of drawRect is being invoked.
danpost danpost

2012/1/19

#
Yeah, the parameter count was a big tell-tale. I should have seen it! (Thanks, davmac)
You need to login to post a reply.