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

2016/9/5

Beam Light Problems

1
2
3
Laurence Laurence

2016/9/6

#
That does the trick perfectly.
Laurence Laurence

2016/9/6

#
Is there a way to keep an actor facing one direction with rotations? For example - When the A key is pressed and the character is facing the opposite direction of the key's direction, they're rotated by 180 but if A is pressed again, it won't rotate but move.
danpost danpost

2016/9/6

#
Laurence wrote...
Is there a way to keep an actor facing one direction with rotations? For example - When the A key is pressed and the character is facing the opposite direction of the key's direction, they're rotated by 180 but if A is pressed again, it won't rotate but move.
You mean:
String key = Greenfoot.getKey();
if (key != null)
{
    if ("a".equals(key))
    {
        if (getRotation() == 180) move(1); else setRotation(180);
    }

    // other keys coded here
}
Laurence Laurence

2016/9/6

#
What's the simplest way to implement detection? For example, if actor one touches actor two (or is right infront or behind it) an event happens.
danpost danpost

2016/9/6

#
Laurence wrote...
What's the simplest way to implement detection? For example, if actor one touches actor two (or is right infront or behind it) an event happens.
It really depends on many different factor as to what might be best. However, if you are trying to detect intersection with a Beam object -- don't. The Beam object covers the entire world; so, any actor within the world will always intersect it. Sometimes it is best to detect intersection immediately after moving; sometimes it is better to just use the coordinates (for left and right side detection) where the difference and which is greater can be used. There are other ways as well; but those are the main two.
Laurence Laurence

2016/9/6

#
Nah, I'm trying to make a character go up to a door then a piece of text commenting on it.
Super_Hippo Super_Hippo

2016/9/7

#
You mean like this? Usually you can check out the Greenfoot API and find a method which you can use.
is (isTouching(Door.class))
{
    //do something
}
You need to login to post a reply.
1
2
3