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

2018/1/9

Rotations from a point

Echarch11 Echarch11

2018/1/9

#
I want my image to rotate but I don't want it to rotate from the center of the image. Instead I want it to rotate from one edge (since the image is a square). However I want the image to always rotate while I move my character so that he has to try and avoid the square that rotates 360 degrees. Any help is great thanks.
danpost danpost

2018/1/9

#
Draw its image at (0, 0) on an image twice its width and set that image to the actor.
Echarch11 Echarch11

2018/1/10

#
Ok. Do you have any example code because I am having trouble starting the code
Echarch11 Echarch11

2018/1/10

#
I'm confused when you say draw and image and what you mean by twice its width. Code would help
danpost danpost

2018/1/11

#
Echarch11 wrote...
I'm confused when you say draw and image and what you mean by twice its width. Code would help
Please see the GreenfootImage class API documentation.
Yehuda Yehuda

2018/1/11

#
I agree you should see the Documentation, but I have a feeling you have no idea where in the documentation to look. So I think danpost meant for you to do the following:
1
2
GreenfootImage objectImage = new GreenfootImage(100, 100);
objectImage.fillRect(0, 0, 50, 50);
The above code will create a GreenfootImage object that is 100x100 transparent pixels with a 50x50 pixel black square drawn onto it. Once you set this image to an Actor then rotate it, the black square will rotate around its bottom-right corner which is the center of the 100x100 transparent square.
danpost danpost

2018/1/11

#
Actually, I meant this:
1
2
3
4
GreenfootImage square = getImage();
GreenfootImage image = new GreenfootImage(2*square.getWidth(), square.getHeight());
image.drawImage(square, 0, 0);
setImage(image);
The documentation shows the constructor used to create an image of a specified size, plus the methods to get the width and height of an image and the method to draw an image onto another one. A cursory glance over the documentation would lead to most, if not all, of these. Like I said, my first post basically said it all, draw (line 3) the image (line 1) at (0, 0) (again, line 3) on an image twice its width (line 2) and set that image to the actor (line 4).
You need to login to post a reply.