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

2014/4/9

When I resize an object it acts the same

qwertyuiop qwertyuiop

2014/4/9

#
I want to resize my object when it collides with something and it works but now the object only looks smaller and doesn't act smaller. It should be half the size but it still acts the same size as before so it collides with other objects before they actually touch. This is what I used for it:
1
2
3
GreenfootImage image = getImage();   
image.scale(16, 16); 
setImage(image);
danpost danpost

2014/4/9

#
One or both of the colliding actors have an image whose size is larger than what you visually see. There could be a surrounding area of transparency or a color that matches the background behind the image. Most probably it is transparency that is the issue. If you do not have an image editor that supports transparencies, download my Image Transparency Adder/Trimmer scenario and just load and save your images with it. It will automatically remove any excess transparency when an image is loaded, so loading and saving is all that is necessary. You can create a jar application with it to run whenever you need it, instead of opening it up in greenfoot. You could click the 'Change background' button a few times to make sure that the area around the visual image is transparent or not. If not, click the outer area and click the 'Make transparent' button, then save it.
qwertyuiop qwertyuiop

2014/4/9

#
I don't understand how there could be any transparency around the images because I have saved 3 separate images where one is 16x16, one is 32x32 and one is 48x48 with nothing around the edges at all. Even though the image of the actor changes to the correct one when the 16x16 image is displayed it acts the same size as the original 32x32 image and same with when it changes to 48x48. Now I am just using setImage(userShrunk) etc.
danpost danpost

2014/4/9

#
What about the image of the object it collides with?
qwertyuiop qwertyuiop

2014/4/9

#
That stays the same size and so I don't know what could cause it.
danpost danpost

2014/4/9

#
qwertyuiop wrote...
That stays the same size and so I don't know what could cause it.
That may be, but it could still have excess transparency around it which is involved in the collision.
qwertyuiop qwertyuiop

2014/4/9

#
Let me check that.
qwertyuiop qwertyuiop

2014/4/9

#
Nope they definitely don't have any excess transparency or background colour around them.
qwertyuiop qwertyuiop

2014/4/9

#
I think I fixed it just by swapping out the order of 2 methods.
qwertyuiop qwertyuiop

2014/4/9

#
I think I fixed it just by swapping out the order of 2 methods. So now it checks and sets the image before checking collision.
You need to login to post a reply.