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

2012/11/14

Problems with scale Images

Gevater_Tod4711 Gevater_Tod4711

2012/11/14

#
Hi all, I got a problem with the scale method in greenfootImage. I am programming a kind of shooter game where you can shoot some enemys which are running arround and trying to kill you. My problem is that the enemys' images are very small at the beginning and they should be much bigger when they are standing in front of me. To change the size of the images I use scale and so I have a problem: The game should be a shooter so I want to shoot the enemys. But if I use scale to change the size of the images only the size of the images is changed and not the size of the objects. So if I try to shoot at the enemys' head I always shoot at some walls and don't hit the enemy. I think I could probably use some coordinates to find out if I hit the enemy object but is there no easyer way?
erdelf erdelf

2012/11/14

#
the method
getIntersectingObject(Class.class);
should help
Gevater_Tod4711 Gevater_Tod4711

2012/11/14

#
This method only can find objects but my problem is that the images are biger than the objects. Also if I want to change the position of this actor using the mouse I have to find the object because it's not as big as the image.
erdelf erdelf

2012/11/14

#
the object is the same size as the image, if I got this right
Gevater_Tod4711 Gevater_Tod4711

2012/11/14

#
no not in my case. normaly your right but if I scale the image it isn't the same size
danpost danpost

2012/11/14

#
Scaling an image changes the dimensions of the GreenfootImage object which is what is used to determine intersections. Gevater_Tod4711, are you saying that you want your intersecting 'hit-zone' to be the same size area, no matter the scale of the image?
Gevater_Tod4711 Gevater_Tod4711

2012/11/14

#
Yes that's what I need. But if the image object is used in the intersecting method then I don't understand what is going wrong in my case.
davmac davmac

2012/11/14

#
I think you're talking about this bug: http://bugs.bluej.org/greenfoot/ticket/360 One workaround is, after you scale the image, set the image to another image (anything will do) and then back.
danpost danpost

2012/11/14

#
Maybe some code might help, here. Include class names, intersection code, scaling code, anything related. Plus, a very specific run-down of how you want it to work with examples. EDIT: I was not aware of the bug in bluej that davmac just posted.
Gevater_Tod4711 Gevater_Tod4711

2012/11/14

#
Ok thank you. I'll try that.
danpost danpost

2012/11/14

#
Try
GreenfootImage image = new GreenfootImage( // name of image file // );
image.scale( // new dimensions //);
setImage(image);
I always try to code 'scaling' in this manner, as re-scaling also has its quirks (stretching parts or removing strips of the image).
Gevater_Tod4711 Gevater_Tod4711

2012/11/15

#
I have fixed that bug. Thank you very much for the quick answers.
You need to login to post a reply.