I have been attempting to write a simple program it should:
1. Have a container with a background of tiled images.
2. The container should have components that are images also.
3. The components in the container should not erase the background for their
entire rectangular region. Wherever the image is clear the background should
show through.
4. The components should be able to have their images modified and redrawn to
the screen. When doing so no trace of the old image shall remain and the
background shall still show through where the image is clear.

I have extended the Container class and called it TextureContainer. During
initialization I create a TexturePaint. I have overidden paint() to call
setPaint() and fillRect() on TextureContainer's graphics context

This part seems to work fine.

The points I'm having trouble with are 3 and 4. I allow the image to be
manipulated by rotating it when the arrow keys are pressed and by moving it
around in the container when the up arrow is pressed.

I've extended the Component class and called it ImageSprite. I attempt to use
double buffering. I have an init() routine I call after calling pack in a main
routine in a driver class. It follows:

  public void init()
   {

      offscreenImage = createImage( spriteSize.width, spriteSize.height );
      offscreenGraphics2D = (Graphics2D) offscreenImage.getGraphics();

      offscreenGraphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
         RenderingHints.VALUE_ANTIALIAS_ON);

      offscreenGraphics2D.fillRect( 0, 0, spriteSize.width, spriteSize.height
);
      offscreenGraphics2D.drawImage( spriteImage, 0, 0, this );

      listenToParentEvents();
   }


my paintComponent() method follows
   public void paintComponent( Graphics onscreenGraphics )
   {

      // update the image on the screen.
      onscreenGraphics.drawImage( offscreenImage, 0, 0, this );

      // try rotating the image.
      // create the affine transform
      AffineTransform imageXform = new AffineTransform();
      imageXform.rotate( angle, (double) (spriteSize.width /2) , (double)
(spriteSize.height/2) );
      offscreenGraphics2D.drawImage( spriteImage, imageXform, null );

   }

The main problem I have is that the whole rectangle that the image occupies is
erased on the container and the background shows through. It seems to me that
the source over rule should allow the image to get painted on the container and
the container should show through the image where the image is clear. I've
tried  forcing the component to do various things and so far this is the
closest solution I've found but it isn't the solution I'm going for. It seems
as if this should be an easy thing to do but I haven't found that to be true so
far. I have learned a good bit on the side though while trying to get this to
work. So what is the solution to this? Is it simple? Do I have to dig deeper
and work with the  raster data?

Thanks

__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to