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

2012/5/21

Changing Pivot point of Actor

BadatCoding BadatCoding

2012/5/21

#
Greetings, I am doing a trebuchet simulation and am wondering if I can change the pivot point of an actor. Or if someone could suggest another way so it doesn't rotate the whole arm. Thanks, BaC
danpost danpost

2012/5/21

#
The easiest way is to alter the image size (adding blank space past the pivot point). Make the pivot point the center of the image. Then rotating the image, or turning the actor, gives the proper visual.
BadatCoding BadatCoding

2012/5/21

#
i Tryed Dat Butt It Dusnt Werk cAn u recomen anyting else or Elbrate on What u Rote! Thankx, bAc
danpost danpost

2012/5/21

#
Then create a new, larger, image and use drawImage to draw the arm image onto the new image and set the image to this new image. Let us say the width of your arm image was 50 and the height was 180; and the pivot point is located on the image at (25, 150). Then, you would create a new GreenfootImage of height 300 (150 x 2), and a width of 50, and draw the arm image on it at (0, 0). Set the image of the arm to this new image. This may not be the exact code you want, but shows the general idea.
GreenfootImage img = getImage();
GreenfootImage newImg = new GreenfootImage(50, 300);
newImg.drawImage(img, 0, 0);
setImage(newImg);
BadatCoding BadatCoding

2012/5/21

#
Thanks dan I'll try it out, sorry for the last message , a couple of friends modified my message. BaC
You need to login to post a reply.