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

2020/9/17

Rotate a „GreenfootImage“

RcCookie RcCookie

2020/9/17

#
Is there a way to rotate an existing GreenfootImage? Essentially what I want to do is draw one GreenfootImage onto another one in a rotated way.
danpost danpost

2020/9/17

#
RcCookie wrote...
Is there a way to rotate an existing GreenfootImage? Essentially what I want to do is draw one GreenfootImage onto another one in a rotated way.
No problem:
GreenfootImage base = new GreenfootImage("imageName.png");
int w = base.getWidth(), h = base.getHeight();
int m = Math.max(w, h); // maximum dimension
GreenfootImage rotatable = new GreenfootImage(m*3/2, m*3/2); //  sqrt(2) plus times max dimension
rotatable.drawImage(base, (m*3/2-w)/2, (m*3/2-h)/2); // draw image on bigger frame
rotatable.rotate(2); // no loss of image due to what size the image is
base.drawImage(rotatable, (w-m*3/2)/2, (h-m*3/2)/2); // create effect
RcCookie RcCookie

2020/9/17

#
Oops.. must have missed that method. Thanks anyways!
You need to login to post a reply.