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

2014/4/25

how to addobject & move it

rohit.dudhbhate rohit.dudhbhate

2014/4/25

#
Hi Everybody, I m very new in greenfoot. I m learning to make games. I want addObject & move it after compile. Plz give the simple examples without using getRandomNumber().
CooliMC CooliMC

2014/4/25

#
Hey Rohit if you want to move them to Special coordiantes use SetLocation(x,y) . As a New One You Could read all the Basic commands Here:http://www.greenfoot.org/files/javadoc/greenfoot/Actor.html I Hope i Could help you if you have Special question Write them Here and i will Anwser them.
danpost danpost

2014/4/26

#
I was going to say the following, but I may be too simple: Create a world subclass (right click on the 'World' class icon and select 'New subclass...') and name it whatever (I will use 'Game' here). Then open the class editor for the new world subclass (right click on the 'Game' class icon and select 'Open editor'. Replace the current code with this:
1
2
3
4
5
6
7
8
public class Game extends greenfoot.World
{
    public Game()
    {
        super(600, 400, 1);
        addObject(new Actor(){ public void act() { move(1); } }, 50, 200);
    }
}
rohit.dudhbhate rohit.dudhbhate

2014/4/27

#
thanks you so much both of you. I have another question when i move the object when it reaches last width location i want disapper it again start moving the object.
danpost danpost

2014/4/27

#
rohit.dudhbhate wrote...
I have another question when i move the object when it reaches last width location i want disapper it again start moving the object.
Please explain in more detail. I think your English is making it difficult to understand what you are wanting. Provide step-by-step what you want to happen when the object reaches to right edge of the world.
rohit.dudhbhate rohit.dudhbhate

2014/4/28

#
Ok Sorry for that, How to move the object in loop when the object reaches to right edge of the world.
danpost danpost

2014/4/28

#
Actor method 'getX' returns the x-coordinate of the actor in the world. Actor method 'getY' returns the y-coordinate of the actor in the world. World method 'getWidth' returns the width of the world (one more than the highest x-coordinate in the world, which is at the right edge; the left edge x-coordinate is zero). Actor method 'getWorld' returns the world the actor is currently in. Actor method 'setLocation' sets an actor at the given coordinates in the world it is in. Those are the methods you will need. You just have to create an 'if' statement that checks to see if the actor is at the right edge of the world and, if so, set its location back on the left edge.
You need to login to post a reply.