graphics

F

fozzy

I want to move a small painted figure (fast)over a background image.
The small figure is also rotating, I was thinking on just painting it on
the graphics. But, when it moves, how can I erase the previous drawn
figure in a smart way? Are there better ways to move a drawing over a
figure?
I checked tutorials on graphics2D but they just move over a white
background, so one can easily clear the rectangle.

pls advise, thanks

len
 
V

VK

I'm not too familiar with the jBlahBlah stuff from Swing, it may have a
better solution. In the old-fashion way I would make
Class myMovingObject extends Canvas {}
Canvas has its own Graphics object corresponding to the canvas size, so you
could place a picture on the canvas and manipulate it as a layer above your
background picture.
 
P

Pierre Pintaric

I want to move a small painted figure (fast)over a background image.
The small figure is also rotating, I was thinking on just painting it on
the graphics. But, when it moves, how can I erase the previous drawn
figure in a smart way? Are there better ways to move a drawing over a
figure?
I checked tutorials on graphics2D but they just move over a white
background, so one can easily clear the rectangle.

pls advise, thanks

len

The smartest way is to redraw the background image only over the
previous position of the figure.
The size of the area depends of the rotation of your figure, make a
rotation of 45°, and canculate the bounding box of the new figure,
then use this size to redraw the background.

Good Luck


Pierre Pintaric
The Genuts Team.
http://www.genuts.com/
 
L

Liu, Chunyen

The most efficient way of doing this is to pre-create
rotated images of the original object. For example,
you can create a new image every 30 degrees. Then
you will have 12 images. Simply pick one of the
rotated images closest t the current angle.
That way, you don't need to dynamically calculate the
new image and therefore the animation will be very fast.
 
T

Thomas G. Marshall

Pierre Pintaric <[email protected]> horrified us with:

....[twack!]...
The size of the area depends of the rotation of your figure, make a
rotation of 45°, and canculate the bounding box of the new figure,
then use this size to redraw the background.


/Whoa!/ No, that only works for squares, not arbitrary rectangles. Imagine
a long skinny rectangle at 45°. as it continues to rotate, it'd easily
exceed the bounding box.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top