Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scale a shape with center as orgin

 
Kalle Zander
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I want the shape to pulse in size on its coordinates x and y, but this is also "moving" the shape diagonally back and to when scaling. How do I avoid the moving? A bit bad explained but I hope you understand what I mean.

Is AffineTransform useful to use here in some way?

//Kalle
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want the shape to pulse in size on its coordinates x and y

Then you need to translate the origin back after scaling.
 
Kalle Zander
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:
I want the shape to pulse in size on its coordinates x and y

Then you need to translate the origin back after scaling.


Thank you, that did it!
 
Campbell Ritchie
Sheriff
Posts: 48921
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you use a copy of the Graphics object, obtained with the (??) Graphics#create() method, to apply those transformations to.
 
Kalle Zander
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I suggest you use a copy of the Graphics object, obtained with the (??) Graphics#create() method, to apply those transformations to.


Yes I use a copy of the Graphics2D object as argument in that draw method, otherwise would other sprites rotate, scale etc the same way as that sprite which is not wanted.
 
Campbell Ritchie
Sheriff
Posts: 48921
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sprites drawn after the rotation would also be rotated. If you try to reverse the transform, tiny rounding errors will be introduced, and there will be slight distortions of the display. That is seen worst after shearing. So it is probably better to copy the Graphics object.
 
Kalle Zander
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Sprites drawn after the rotation would also be rotated. If you try to reverse the transform, tiny rounding errors will be introduced, and there will be slight distortions of the display. That is seen worst after shearing. So it is probably better to copy the Graphics object.


What do you mean by copying in this case then, not like I meant?
 
Campbell Ritchie
Sheriff
Posts: 48921
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kalle Zander wrote: . . . What do you mean by copying in this case then, not like I meant?
I obviously wasn't clear. I was agreeing with you, and explaining potential problems if you don't use a copy.
 
Kalle Zander
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Kalle Zander wrote: . . . What do you mean by copying in this case then, not like I meant?
I obviously wasn't clear. I was agreeing with you, and explaining potential problems if you don't use a copy.


Ah, ok sorry. I thought you wasn't agreeing and referred to something else. Nevermind.
 
Campbell Ritchie
Sheriff
Posts: 48921
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic