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

2011/9/27

Actor.move problem?

brian brian

2011/9/27

#
I'm new to Greenfoot and will be introducing pupils in my school to it in the next few days and I have hit a problem that I was hoping someone could help me with. Basically if I create a world with the following constructor as far as I can figure I should get a world that consist of 100x100 cells each of which are 10x10 pixels.
    public GameParkWorld()
    {    
        // Create a new world
        super(100, 100, 10); 
    }
So far so good. However when I create an actor subclass which calls move(1) the actor actually moves 10 cells in the world not just one! Being curious I changed the cell size to 8x8 pixels and sure enough when the actor calls move(2) it moves 16 cells. As far as I can figure out it is moving a certain number of cells when it should be moving that number of pixels. I know I can get around this by using something like setLocation(getX()+2, getY()) and it's only going to be an issue if your cell size is not 1x1 but it doesn't seem right to me. Have I misunderstood something? I would appreciate any help you can provide.
Duta Duta

2011/9/27

#
Basically, what you say (it is moving a certain number of cells when it should be moving that many pixels) is... as far as I am aware - wrong. It seems to me it is moving that number of pixels. I might be misunderstanding what you're saying as my brain's ever-so-slightly dead at the moment. I'll think about it and post again when my brain is working most likely.
ImFerocious ImFerocious

2011/9/27

#
hmm that's weird...i thought that when you call the move method say once then it moves the actor a total of whatever number you put in multiplied by how big a cell is...so for example
public myWorld() {
    //Create a new world
    super(10,10,10); 
}
says you have a world that's 10 cells by 10 cells and each cell is 10 pixels so if you have an actor and call the method .move(1) then it should move the actor 10 pixels in the direction you specify so you moved 1 cell
brian brian

2011/9/27

#
That's what I assumed but as a simple test, assuming that the Actor is facing 0 degrees, move(1) and setLocation(getX()+1, getY()) should do the same thing... right? Anyway if, and only if, the cell size is anything greater than 1x1 they don't do the same thing ... at least not for me!
Duta Duta

2011/9/27

#
...No, as far as I am aware, setLocation(getX()+1, getY()) shouldn't do the same as move(1) when cell size > 1x1. I believe (correct me if I'm wrong, I'm fairly new to this) that getX()+1 will move it one pixel across, not one cell. Now that I've typed that I think I'm probably wrong. :L
brian brian

2011/9/27

#
Well on the actor API page it states the following for the setLocation method.
Assign a new location for this actor. This moves the actor to the specified location. The location is specified as the co-ordinates of a cell in the world.
To me this reads like the coordinates provided are that of cell and not a pixel. That being the case I still think the two bits of code should be equivalent.
Duta Duta

2011/9/27

#
Hmm good point. Yeah now I've stopped being retarded I think the same as you... No idea tbh :P God I'm so helpful.
davmac davmac

2011/9/28

#
brian, it looks like you've found a bug in Greenfoot here. I've added it to our bug database. Thanks!
kiarocks kiarocks

2011/9/28

#
here is what the API says
Actor API wrote...
public void move(int distance) Move this actor the specified distance in the direction it is currently facing. The direction can be set using the setRotation(int) method. Parameters: distance - The distance to move (in cell-size units); a negative value will move backwards See Also: setLocation(int, int)
kiarocks kiarocks

2011/9/28

#
i think that move has an advantage. it will move diagonal, while setLocation() will not.
Duta Duta

2011/9/28

#
Yeah I agree with kiarocks. :p
You need to login to post a reply.