Hi guys!
First post on this forums, I registered almost three weeks ago but had major problems to activate this account. When Im here I tried to post to the old topic I wanted to share my knowledge and experience but the topic was to old. To bad! ;D
Well I have some questions about Slick 2D and rotating objects, I´ll try to post some describing images but please let me know if I am not clear enough.
I have build a 2D engine (with some basics from Benny @ https://code.google.com/p/slick-rpg-engine/ ) by using slick and I am finally far enough to start working with game content and functions. Right now my project is to fell trees which I can do.
First picture: Equipped with a axe redo to fell the tree!
http://s21.postimg.org/o61c3ethj/Slick_game_1.png
Second picture: Debug mode, please note the big yellow rectangle for the tree which is the body (its actually a polygon) with x and y cord in the top left cornet (cyan circle). The rotation centre is the yellow small circle at the base.
http://s15.postimg.org/ern6i566z/Slick_game_2.png
Now when the tree is felled, it updates the rotation until its finished. I also would like to update the body so I can use this for collisiondetection and debug purpose. But, rotating the body which is a polygon causes some wierd problems. Please see the following short swf which describes the problem:
Swf-file of rotation “problem”:
http://www.swfcabin.com/open/1409311658
Every time I rotate the tree entity I also transform the body:
public void setRotation(float rotation) {
this.rotation = rotation;
setBody((Polygon) getBody().transform(Transform.createRotateTransform((float)Math.toRadians(rotation), getX() + getCenterOfRotation().getX(), getY() + getCenterOfRotation().getY())));
How come that during the update of the rotation the image object is rotated correctly but the body seems to be rotated double? Also in the end, the body ends up in the correct place.
Please note the cyan little circle that represents the x and y position of the tree, its still up there and I would like to learn how to move it to a new correct position so I can use this in the next step.
Any ideas?
It may not be a critical problem but the next step is to drag the tree around after the player and I have problems to position the tree correctly. I believe I don’t completely understands how rotation and position (x and y) is connected.
Once per update for the entity i call updateBody():
@Override
public void update(int delta) {
updateBody();
}
public void updateBody() {
body = new Polygon(new float[]{getX(), getY(),getX()+width, getY(), getX()+width, getY() + height, getX(), getY()+height});
body.setLocation(getX(), getY());
setRotation(getRotation());
}
To make sure that the position of the body is correct and that rotation is set accordingly.
During render i do this:
@Override
public void render(Graphics g) {
/** some other stuff */
image.setCenterOfRotation(getCenterOfRotation().getX(), getCenterOfRotation().getY());
image.setRotation(rotation);
image.draw(x, y, scale, c);
//if debug
g.draw(getBody());
Could the call from updateBody() cause the “double” rotation during the time the tree is felled?
Thank you for some input!