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

2015/4/19

Collision

xWanna xWanna

2015/4/19

#
Hey, I created a normal collision with getOneObjectAtOffset() and isTouching() but I need a more accurate one, because I put a little Animation on my character and so the box around him would varie if I cut it and it would be too much editing work to compensate it. My images are have transparent (PNG format). Do you guys know a method to do so?
if (Greenfoot.isKeyDown("right") && getOneObjectAtOffset(36, 0, Wände.class)==null && getOneObjectAtOffset(36, 0, Tor.class)==null){
            setLocation(x + 4, y);
            setImage("Schlagen/Rechts/Rechts.png");
}

and

if(isTouching(Spieler.class)) {    
            Leben.Leben = Leben.Leben + Heilung;
            getWorld().removeObject(this);
        }

Thanks for your help. xWanna
Super_Hippo Super_Hippo

2015/4/19

#
There is a scenario with pixel perfect collision checking: http://www.greenfoot.org/scenarios/9908 Be sure that the images are small or this will produce lag.
xWanna xWanna

2015/4/19

#
My images are quite big and with a lot if pixels.
Super_Hippo Super_Hippo

2015/4/19

#
You can try to use it. If it lags too much, then I don't know an easy way to do it. I also failed with it in my SPIKXX game. It isn't playable because of the lag. Hopefully it will be better for you.
xWanna xWanna

2015/4/19

#
Ok, thanks. I'll try it later. Are there any others ideas?
danpost danpost

2015/4/19

#
Other ideas might be: (1) scale down the entire scenario (size of background and size of images) to reduce lag; (2) remove any and all excess transparencies around the images of your actors (rows and/or columns of pixels along the edges of the actor images that are totally transparent; that is, every pixel in that row or column is transparent). If you need a way to remove such rows or columns of pixels, you can download my Image Transparency Adder/Trimmer scenario and use it to easily remove excess transparency. You could also use an image editor that does not support transparency to scale down all the images and then use my scenario to re-introduce the needed transparency.
You need to login to post a reply.