/
8way.js.html
130 lines (97 loc) · 3.4 KB
/
8way.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: plugins/sprite/8way.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: plugins/sprite/8way.js</h1>
<section>
<article>
<pre class="prettyprint source"><code>/*global define*/
define(function() {
'use strict';
var sn;
function Face8Way() {
}
/** Called with the update options as the function context, one of which
* is this.sprite, which refers to the sprite being updated.
* @param {Number} now The time of the current frame
* @param {Bool} phaseOn If the update is controlled by a phaser,
* this will be true to hint that we do a full batch of work, or false
* to hint that we try to exit as trivially as possible. Ignored on this
* plugin.
* @return true normally, or false to prevent any further
* plugins being called on this sprite for this frame.
*/
Face8Way.prototype.update = function(now, phaseOn) {
var s = this.sprite;
var dx = s.directionx - s.x;
var dy = 2*(s.directiony - s.y); /* Because Y is halved in isometric land */
var d;
if (dy===0) {
if (dx===0) {
d = this.direction;
} else {
d = dx>0?'e':'w';
}
} else {
/* dy!=0 => Division is ok */
var r = dx/dy;
if (r>=0) {
if (r < 0.41421) {
d = dy>0?'s':'n';
} else if(r > 2.4142) {
d = dx>0?'e':'w';
} else {
d = dx>0?'se':'nw';
}
} else {
if (r > -0.41421) {
d = dy>0?'s':'n';
} else if(r < -2.4142) {
d = dx>0?'e':'w';
} else {
d = dx>0?'ne':'sw';
}
}
}
this.direction = d;
this.oldx = s.x;
this.oldy = s.y;
s.setState(s.stateName, this.direction);
return true;
};
Face8Way.prototype.init = function(sprite) {
this.sprite = sprite;
this.direction = 'e';
};
Face8Way.prototype.onSpriteRemoved = function() {
};
return function(snaps) {
sn = snaps;
sn.registerSpriteUpdater('8way', Face8Way);
};
});
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="pathfinder.html">ai/pathfinder</a></li><li><a href="tween.html">animate/tween</a></li></ul><h3>Classes</h3><ul><li><a href="pathfinder.PathFinder.html">PathFinder</a></li></ul><h3>Global</h3><ul><li><a href="global.html#fastRand">fastRand</a></li></ul>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.0-dev</a> on Tue Apr 30 2013 22:41:04 GMT+0100 (BST)
</footer>
<script> prettyPrint(); </script>
</body>
</html>