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

2013/6/8

Smooth move while cellsize superior

welleid welleid

2013/6/8

#
Hey, I have a world with cellsize of 80 in my super declaration. Objects shall move in this world, but if i set the usual move() method, or the setX() + x, The object's movement is from one cell to another without transition. I'd like my object to move from one cell to another as if his move was from a pixel to another. I tried to use the Smoothmove Class, but doesnt work. (Thought that a slower move would make it, but didnt). Any idea ?
Solringolt Solringolt

2013/6/8

#
Very interesting question If this is possible I could change my whole tricky code and simplify my code.
danpost danpost

2013/6/8

#
To be able to move one pixel at a time, you need to declare your world with pixel-sized cells (cellsize of 1) and multiply the width and height by 80, as well. You can still place everything into the world 80 pixels apart from each other by multiplying their placement x and y coordinates by 80 and adding 40 (to account for centering within the 'cell'. Once you do that, the Smoothmove Class will work correctly (if implemented appropriately).
Solringolt Solringolt

2013/6/8

#
I had some advantages from having a World with a bigger cell size like when my actor add an object on his location it was automatically placed on the right cell. With a one pixel world I don't know what kind of function to use to replace the object automatically
danpost danpost

2013/6/8

#
There should not be any change in the code for an actor to add an object on his location unless you are using offsets from the actors location (just multiply the offsets by the cellsize you were using, if that is the case).
welleid welleid

2013/6/8

#
Dat Philippe ^^ Anyway the point is that user should be able to place object using the mouse, but those object have specified places, using my big cells, and then should move. You could imagine a chess game where pieces move fluently and smoothly. Is There à way to do that ? Like two superposed worlds, with different cellsizes, or à special method ?
danpost danpost

2013/6/9

#
The following should 'snap' the object placed by the user into its proper location (using a imaginary cellsize of 80x80). the (n/80)*80 part gets the multiple of 80 for where it was placed; the +40 centers the object into that 80x80 imaginary cell.
1
2
3
4
5
6
if (/* placed by user */)
{
    int x = (getX()/80)*80+40;
    int y = (getY()/80)*80+40;
    setLocation(x, y);
}
You need to login to post a reply.