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

2012/7/29

Changing an Image

erdelf erdelf

2012/7/29

#
I want to change an image I add to the world using the drawImage() method. I just forgot how, could anyone help me?
Upupzealot Upupzealot

2012/7/29

#
Why not try the method setBackground(GreenfootImage image) in the world class
danpost danpost

2012/7/29

#
getBackground.drawImage(new GreenfootImage(imageName), leftX, topY); @Upupzealot, I do not think erdelf wants to replace the image of the world; just add something to the existing background. @erdelf, Maybe I am a bit confused myself. Was this image you added to the world (that you want to change) drawn on the background already, or is it an Actor image, or what?
erdelf erdelf

2012/7/29

#
I have a GreenfootImage, add this to the world and then I want to change it. so it is just a GreenfootImage, and it is added to world.
danpost danpost

2012/7/29

#
You still are not being very clear as to what you are doing. I will call your GreenfootImage 'baseImage'. You draw this image on the world background. Then, just change 'baseImage' and re-draw the image on the world background at the same place. As long as you are not making the image smaller, this should work.
danpost danpost

2012/7/29

#
You may have to re-create the world background from scratch before adding the changed image to get the proper background image. But, of course, I know not HOW you create the background to begin with or WHAT kind of changes are being done to the image that you are adding to the background image. Information like that would make it alot easier to come up with a decent workable solution quickly.
erdelf erdelf

2012/7/29

#
the first would not work cause the pics works with transparency. the changes should be that there is an another image after the change. The background is build from an Image and the userpic.
danpost danpost

2012/7/29

#
Then, re-create the background with the userpic and draw the new image on that. You could instead, save the background image with the userpic before you initially draw the image on it, and use 'new GreenfootImage(savedImage)' to create a new base background image.
You need to login to post a reply.