开发者

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 = Right

The 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]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜