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

2016/8/4

Making something move randomly across the x axis.

spider65 spider65

2016/8/4

#
How would i make an object move across the x axis? The object should be moving across randomly. Please explain it to me in basic terms.
Game/maniac Game/maniac

2016/8/4

#
What sort of effect are you trying to create?
danpost danpost

2016/8/4

#
spider65 wrote...
How would i make an object move across the x axis? The object should be moving across randomly. Please explain it to me in basic terms.
I will presume that 'randomly' means spawning on the left or the right and moving across the screen in opposite directions. To accomplish this with multiple objects of the same class, you will need an instance field for the direction of the objects. The value set for this field is directly related to where it is spawned along the x axis in the world and it can be set in one of several ways in your code. You will need to post the class code for this type of object so we know how you are trying to go about this.
spider65 spider65

2016/8/5

#
By randomly, I mean right and left. What do you mean by the class code?
danpost danpost

2016/8/5

#
spider65 wrote...
By randomly, I mean right and left. What do you mean by the class code?
Well, I presume you created a subclass of the Actor class to create the Actor objects that are to move across the screen. Open the editor to that class and copy/paste its contents here. There is a link below the reply box to explain how to post code (which is what you will be doing) here.
spider65 spider65

2016/8/6

#
Well actually, I dont have any code for that object yet
erdelf erdelf

2016/8/6

#
spider65 wrote...
How would i make an object move across the x axis? The object should be moving across randomly. Please explain it to me in basic terms.
I guess you don't want finished code. So basically look at this and this. Combine them and it should give you what you want, if I understood you correctly.
You need to login to post a reply.