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

2012/6/23

Wondering how to resize object/actor

1
2
ThinkingPainter ThinkingPainter

2012/6/24

#
i set : public void act() { GreenfootImage image = getImage(); image.scale(image.getWidth() - 0, image.getHeight() - 0); setImage(image); } // rest of class to 0's as you can see and no more error but when you add a number like - 1 its give me the error listed above... also Actor "Blip" will not move with this code public void moveAndTurn() { move(4); if (Greenfoot.isKeyDown("a")) { turn (-3); } if (Greenfoot.isKeyDown("d")) { turn(3); } } i think that the code you gave me for resizing my actor is causing "Blip" not to move, but my second actor "RedBlip" moves with this code above but he doesnt have code you gave me to resize my actor coded in it's file. Thanks for all your help. Appreciate you helping me to understand the language a little better :P
SPower SPower

2012/6/24

#
I'm sorry, I should have said:
1
getImage().scale(..., ...);
I just forgot the () :)
danpost danpost

2012/6/24

#
The code I provided does not go in the 'act' method (anything you put in the 'act' method will be repeatedly executed). The constructor is only called once; when the object is created. My code will go in the constructor. Again you should have:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public Blip()
{
    GreenfootImage image = getImage();
    image.scale(image.getWidth() - 10, image.getHeight() - 10);
    setImage(image);
}
 
public void act()
{
    moveAndTurn();
}
 
public void moveAndTurn()
{
    // etc.
ThinkingPainter ThinkingPainter

2012/6/24

#
Thanks, Dan it worked!
danpost danpost

2012/6/24

#
That is what I like to hear!
Super_Hippo Super_Hippo

2013/1/30

#
(how do i delete a post?)
csrgamer csrgamer

2014/10/17

#
Edit: Never mind. I tried to answer your question but didn't realize it had two pages and was already answered! :p
marzofkae0274 marzofkae0274

2014/12/11

#
.
smcgee smcgee

2015/10/13

#
I was able to copy and paste the code provided and it worked perfectly. thank you! public ClassName() { GreenfootImage image = getImage(); image.scale(image.getWidth() - 10, image.getHeight() - 10); setImage(image); }
smcgee smcgee

2015/10/13

#
I opened the Class and pasted in the code and only had to make a single change: ClassName and it worked just fine.
danpost danpost

2015/10/13

#
@smcgee, just to bring out a point: the code given does not resize the image proportionally; use something like the following to resize the original image proportionally:
1
2
3
int percentage = 80;
GreenfootImage image = getImage();
image.scale(image.getWidth()*percentage/100, image.getHeight()*percentage/100);
Also, it is not required to reset the image to the actor. The rescaling is done directly on the image currently set to the actor (it is not a different image; but a modified one).
ironphoenix20 ironphoenix20

2015/12/14

#
hi
You need to login to post a reply.
1
2