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

2022/2/27

IsTouching issue

Claudiu Claudiu

2022/2/27

#
Hello. I have a problem with my code.. I want to check if an actor touches another actor and i used if (this.isTouching(brick2.class)) and it works, it returns true but too early.. i remove the object when they are touching each other but it says they touch each other too early, when it s at distance from it.
danpost danpost

2022/2/27

#
Claudiu wrote...
I want to check if an actor touches another actor and i used if (this.isTouching(brick2.class)) and it works, it returns true but too early.. i remove the object when they are touching each other but it says they touch each other too early, when it s at distance from it.
There is probably excess transparencies around the images of one or both of the interacting actors. Remove all rows and columns along any edge of the images involved that are completely transparent. Use an image editor to do this; or, download my Image Transparency Adder/Trimmer scenario and use it (just run, load and save image to automatically remove excess transparencies; an executable jar file is included in the download to use directly without greenfoot)
Claudiu Claudiu

2022/2/27

#
Yes, that was the problem, thank you. Now i have another problem if you would like to help me.. i want to compare my current actor coordinates with another actor's coordinates.. how do i do that? how do i access that actor in my current class?
danpost danpost

2022/2/27

#
Claudiu wrote...
i want to compare my current actor coordinates with another actor's coordinates.. how do i do that? how do i access that actor in my current class?
In ClassA:
Actor classB  = null;
for (Object obj : getWorld().getObjects(ClassB.class))
{
    classB = (Actor)obj;
    break;
}
if (classB != null)
{
    // compare here, for example:
    if (classB.getX() > this.getX())
    {
        // do stuff
    }
}
Claudiu Claudiu

2022/2/28

#
Thanks. Can you help me again please? I want to turn my actor(ball) with the right angle, like when it hits the wall or the brick to turn with the same angle but in the opposite direction.. but i have to know the angle between the actor and the wall it hits
You need to login to post a reply.