Make character face direction
I have one character which can face several directions: t, b, l, r, tl, tr, bl, br
The type of camera is top-down 2d
T stands for Top, which is when he is looking to the top of the screen
B = Bot开发者_JAVA百科tom L = Left R = RightThe character can look to other directions, like the Top-Left of the screen, which is tl
How do I calculate which direction he should look to if I only have one variable, rotation
?
Assuming your rotation property is from -180 to 180 (this is the way DisplayObject.rotation behaves)
// this gives us an index of 0-7 for rotation.
var direction:int = (character.rotation + 180) / 45;
// should you need a string representation, use an array like this:
var direction_labels:Array = ['b', 'bl', 'l', 'tl', 't', 'tr', 'r', 'br'];
trace(direction_labels[direction]);
精彩评论