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

2014/11/5

Non rectangular object borders in Greenfoot

classicjimmy classicjimmy

2014/11/5

#
So it's cool that you can use pictures with transparent backgrounds but the transparent background will still be considered part of the object. Any way to make the transparent background not part of the object so that the object has non rectangular borders?
Super_Hippo Super_Hippo

2014/11/5

#
I don't think that this is possible, a GreenfootImage will always be a rectangle.
danpost danpost

2014/11/5

#
You can program your own collision detection so that the transparent areas are ignored to give the behavior of your objects as not having rectangular shapes. However, that kind of collision detection usually hogs CPU time and produces lagging.
classicjimmy classicjimmy

2014/11/6

#
Has it been done before in some scenario you know of? I would like to see how badly it effects performance.
danpost danpost

2014/11/6

#
I do not know of any in particular that both use it and are up on the site. Most of the time, the programmer decides on some other way around it (whether it would be changing the images or maybe using an alternate collision detection method; or both). How odd is/are the shape(s) of the image(s) that you are using? if it is just excess (meaning complete rows or columns of totally transparent pixels along the border(s) of your images, they can be removed.
classicjimmy classicjimmy

2014/11/6

#
I already scaled them down as much as I could and it turns out that even in this state about 50% of their rectangular size is covered by the transparent background. It's actually a recurring problem whenever I want to start a new project cause I feel like having to use rectangular objects limits my options quite a lot. Say I want to make a road and have a car drive on that road. Then the road basically needs to be completely straight since any turns will potentially ruin its interaction with the car . Yes I could make the turns square-shaped but it wouldn't look natural.
danpost danpost

2014/11/6

#
There are still things you can do programmatically, to address the problem. For your car example, you may want to look at my Racetrack Demo scenario.
Super_Hippo Super_Hippo

2014/11/6

#
I tried using it in my SPIKXX game and it produces a lot of lag. As noted in the description there, I used Busch's Pixel-perfect collision detection. The source code is published, so you can try it out.
danpost danpost

2014/11/6

#
There is also the method of dividing your image into smaller rectangular units (multiple actors that act as one, but collision can be checked on each part). That way, you can still use conventional greenfoot collision detection instead of creating elaborate collision checking code. To be sure, rotated smaller units can be used for odd-angled extensions of the actual image.
classicjimmy classicjimmy

2014/11/7

#
Thanks I will check those out. Dividing the objects into parts is a great idea and definately something I will use for simple pictures. For more complex pictures its too much work I think..
You need to login to post a reply.