PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/BodyDebug.js.html

https://gitlab.com/lobsterhands/phaser
HTML | 1009 lines | 766 code | 240 blank | 3 comment | 0 complexity | 8d99333720cf1b4e70e9ffd157e34866 MD5 | raw file
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Phaser Source: physics/p2/BodyDebug.js</title>
  6. <!--[if lt IE 9]>
  7. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  8. <![endif]-->
  9. <link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
  10. <link type="text/css" rel="stylesheet" href="styles/site.cerulean.css">
  11. </head>
  12. <body>
  13. <div class="container-fluid">
  14. <div class="navbar navbar-fixed-top navbar-inverse">
  15. <div class="navbar-inner">
  16. <a class="brand" href="index.html">Phaser</a>
  17. <ul class="nav">
  18. <li class="dropdown">
  19. <a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b
  20. class="caret"></b></a>
  21. <ul class="dropdown-menu ">
  22. <li class="class-depth-0">
  23. <a href="Phaser.html">Phaser</a>
  24. </li>
  25. </ul>
  26. </li>
  27. <li class="dropdown">
  28. <a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b
  29. class="caret"></b></a>
  30. <ul class="dropdown-menu ">
  31. <li class="class-depth-1">
  32. <a href="Phaser.Animation.html">Animation</a>
  33. </li>
  34. <li class="class-depth-1">
  35. <a href="Phaser.AnimationManager.html">AnimationManager</a>
  36. </li>
  37. <li class="class-depth-1">
  38. <a href="Phaser.AnimationParser.html">AnimationParser</a>
  39. </li>
  40. <li class="class-depth-1">
  41. <a href="Phaser.BitmapData.html">BitmapData</a>
  42. </li>
  43. <li class="class-depth-1">
  44. <a href="Phaser.BitmapText.html">BitmapText</a>
  45. </li>
  46. <li class="class-depth-1">
  47. <a href="Phaser.Button.html">Button</a>
  48. </li>
  49. <li class="class-depth-1">
  50. <a href="Phaser.Cache.html">Cache</a>
  51. </li>
  52. <li class="class-depth-1">
  53. <a href="Phaser.Camera.html">Camera</a>
  54. </li>
  55. <li class="class-depth-1">
  56. <a href="Phaser.Canvas.html">Canvas</a>
  57. </li>
  58. <li class="class-depth-1">
  59. <a href="Phaser.Circle.html">Circle</a>
  60. </li>
  61. <li class="class-depth-1">
  62. <a href="Phaser.Color.html">Color</a>
  63. </li>
  64. <li class="class-depth-1">
  65. <a href="Phaser.Device.html">Device</a>
  66. </li>
  67. <li class="class-depth-1">
  68. <a href="Phaser.Easing.html">Easing</a>
  69. </li>
  70. <li class="class-depth-2">
  71. <a href="Phaser.Easing.Back.html">Back</a>
  72. </li>
  73. <li class="class-depth-2">
  74. <a href="Phaser.Easing.Bounce.html">Bounce</a>
  75. </li>
  76. <li class="class-depth-2">
  77. <a href="Phaser.Easing.Circular.html">Circular</a>
  78. </li>
  79. <li class="class-depth-2">
  80. <a href="Phaser.Easing.Cubic.html">Cubic</a>
  81. </li>
  82. <li class="class-depth-2">
  83. <a href="Phaser.Easing.Elastic.html">Elastic</a>
  84. </li>
  85. <li class="class-depth-2">
  86. <a href="Phaser.Easing.Exponential.html">Exponential</a>
  87. </li>
  88. <li class="class-depth-2">
  89. <a href="Phaser.Easing.Linear.html">Linear</a>
  90. </li>
  91. <li class="class-depth-2">
  92. <a href="Phaser.Easing.Quadratic.html">Quadratic</a>
  93. </li>
  94. <li class="class-depth-2">
  95. <a href="Phaser.Easing.Quartic.html">Quartic</a>
  96. </li>
  97. <li class="class-depth-2">
  98. <a href="Phaser.Easing.Quintic.html">Quintic</a>
  99. </li>
  100. <li class="class-depth-2">
  101. <a href="Phaser.Easing.Sinusoidal.html">Sinusoidal</a>
  102. </li>
  103. <li class="class-depth-1">
  104. <a href="Phaser.Ellipse.html">Ellipse</a>
  105. </li>
  106. <li class="class-depth-1">
  107. <a href="Phaser.Events.html">Events</a>
  108. </li>
  109. <li class="class-depth-1">
  110. <a href="Phaser.Filter.html">Filter</a>
  111. </li>
  112. <li class="class-depth-1">
  113. <a href="Phaser.Frame.html">Frame</a>
  114. </li>
  115. <li class="class-depth-1">
  116. <a href="Phaser.FrameData.html">FrameData</a>
  117. </li>
  118. <li class="class-depth-1">
  119. <a href="Phaser.Game.html">Game</a>
  120. </li>
  121. <li class="class-depth-1">
  122. <a href="Phaser.GameObjectCreator.html">GameObjectCreator</a>
  123. </li>
  124. <li class="class-depth-1">
  125. <a href="Phaser.GameObjectFactory.html">GameObjectFactory</a>
  126. </li>
  127. <li class="class-depth-1">
  128. <a href="Phaser.Gamepad.html">Gamepad</a>
  129. </li>
  130. <li class="class-depth-1">
  131. <a href="Phaser.GamepadButton.html">GamepadButton</a>
  132. </li>
  133. <li class="class-depth-1">
  134. <a href="Phaser.Graphics.html">Graphics</a>
  135. </li>
  136. <li class="class-depth-1">
  137. <a href="Phaser.Group.html">Group</a>
  138. </li>
  139. <li class="class-depth-1">
  140. <a href="Phaser.Image.html">Image</a>
  141. </li>
  142. <li class="class-depth-1">
  143. <a href="Phaser.Input.html">Input</a>
  144. </li>
  145. <li class="class-depth-1">
  146. <a href="Phaser.InputHandler.html">InputHandler</a>
  147. </li>
  148. <li class="class-depth-1">
  149. <a href="Phaser.Key.html">Key</a>
  150. </li>
  151. <li class="class-depth-1">
  152. <a href="Phaser.Keyboard.html">Keyboard</a>
  153. </li>
  154. <li class="class-depth-1">
  155. <a href="Phaser.Line.html">Line</a>
  156. </li>
  157. <li class="class-depth-1">
  158. <a href="Phaser.LinkedList.html">LinkedList</a>
  159. </li>
  160. <li class="class-depth-1">
  161. <a href="Phaser.Loader.html">Loader</a>
  162. </li>
  163. <li class="class-depth-1">
  164. <a href="Phaser.LoaderParser.html">LoaderParser</a>
  165. </li>
  166. <li class="class-depth-1">
  167. <a href="Phaser.Math.html">Math</a>
  168. </li>
  169. <li class="class-depth-1">
  170. <a href="Phaser.Mouse.html">Mouse</a>
  171. </li>
  172. <li class="class-depth-1">
  173. <a href="Phaser.MSPointer.html">MSPointer</a>
  174. </li>
  175. <li class="class-depth-1">
  176. <a href="Phaser.Net.html">Net</a>
  177. </li>
  178. <li class="class-depth-1">
  179. <a href="Phaser.Particle.html">Particle</a>
  180. </li>
  181. <li class="class-depth-1">
  182. <a href="Phaser.Particles.html">Particles</a>
  183. </li>
  184. <li class="class-depth-3">
  185. <a href="Phaser.Particles.Arcade.Emitter.html">Emitter</a>
  186. </li>
  187. <li class="class-depth-1">
  188. <a href="Phaser.Physics.html">Physics</a>
  189. </li>
  190. <li class="class-depth-2">
  191. <a href="Phaser.Physics.Arcade.html">Arcade</a>
  192. </li>
  193. <li class="class-depth-3">
  194. <a href="Phaser.Physics.Arcade.Body.html">Body</a>
  195. </li>
  196. <li class="class-depth-2">
  197. <a href="Phaser.Physics.Ninja.html">Ninja</a>
  198. </li>
  199. <li class="class-depth-3">
  200. <a href="Phaser.Physics.Ninja.AABB.html">AABB</a>
  201. </li>
  202. <li class="class-depth-3">
  203. <a href="Phaser.Physics.Ninja.Body.html">Body</a>
  204. </li>
  205. <li class="class-depth-3">
  206. <a href="Phaser.Physics.Ninja.Circle.html">Circle</a>
  207. </li>
  208. <li class="class-depth-3">
  209. <a href="Phaser.Physics.Ninja.Tile.html">Tile</a>
  210. </li>
  211. <li class="class-depth-2">
  212. <a href="Phaser.Physics.P2.html">P2</a>
  213. </li>
  214. <li class="class-depth-3">
  215. <a href="Phaser.Physics.P2.Body.html">Body</a>
  216. </li>
  217. <li class="class-depth-3">
  218. <a href="Phaser.Physics.P2.BodyDebug.html">BodyDebug</a>
  219. </li>
  220. <li class="class-depth-3">
  221. <a href="Phaser.Physics.P2.CollisionGroup.html">CollisionGroup</a>
  222. </li>
  223. <li class="class-depth-3">
  224. <a href="Phaser.Physics.P2.ContactMaterial.html">ContactMaterial</a>
  225. </li>
  226. <li class="class-depth-3">
  227. <a href="Phaser.Physics.P2.DistanceConstraint.html">DistanceConstraint</a>
  228. </li>
  229. <li class="class-depth-3">
  230. <a href="Phaser.Physics.P2.FixtureList.html">FixtureList</a>
  231. </li>
  232. <li class="class-depth-3">
  233. <a href="Phaser.Physics.P2.GearConstraint.html">GearConstraint</a>
  234. </li>
  235. <li class="class-depth-3">
  236. <a href="Phaser.Physics.P2.InversePointProxy.html">InversePointProxy</a>
  237. </li>
  238. <li class="class-depth-3">
  239. <a href="Phaser.Physics.P2.LockConstraint.html">LockConstraint</a>
  240. </li>
  241. <li class="class-depth-3">
  242. <a href="Phaser.Physics.P2.Material.html">Material</a>
  243. </li>
  244. <li class="class-depth-3">
  245. <a href="Phaser.Physics.P2.PointProxy.html">PointProxy</a>
  246. </li>
  247. <li class="class-depth-3">
  248. <a href="Phaser.Physics.P2.PrismaticConstraint.html">PrismaticConstraint</a>
  249. </li>
  250. <li class="class-depth-3">
  251. <a href="Phaser.Physics.P2.RevoluteConstraint.html">RevoluteConstraint</a>
  252. </li>
  253. <li class="class-depth-3">
  254. <a href="Phaser.Physics.P2.Spring.html">Spring</a>
  255. </li>
  256. <li class="class-depth-1">
  257. <a href="Phaser.Plugin.html">Plugin</a>
  258. </li>
  259. <li class="class-depth-1">
  260. <a href="Phaser.PluginManager.html">PluginManager</a>
  261. </li>
  262. <li class="class-depth-1">
  263. <a href="Phaser.Point.html">Point</a>
  264. </li>
  265. <li class="class-depth-1">
  266. <a href="Phaser.Pointer.html">Pointer</a>
  267. </li>
  268. <li class="class-depth-1">
  269. <a href="Phaser.Polygon.html">Polygon</a>
  270. </li>
  271. <li class="class-depth-1">
  272. <a href="Phaser.QuadTree.html">QuadTree</a>
  273. </li>
  274. <li class="class-depth-1">
  275. <a href="Phaser.RandomDataGenerator.html">RandomDataGenerator</a>
  276. </li>
  277. <li class="class-depth-1">
  278. <a href="Phaser.Rectangle.html">Rectangle</a>
  279. </li>
  280. <li class="class-depth-1">
  281. <a href="Phaser.RenderTexture.html">RenderTexture</a>
  282. </li>
  283. <li class="class-depth-1">
  284. <a href="Phaser.RequestAnimationFrame.html">RequestAnimationFrame</a>
  285. </li>
  286. <li class="class-depth-1">
  287. <a href="Phaser.RetroFont.html">RetroFont</a>
  288. </li>
  289. <li class="class-depth-1">
  290. <a href="Phaser.ScaleManager.html">ScaleManager</a>
  291. </li>
  292. <li class="class-depth-1">
  293. <a href="Phaser.Signal.html">Signal</a>
  294. </li>
  295. <li class="class-depth-1">
  296. <a href="Phaser.SignalBinding.html">SignalBinding</a>
  297. </li>
  298. <li class="class-depth-1">
  299. <a href="Phaser.SinglePad.html">SinglePad</a>
  300. </li>
  301. <li class="class-depth-1">
  302. <a href="Phaser.Sound.html">Sound</a>
  303. </li>
  304. <li class="class-depth-1">
  305. <a href="Phaser.SoundManager.html">SoundManager</a>
  306. </li>
  307. <li class="class-depth-1">
  308. <a href="Phaser.Sprite.html">Sprite</a>
  309. </li>
  310. <li class="class-depth-1">
  311. <a href="Phaser.SpriteBatch.html">SpriteBatch</a>
  312. </li>
  313. <li class="class-depth-1">
  314. <a href="Phaser.Stage.html">Stage</a>
  315. </li>
  316. <li class="class-depth-1">
  317. <a href="Phaser.State.html">State</a>
  318. </li>
  319. <li class="class-depth-1">
  320. <a href="Phaser.StateManager.html">StateManager</a>
  321. </li>
  322. <li class="class-depth-1">
  323. <a href="Phaser.Text.html">Text</a>
  324. </li>
  325. <li class="class-depth-1">
  326. <a href="Phaser.Tile.html">Tile</a>
  327. </li>
  328. <li class="class-depth-1">
  329. <a href="Phaser.Tilemap.html">Tilemap</a>
  330. </li>
  331. <li class="class-depth-1">
  332. <a href="Phaser.TilemapLayer.html">TilemapLayer</a>
  333. </li>
  334. <li class="class-depth-1">
  335. <a href="Phaser.TilemapParser.html">TilemapParser</a>
  336. </li>
  337. <li class="class-depth-1">
  338. <a href="Phaser.Tileset.html">Tileset</a>
  339. </li>
  340. <li class="class-depth-1">
  341. <a href="Phaser.TileSprite.html">TileSprite</a>
  342. </li>
  343. <li class="class-depth-1">
  344. <a href="Phaser.Time.html">Time</a>
  345. </li>
  346. <li class="class-depth-1">
  347. <a href="Phaser.Timer.html">Timer</a>
  348. </li>
  349. <li class="class-depth-1">
  350. <a href="Phaser.TimerEvent.html">TimerEvent</a>
  351. </li>
  352. <li class="class-depth-1">
  353. <a href="Phaser.Touch.html">Touch</a>
  354. </li>
  355. <li class="class-depth-1">
  356. <a href="Phaser.Tween.html">Tween</a>
  357. </li>
  358. <li class="class-depth-1">
  359. <a href="Phaser.TweenManager.html">TweenManager</a>
  360. </li>
  361. <li class="class-depth-1">
  362. <a href="Phaser.Utils.html">Utils</a>
  363. </li>
  364. <li class="class-depth-2">
  365. <a href="Phaser.Utils.Debug.html">Debug</a>
  366. </li>
  367. <li class="class-depth-1">
  368. <a href="Phaser.World.html">World</a>
  369. </li>
  370. </ul>
  371. </li>
  372. </ul>
  373. </div>
  374. </div>
  375. <div class="row-fluid">
  376. <div class="span12">
  377. <div id="main">
  378. <h1 class="page-title">Source: physics/p2/BodyDebug.js</h1>
  379. <section>
  380. <article>
  381. <pre class="sunlight-highlight-javascript linenums">/**
  382. * @author George https://github.com/georgiee
  383. * @author Richard Davey &lt;rich@photonstorm.com>
  384. * @copyright 2014 Photon Storm Ltd.
  385. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
  386. */
  387. /**
  388. * Draws a P2 Body to a Graphics instance for visual debugging.
  389. * Needless to say, for every body you enable debug drawing on, you are adding processor and graphical overhead.
  390. * So use sparingly and rarely (if ever) in production code.
  391. *
  392. * @class Phaser.Physics.P2.BodyDebug
  393. * @classdesc Physics Body Debug Constructor
  394. * @constructor
  395. * @extends Phaser.Group
  396. * @param {Phaser.Game} game - Game reference to the currently running game.
  397. * @param {Phaser.Physics.P2.Body} body - The P2 Body to display debug data for.
  398. * @param {object} settings - Settings object.
  399. */
  400. Phaser.Physics.P2.BodyDebug = function(game, body, settings) {
  401. Phaser.Group.call(this, game);
  402. /**
  403. * @property {object} defaultSettings - Default debug settings.
  404. * @private
  405. */
  406. var defaultSettings = {
  407. pixelsPerLengthUnit: 20,
  408. debugPolygons: false,
  409. lineWidth: 1,
  410. alpha: 0.5
  411. };
  412. this.settings = Phaser.Utils.extend(defaultSettings, settings);
  413. /**
  414. * @property {number} ppu - Pixels per Length Unit.
  415. */
  416. this.ppu = this.settings.pixelsPerLengthUnit;
  417. this.ppu = -1 * this.ppu;
  418. /**
  419. * @property {Phaser.Physics.P2.Body} body - The P2 Body to display debug data for.
  420. */
  421. this.body = body;
  422. /**
  423. * @property {Phaser.Graphics} canvas - The canvas to render the debug info to.
  424. */
  425. this.canvas = new Phaser.Graphics(game);
  426. this.canvas.alpha = this.settings.alpha;
  427. this.add(this.canvas);
  428. this.draw();
  429. };
  430. Phaser.Physics.P2.BodyDebug.prototype = Object.create(Phaser.Group.prototype);
  431. Phaser.Physics.P2.BodyDebug.prototype.constructor = Phaser.Physics.P2.BodyDebug;
  432. Phaser.Utils.extend(Phaser.Physics.P2.BodyDebug.prototype, {
  433. /**
  434. * Core update.
  435. *
  436. * @method Phaser.Physics.P2.BodyDebug#update
  437. */
  438. update: function() {
  439. this.updateSpriteTransform();
  440. },
  441. /**
  442. * Core update.
  443. *
  444. * @method Phaser.Physics.P2.BodyDebug#updateSpriteTransform
  445. */
  446. updateSpriteTransform: function() {
  447. this.position.x = this.body.position[0] * this.ppu;
  448. this.position.y = this.body.position[1] * this.ppu;
  449. return this.rotation = this.body.angle;
  450. },
  451. /**
  452. * Draws the P2 shapes to the Graphics object.
  453. *
  454. * @method Phaser.Physics.P2.BodyDebug#draw
  455. */
  456. draw: function() {
  457. var angle, child, color, i, j, lineColor, lw, obj, offset, sprite, v, verts, vrot, _j, _ref1;
  458. obj = this.body;
  459. sprite = this.canvas;
  460. sprite.clear();
  461. color = parseInt(this.randomPastelHex(), 16);
  462. lineColor = 0xff0000;
  463. lw = this.lineWidth;
  464. if (obj instanceof p2.Body && obj.shapes.length)
  465. {
  466. var l = obj.shapes.length;
  467. i = 0;
  468. while (i !== l)
  469. {
  470. child = obj.shapes[i];
  471. offset = obj.shapeOffsets[i];
  472. angle = obj.shapeAngles[i];
  473. offset = offset || 0;
  474. angle = angle || 0;
  475. if (child instanceof p2.Circle)
  476. {
  477. this.drawCircle(sprite, offset[0] * this.ppu, offset[1] * this.ppu, angle, child.radius * this.ppu, color, lw);
  478. }
  479. else if (child instanceof p2.Convex)
  480. {
  481. verts = [];
  482. vrot = p2.vec2.create();
  483. for (j = _j = 0, _ref1 = child.vertices.length; 0 &lt;= _ref1 ? _j &lt; _ref1 : _j > _ref1; j = 0 &lt;= _ref1 ? ++_j : --_j)
  484. {
  485. v = child.vertices[j];
  486. p2.vec2.rotate(vrot, v, angle);
  487. verts.push([(vrot[0] + offset[0]) * this.ppu, -(vrot[1] + offset[1]) * this.ppu]);
  488. }
  489. this.drawConvex(sprite, verts, child.triangles, lineColor, color, lw, this.settings.debugPolygons, [offset[0] * this.ppu, -offset[1] * this.ppu]);
  490. }
  491. else if (child instanceof p2.Plane)
  492. {
  493. this.drawPlane(sprite, offset[0] * this.ppu, -offset[1] * this.ppu, color, lineColor, lw * 5, lw * 10, lw * 10, this.ppu * 100, angle);
  494. }
  495. else if (child instanceof p2.Line)
  496. {
  497. this.drawLine(sprite, child.length * this.ppu, lineColor, lw);
  498. }
  499. else if (child instanceof p2.Rectangle)
  500. {
  501. this.drawRectangle(sprite, offset[0] * this.ppu, -offset[1] * this.ppu, angle, child.width * this.ppu, child.height * this.ppu, lineColor, color, lw);
  502. }
  503. i++;
  504. }
  505. }
  506. },
  507. /**
  508. * Draws the P2 shapes to the Graphics object.
  509. *
  510. * @method Phaser.Physics.P2.BodyDebug#draw
  511. */
  512. drawRectangle: function(g, x, y, angle, w, h, color, fillColor, lineWidth) {
  513. if (typeof lineWidth === 'undefined') { lineWidth = 1; }
  514. if (typeof color === 'undefined') { color = 0x000000; }
  515. g.lineStyle(lineWidth, color, 1);
  516. g.beginFill(fillColor);
  517. g.drawRect(x - w / 2, y - h / 2, w, h);
  518. },
  519. /**
  520. * Draws a P2 Circle shape.
  521. *
  522. * @method Phaser.Physics.P2.BodyDebug#drawCircle
  523. */
  524. drawCircle: function(g, x, y, angle, radius, color, lineWidth) {
  525. if (typeof lineWidth === 'undefined') { lineWidth = 1; }
  526. if (typeof color === 'undefined') { color = 0xffffff; }
  527. g.lineStyle(lineWidth, 0x000000, 1);
  528. g.beginFill(color, 1.0);
  529. g.drawCircle(x, y, -radius);
  530. g.endFill();
  531. g.moveTo(x, y);
  532. g.lineTo(x + radius * Math.cos(-angle), y + radius * Math.sin(-angle));
  533. },
  534. /**
  535. * Draws a P2 Line shape.
  536. *
  537. * @method Phaser.Physics.P2.BodyDebug#drawCircle
  538. */
  539. drawLine: function(g, len, color, lineWidth) {
  540. if (typeof lineWidth === 'undefined') { lineWidth = 1; }
  541. if (typeof color === 'undefined') { color = 0x000000; }
  542. g.lineStyle(lineWidth * 5, color, 1);
  543. g.moveTo(-len / 2, 0);
  544. g.lineTo(len / 2, 0);
  545. },
  546. /**
  547. * Draws a P2 Convex shape.
  548. *
  549. * @method Phaser.Physics.P2.BodyDebug#drawConvex
  550. */
  551. drawConvex: function(g, verts, triangles, color, fillColor, lineWidth, debug, offset) {
  552. var colors, i, v, v0, v1, x, x0, x1, y, y0, y1;
  553. if (typeof lineWidth === 'undefined') { lineWidth = 1; }
  554. if (typeof color === 'undefined') { color = 0x000000; }
  555. if (!debug)
  556. {
  557. g.lineStyle(lineWidth, color, 1);
  558. g.beginFill(fillColor);
  559. i = 0;
  560. while (i !== verts.length)
  561. {
  562. v = verts[i];
  563. x = v[0];
  564. y = v[1];
  565. if (i === 0)
  566. {
  567. g.moveTo(x, -y);
  568. }
  569. else
  570. {
  571. g.lineTo(x, -y);
  572. }
  573. i++;
  574. }
  575. g.endFill();
  576. if (verts.length > 2)
  577. {
  578. g.moveTo(verts[verts.length - 1][0], -verts[verts.length - 1][1]);
  579. return g.lineTo(verts[0][0], -verts[0][1]);
  580. }
  581. }
  582. else
  583. {
  584. colors = [0xff0000, 0x00ff00, 0x0000ff];
  585. i = 0;
  586. while (i !== verts.length + 1)
  587. {
  588. v0 = verts[i % verts.length];
  589. v1 = verts[(i + 1) % verts.length];
  590. x0 = v0[0];
  591. y0 = v0[1];
  592. x1 = v1[0];
  593. y1 = v1[1];
  594. g.lineStyle(lineWidth, colors[i % colors.length], 1);
  595. g.moveTo(x0, -y0);
  596. g.lineTo(x1, -y1);
  597. g.drawCircle(x0, -y0, lineWidth * 2);
  598. i++;
  599. }
  600. g.lineStyle(lineWidth, 0x000000, 1);
  601. return g.drawCircle(offset[0], offset[1], lineWidth * 2);
  602. }
  603. },
  604. /**
  605. * Draws a P2 Path.
  606. *
  607. * @method Phaser.Physics.P2.BodyDebug#drawPath
  608. */
  609. drawPath: function(g, path, color, fillColor, lineWidth) {
  610. var area, i, lastx, lasty, p1x, p1y, p2x, p2y, p3x, p3y, v, x, y;
  611. if (typeof lineWidth === 'undefined') { lineWidth = 1; }
  612. if (typeof color === 'undefined') { color = 0x000000; }
  613. g.lineStyle(lineWidth, color, 1);
  614. if (typeof fillColor === "number")
  615. {
  616. g.beginFill(fillColor);
  617. }
  618. lastx = null;
  619. lasty = null;
  620. i = 0;
  621. while (i &lt; path.length)
  622. {
  623. v = path[i];
  624. x = v[0];
  625. y = v[1];
  626. if (x !== lastx || y !== lasty)
  627. {
  628. if (i === 0)
  629. {
  630. g.moveTo(x, y);
  631. }
  632. else
  633. {
  634. p1x = lastx;
  635. p1y = lasty;
  636. p2x = x;
  637. p2y = y;
  638. p3x = path[(i + 1) % path.length][0];
  639. p3y = path[(i + 1) % path.length][1];
  640. area = ((p2x - p1x) * (p3y - p1y)) - ((p3x - p1x) * (p2y - p1y));
  641. if (area !== 0)
  642. {
  643. g.lineTo(x, y);
  644. }
  645. }
  646. lastx = x;
  647. lasty = y;
  648. }
  649. i++;
  650. }
  651. if (typeof fillColor === "number")
  652. {
  653. g.endFill();
  654. }
  655. if (path.length > 2 && typeof fillColor === "number")
  656. {
  657. g.moveTo(path[path.length - 1][0], path[path.length - 1][1]);
  658. g.lineTo(path[0][0], path[0][1]);
  659. }
  660. },
  661. /**
  662. * Draws a P2 Plane shape.
  663. *
  664. * @method Phaser.Physics.P2.BodyDebug#drawPlane
  665. */
  666. drawPlane: function(g, x0, x1, color, lineColor, lineWidth, diagMargin, diagSize, maxLength, angle) {
  667. var max, xd, yd;
  668. if (typeof lineWidth === 'undefined') { lineWidth = 1; }
  669. if (typeof color === 'undefined') { color = 0xffffff; }
  670. g.lineStyle(lineWidth, lineColor, 11);
  671. g.beginFill(color);
  672. max = maxLength;
  673. g.moveTo(x0, -x1);
  674. xd = x0 + Math.cos(angle) * this.game.width;
  675. yd = x1 + Math.sin(angle) * this.game.height;
  676. g.lineTo(xd, -yd);
  677. g.moveTo(x0, -x1);
  678. xd = x0 + Math.cos(angle) * -this.game.width;
  679. yd = x1 + Math.sin(angle) * -this.game.height;
  680. g.lineTo(xd, -yd);
  681. },
  682. /**
  683. * Picks a random pastel color.
  684. *
  685. * @method Phaser.Physics.P2.BodyDebug#randomPastelHex
  686. */
  687. randomPastelHex: function() {
  688. var blue, green, mix, red;
  689. mix = [255, 255, 255];
  690. red = Math.floor(Math.random() * 256);
  691. green = Math.floor(Math.random() * 256);
  692. blue = Math.floor(Math.random() * 256);
  693. red = Math.floor((red + 3 * mix[0]) / 4);
  694. green = Math.floor((green + 3 * mix[1]) / 4);
  695. blue = Math.floor((blue + 3 * mix[2]) / 4);
  696. return this.rgbToHex(red, green, blue);
  697. },
  698. /**
  699. * Converts from RGB to Hex.
  700. *
  701. * @method Phaser.Physics.P2.BodyDebug#rgbToHex
  702. */
  703. rgbToHex: function(r, g, b) {
  704. return this.componentToHex(r) + this.componentToHex(g) + this.componentToHex(b);
  705. },
  706. /**
  707. * Component to hex conversion.
  708. *
  709. * @method Phaser.Physics.P2.BodyDebug#componentToHex
  710. */
  711. componentToHex: function(c) {
  712. var hex;
  713. hex = c.toString(16);
  714. if (hex.len === 2)
  715. {
  716. return hex;
  717. }
  718. else
  719. {
  720. return hex + '0';
  721. }
  722. }
  723. });
  724. </pre>
  725. </article>
  726. </section>
  727. </div>
  728. <div class="clearfix"></div>
  729. <footer>
  730. <span class="copyright">
  731. Phaser Copyright © 2012-2014 Photon Storm Ltd.
  732. </span>
  733. <br />
  734. <span class="jsdoc-message">
  735. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-dev</a>
  736. on Fri Apr 11 2014 13:25:03 GMT+0100 (BST) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
  737. </span>
  738. </footer>
  739. </div>
  740. <br clear="both">
  741. </div>
  742. </div>
  743. <script src="scripts/sunlight.js"></script>
  744. <script src="scripts/sunlight.javascript.js"></script>
  745. <script src="scripts/sunlight-plugin.doclinks.js"></script>
  746. <script src="scripts/sunlight-plugin.linenumbers.js"></script>
  747. <script src="scripts/sunlight-plugin.menu.js"></script>
  748. <script src="scripts/jquery.min.js"></script>
  749. <script src="scripts/jquery.scrollTo.js"></script>
  750. <script src="scripts/jquery.localScroll.js"></script>
  751. <script src="scripts/bootstrap-dropdown.js"></script>
  752. <script src="scripts/toc.js"></script>
  753. <script> Sunlight.highlightAll({lineNumbers:true, showMenu: true, enableDoclinks :true}); </script>
  754. <script>
  755. $( function () {
  756. $( "#toc" ).toc( {
  757. anchorName : function(i, heading, prefix) {
  758. return $(heading).attr("id") || ( prefix + i );
  759. },
  760. selectors : "h1,h2,h3,h4",
  761. showAndHide : false,
  762. scrollTo : 60
  763. } );
  764. $( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
  765. $( "#main span[id^='toc']" ).addClass( "toc-shim" );
  766. } );
  767. </script>
  768. </body>
  769. </html>