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

2018/11/9

Actor looking left/ right

karlmell karlmell

2018/11/9

#
Hey I need a code where an actor goes to a random place on the field. When the actor moves right the actor has to look right and when moves left has to look left. oh and this has to be done with a constructor. Without setRotation() The problem is I have no idea how to put that together... Can someone help me? Thanks in advance!
danpost danpost

2018/11/9

#
karlmell wrote...
I need a code where an actor goes to a random place on the field. When the actor moves right the actor has to look right and when moves left has to look left. oh and this has to be done with a constructor. Without setRotation()
A constructor is for initialization of an object, for when the object is being created. An actor cannot yet be in any world during its execution. There is no apparent directional changes at that time. Using setRotation in a constructor will only internally set the actor's rotation for when it is finally placed into the world. It is only by way of an act method that some visual change can be made to an actor. Now, the constructor can be used in the setting up of what fields you might need to implement the changes between looking left and right; but the changes themselves would be done at a later time after the constructor was done executing. What do you anticipate is needed to make the actor change from looking one way to another?
You need to login to post a reply.