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

2012/5/6

Need a little help with java.awt.Graphics

1
2
danpost danpost

2012/5/13

#
Are you using 'getWorld().setBackground(canvas)'? or, do you still have a canvas object that is in the world?
darkmist255 darkmist255

2012/5/13

#
Well I think that will have to work for now, redrawing every fifth cycle has lowered the CPU usage to about 90%, so it's running normal speed albeit fairly high CPU at this point. @danpost I'm operating on the world image itself, but I can change it to do setBackground(canvas), that might work. edit: Whohohoooa! Nevermind, setting the background to canvas makes it so that the images don't clear their old images on the screen before they update in the new position, then you get that old laggy window effect.
darkmist255 darkmist255

2012/5/13

#
Alright I've got it working with no adverse effects on the CPU now, I just reduced the canvas size to 1 pixel wide since its only a single line, then it's not refreshing the entire world dimensions :D. I no longer need to have it redraw every fifth cycle. Thanks for all the help guys!
danpost danpost

2012/5/13

#
darkmist255 wrote...
that old laggy window effect.
LOL (nice description!)
Builderboy2005 Builderboy2005

2012/5/13

#
I'm really confused as to what you did or how you fixed it, but glad it is working now!
darkmist255 darkmist255

2012/5/13

#
Basically the core part of what I did was I changed
canvas = new GreenfootImage(getWorld().getWidth(), getWorld().getHeight());  
to
canvas = new GreenfootImage(1, getWorld().getHeight());  
That way it doesn't have a big resolution to calculate. And my thought for the future is I'll make a class called canvas that will do nothing except for allow other classes to use Graphics draw() methods on it, that way I don't have many canvases.
Builderboy2005 Builderboy2005

2012/5/13

#
What is it you are using canvas for anyway? What are you trying to accomplish?
darkmist255 darkmist255

2012/5/13

#
I use it for canvas.drawLine(), it's the image I'm drawing on to.
pyrokey3 pyrokey3

2012/5/24

#
import greenfoot.*;
import java.awt.Color;

getImage().clear();
getImage().setColor(Color.WHITE);
getImage().drawLine(0,0, 0,15);
getImage().drawLine(15,0, 15,15);
getImage().drawLine(0,0, 15,0);
getImage().drawLine(15,15, 0,15);
this will draw a white square (15x15)... You can figure out the rest
danpost danpost

2012/5/24

#
I think this is what he is using to draw a line:
GreenfootImage canvas = new GreenfootImage(1, getWorld().getHeight()); 
canvas.setColor(Color.WHITE);
canvas.fill();
setImage(canvas);
danpost danpost

2012/5/24

#
@pyrokey3, in your code, lines 6 through 9 can be replaced with this one line
getImage().drawRect(0, 0, 15, 15);
You need to login to post a reply.
1
2