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

2012/5/18

Light in a Dark Room

1
2
3
danpost danpost

2012/5/18

#
I made the method public so you could call it from the world (and yes, as many times as you want).
RM6442 RM6442

2012/5/18

#
Nevermind, unlike BuilderBoy's code, I can actually wrap my head around danpost's, no offense. It wouldn't be very fair if I couldn't figure it out myself.
Builderboy2005 Builderboy2005

2012/5/18

#
Yes they will danpost, I use them myself for my Nightmare scenario and they work just fine. The issue I assume is that the correct image is not being manipulated. Keep in mind my original code was written without any knowledge of your current routines or implementation, and was just a demonstration. Mirroring Danposts post, a similar method would be like: public void createPortal(int x, int y, int r) // x and y are the center and r is the radius { BufferedImage myBuffer = getImage().getAwtImage(); Graphics2D myGraphics = myBuffer.createGraphics(); AlphaComposite compClear = AlphaComposite.Clear; myGraphics.setComposite(compClear); myGraphics.fillOval(x-r,y-r,r*2,r*2); } EDIT: Ah ok, well my method will always be here if you run into any sort of speed issues!
danpost danpost

2012/5/18

#
I think the point was that all the imported classes are not neccessary to accomplish what was wanted. The inexperienced programmer gets lost in code as you are providing. Hence, RM6442's response of "I can actually wrap my head around danpost's. I believe what he was saying, is that he could understand the code (instead of just blindly using it).
Builderboy2005 Builderboy2005

2012/5/18

#
Yes I understand that, hence my edit (which you may or may not have caught due to page refresh D:). But yeah, I understand that your routine is easier to understand, so I am merely providing my routine as a backup at this point if he ever wants to come back and check it out.
RM6442 RM6442

2012/5/18

#
Both work, but danpost's right. I want to be able to understand the code I'm putting into this program. I try BuilderBoy's code when I understand what each of the things I had to import mean.
RM6442 RM6442

2012/5/18

#
Both codes work as erasers when I attach them to moving objects. When I had the image recreate itself before at the beginning of the method, I lost the ability to use it on more than one object.
Builderboy2005 Builderboy2005

2012/5/18

#
Ah yeah that makes sense. That was probably just a result of adapting my general code to your program without understanding what it meant. So glad you have a routine that works for you, and that you can understand now ^^
RM6442 RM6442

2012/5/18

#
I wanted to attach this code to more that one moving objects. Any ideas?
Builderboy2005 Builderboy2005

2012/5/18

#
Danposts code? What is going wrong with it?
RM6442 RM6442

2012/5/18

#
This is what happens when the object that calls it moves here.
Builderboy2005 Builderboy2005

2012/5/18

#
Try re-filling the image with black each frame before you cut the holes in the image. What is happening right now is that each time the routine is called, it cuts another hole without filling in the previous one.
RM6442 RM6442

2012/5/18

#
Ah, refill the hole. I was thinking of redrawing the image.
RM6442 RM6442

2012/5/18

#
Wait, to refill the hole, it would require a way of knowing where it was previously. If I ignore that by simply using a larger oval to refill the hole, there may be problems when two objects meet.
RM6442 RM6442

2012/5/18

#
Unless I create a method that fills the hole and have the object call it before it moves! Nevermind, figured it out myself.
There are more replies on the next page.
1
2
3