RotatingTraveler

RotatingTraveler

A RotatingTraveler is a WDTraveler that has a animation that can rotate.


Constructor

new RotatingTraveler(wd, source, canvas, fromRect, x, y, width, height, rotationImage, rotationFromRect)

Parameters:
Name Type Description
wd WayDeterminer

A WayDeterminer instance for collision stuffs

source Image

HTML Image or Canvas Element, the sprite sheet to draw from

canvas CanvasObject

CanvasObject to draw to

fromRect Rectangle

fromRect used as WDTraveler/BlittedTraveler

x Number

x position

y Number

y position

width Number

width

height Number

height

rotationImage CanvasObject

A CanvasObject that is 3x larger than the rotation image. For example if the rotation image is 32x32 this CanvasObject needs to be 96x96. This CanvasObject will get rotated offscreen and during blit it is drawn from on top of anything else. For example, if you have a normal animation defined (see BlittedTraveler) it would get drawn first into canvas, then the rotationImage is used to draw from next into canvas. setRotation and rotateWithMoverPoint rotate rotationImage. Your image needs to be facing right.

rotationFromRect Rectangle

A Rectangle defining where in the source to get the 3x area that has the 1x rotation image in the middle. For example, if your image is 32x32 it needs to be in the middle of 96x96 space, and this Rectangle would define that 96x96 area in the source. Your image needs to be facing right, see the top down rotating gun shooter example.

Members

constructor

nr

Rotation, use getRotation

rFromRect :Rectangle

The rotation from Rectangle, defined during construction. To change what the rotation image is on the fly, simply change this rectangle.

Type:

rImageHolder :CanvasObject

The CanvasObject that holds the image to rotate.

Type:

Methods

(static) setRotation(toThis)

Rotates the rImageHolder, when blit is called the result is seen.

Parameters:
Name Type Description
toThis Number

A number from 0 to 180 or -1 to -180

alwaysDisplayRotationOnly()

When called any animation would not show during blit, just the rotation. To bring back animations call this method again.

animateRotationOnly()

Animate the rotation only, to use, call before calling blit.

To maintain just showing the rotation you would have to keep calling this before calling blit. When just this method is used, subsequent blit calls would go back to animating both the defined animations and the rotation. To keep it only animating the roation use the alwaysDisplayRotationOnly method.

blit(r, p, rop)

If animateRotationOnly has not been called, this method will display any animationSpecs defined animations first, and then it will draw the rotation image on top.

If animateRotationOnly has been called, then only the roation image is drawn.

Parameters:
Name Type Description
r Object
p Object
rop Object

getRotation() → {Number}

Returns the current rotation

Returns:
Type
Number

rotateWithMoverPoint(mp, addedY, addedX)

Rotate with a MoverPoint.

Parameters:
Name Type Description
mp MoverPoint

MoverPoint to rotate with.

addedY Number

optional added y.

addedX Number

optional added x.