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

2013/1/27

Problem with an image

moobe moobe

2013/1/27

#
Hi, I have a class, which can fly around and is animated. Therefore every image has to have the same image size. Now my problem: When my actor of that class intersects an other actor, it shall remove both. So using "getOneIntersectingObject" does not work, because the images of the actor are a little bit larger than the real actor. I could use "getOneObjectAtOffset" four times (in all 4 corners), but would that be the best solution? Hopefully you've understood the problem. If not, you can ask me again or try my game. You'll see that the bats kill the snowman, although they haven't touched the snowman.
danpost danpost

2013/1/27

#
Althought the problem is somewhat a result of the image of the snowman, it is the images of the bat with the excess width and height that is the main problem. You can cut down the wasted space around the actual images of the bat; however, as a consequence, you will then have to constantly adjust the y-location of the object for each change in its image.
moobe moobe

2013/1/27

#
Yeah, that's the only way to solve it, but it won't be easy... I think I'll try it, but I'm not sure wether it will work with my onGround method. My bat shall change the direction, when it isn't flying over the ground anymore, so maybe I'll have some problems when I change the images..
danpost danpost

2013/1/27

#
It is certainly not the only way to solve it and certainly not a complete solution; however, it would allow the bat to approach much closer to the snowman before intersection is detected. There are other ways to work out a solution, all of which unfortunately have their own set of issues to work out. Some are the color detection and distance computational methods which can be used after image intersection has been detected; and there is the method of breaking the image(s) into smaller parts so detection occurs on the individual parts instead of the whole image..
moobe moobe

2013/1/27

#
OK, but I don't know the other ways, so I have to do it by making the images smaller. I have cut all the images now, but how do I know the amount of pixels I have to change after I've set a new image? I am a little bit confused right now, because it has to be possible to calculate the new position of my bat. What do I have to do for that? UPDATE: I think it looks more realistic now. You can check it out ;)
danpost danpost

2013/1/27

#
For every two lines of pixels removed from one edge of the image, move the image one pixel away from that edge.
moobe moobe

2013/1/27

#
Yeah, just wanted to do that, but then I noticed that it looks more realistic right now! Anyway, thank you so much for your help!
You need to login to post a reply.