Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Xatruch

Hi community, i'm new to the forums and recently bought the license. I was just playing with the engine and can't figure out how to rotate an entity if is possible.

Like for example I got a triangle looking to the north and want to rotate it when the user press the right or left arrow I don't know maybe 20 degrees?

regards

1 decade ago by Graphikos

Rotation is defined by the entity's animation angle... specified in radians.

http://impactjs.com/documentation/class-reference/animation#angle

1 decade ago by Jerczu

It's better to just draw your entity at different angles as the rotation looks just awful

1 decade ago by quidmonkey

But rotating is drawing your entity at different angles!

Do this in your player.update():

if( ig.input.state('left') ){
    this.currentAnim.angle -= Math.PI/9 * ig.system.tick;
}
else if( ig.input.state('right') ){
    this.currentAnim.angle += Math.PI/9 * ig.system.tick;
}

1 decade ago by Arantor

Quote from quidmonkey
But rotating is drawing your entity at different angles!


Yes it is, but there's a difference between having an artist do the rotation vs doing it automatically by a drawing system; the artist can usually make it look better.

1 decade ago by littlefoot

I've actually been looking for a way to have an entity spin as it's falling down. So would I be better of just drawing each state into a spritesheet and using that or somehow implementing this through code?

1 decade ago by Arantor

It really depends on the shape involved as to whether it'd look better or not being done in a spritesheet. Generally, complex shapes - especially in pixel art contexts - are going to look better being done properly in a spritesheet. That said, if it's a fast spin and only on the screen for a short time, it might be an acceptable trade-off.

The only way to be sure is to try it.

Doing it in code is not that complex. Presumably you have some way of identifying the fact that the entity is falling, and thus should be spinning. I can think of a few ways of doing it but the cleanest is likely to retain a counter that's updated during the update() function, which tracks rotation in degrees, and when it gets to > 360, take 360 off of it. Then in the entity draw function, do the conversion from degrees to radians by multiplying the number of degrees by 180/Math.PI and pass that as a parameter.

1 decade ago by Xatruch

Thanks everybody for your answers (and sorry to reply late), I've tried quidmonkey's code on the paddle-player entity and I get the error "Uncaught TypeError: Cannot read property 'angle' of null" on chrome's console although i'm requiring the 'impact.animation'. Anybody knows what could be happening?

And if you ask, yes i'm JS & impact newb xD

regards!

1 decade ago by Arantor

You need to update the animation's angle, not the entity's angle itself.

Without seeing the code of your entity, can't really tell you any more than that, I'm afraid.

1 decade ago by Hareesun

I still really wish there was a way to rotate an entity and it’s bounding box, but alas.

One way around this is to use Box2D, but I’ve not spent much time using that lately.

1 decade ago by Xatruch

Well thanks it worked well with quidmonkey's script.
Page 1 of 1
« first « previous next › last »