PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/AnimationParser.js.html

https://gitlab.com/lobsterhands/phaser
HTML | 897 lines | 680 code | 214 blank | 3 comment | 0 complexity | a0f82c13cf0cc8c09bae1c0d5bfe48cf MD5 | raw file
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Phaser Source: animation/AnimationParser.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: animation/AnimationParser.js</h1>
  379. <section>
  380. <article>
  381. <pre class="sunlight-highlight-javascript linenums">/**
  382. * @author Richard Davey &lt;rich@photonstorm.com>
  383. * @copyright 2014 Photon Storm Ltd.
  384. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
  385. */
  386. /**
  387. * Responsible for parsing sprite sheet and JSON data into the internal FrameData format that Phaser uses for animations.
  388. *
  389. * @class Phaser.AnimationParser
  390. */
  391. Phaser.AnimationParser = {
  392. /**
  393. * Parse a Sprite Sheet and extract the animation frame data from it.
  394. *
  395. * @method Phaser.AnimationParser.spriteSheet
  396. * @param {Phaser.Game} game - A reference to the currently running game.
  397. * @param {string} key - The Game.Cache asset key of the Sprite Sheet image.
  398. * @param {number} frameWidth - The fixed width of each frame of the animation.
  399. * @param {number} frameHeight - The fixed height of each frame of the animation.
  400. * @param {number} [frameMax=-1] - The total number of animation frames to extact from the Sprite Sheet. The default value of -1 means "extract all frames".
  401. * @param {number} [margin=0] - If the frames have been drawn with a margin, specify the amount here.
  402. * @param {number} [spacing=0] - If the frames have been drawn with spacing between them, specify the amount here.
  403. * @return {Phaser.FrameData} A FrameData object containing the parsed frames.
  404. */
  405. spriteSheet: function (game, key, frameWidth, frameHeight, frameMax, margin, spacing) {
  406. // How big is our image?
  407. var img = game.cache.getImage(key);
  408. if (img == null)
  409. {
  410. return null;
  411. }
  412. var width = img.width;
  413. var height = img.height;
  414. if (frameWidth &lt;= 0)
  415. {
  416. frameWidth = Math.floor(-width / Math.min(-1, frameWidth));
  417. }
  418. if (frameHeight &lt;= 0)
  419. {
  420. frameHeight = Math.floor(-height / Math.min(-1, frameHeight));
  421. }
  422. var row = Math.floor((width - margin) / (frameWidth + spacing));
  423. var column = Math.floor((height - margin) / (frameHeight + spacing));
  424. var total = row * column;
  425. if (frameMax !== -1)
  426. {
  427. total = frameMax;
  428. }
  429. // Zero or smaller than frame sizes?
  430. if (width === 0 || height === 0 || width &lt; frameWidth || height &lt; frameHeight || total === 0)
  431. {
  432. console.warn("Phaser.AnimationParser.spriteSheet: width/height zero or width/height &lt; given frameWidth/frameHeight");
  433. return null;
  434. }
  435. // Let's create some frames then
  436. var data = new Phaser.FrameData();
  437. var x = margin;
  438. var y = margin;
  439. for (var i = 0; i &lt; total; i++)
  440. {
  441. var uuid = game.rnd.uuid();
  442. data.addFrame(new Phaser.Frame(i, x, y, frameWidth, frameHeight, '', uuid));
  443. PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[key], {
  444. x: x,
  445. y: y,
  446. width: frameWidth,
  447. height: frameHeight
  448. });
  449. x += frameWidth + spacing;
  450. if (x + frameWidth > width)
  451. {
  452. x = margin;
  453. y += frameHeight + spacing;
  454. }
  455. }
  456. return data;
  457. },
  458. /**
  459. * Parse the JSON data and extract the animation frame data from it.
  460. *
  461. * @method Phaser.AnimationParser.JSONData
  462. * @param {Phaser.Game} game - A reference to the currently running game.
  463. * @param {Object} json - The JSON data from the Texture Atlas. Must be in Array format.
  464. * @param {string} cacheKey - The Game.Cache asset key of the texture image.
  465. * @return {Phaser.FrameData} A FrameData object containing the parsed frames.
  466. */
  467. JSONData: function (game, json, cacheKey) {
  468. // Malformed?
  469. if (!json['frames'])
  470. {
  471. console.warn("Phaser.AnimationParser.JSONData: Invalid Texture Atlas JSON given, missing 'frames' array");
  472. console.log(json);
  473. return;
  474. }
  475. // Let's create some frames then
  476. var data = new Phaser.FrameData();
  477. // By this stage frames is a fully parsed array
  478. var frames = json['frames'];
  479. var newFrame;
  480. for (var i = 0; i &lt; frames.length; i++)
  481. {
  482. var uuid = game.rnd.uuid();
  483. newFrame = data.addFrame(new Phaser.Frame(
  484. i,
  485. frames[i].frame.x,
  486. frames[i].frame.y,
  487. frames[i].frame.w,
  488. frames[i].frame.h,
  489. frames[i].filename,
  490. uuid
  491. ));
  492. PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[cacheKey], {
  493. x: frames[i].frame.x,
  494. y: frames[i].frame.y,
  495. width: frames[i].frame.w,
  496. height: frames[i].frame.h
  497. });
  498. if (frames[i].trimmed)
  499. {
  500. newFrame.setTrim(
  501. frames[i].trimmed,
  502. frames[i].sourceSize.w,
  503. frames[i].sourceSize.h,
  504. frames[i].spriteSourceSize.x,
  505. frames[i].spriteSourceSize.y,
  506. frames[i].spriteSourceSize.w,
  507. frames[i].spriteSourceSize.h
  508. );
  509. PIXI.TextureCache[uuid].trim = new Phaser.Rectangle(frames[i].spriteSourceSize.x, frames[i].spriteSourceSize.y, frames[i].sourceSize.w, frames[i].sourceSize.h);
  510. }
  511. }
  512. return data;
  513. },
  514. /**
  515. * Parse the JSON data and extract the animation frame data from it.
  516. *
  517. * @method Phaser.AnimationParser.JSONDataHash
  518. * @param {Phaser.Game} game - A reference to the currently running game.
  519. * @param {Object} json - The JSON data from the Texture Atlas. Must be in JSON Hash format.
  520. * @param {string} cacheKey - The Game.Cache asset key of the texture image.
  521. * @return {Phaser.FrameData} A FrameData object containing the parsed frames.
  522. */
  523. JSONDataHash: function (game, json, cacheKey) {
  524. // Malformed?
  525. if (!json['frames'])
  526. {
  527. console.warn("Phaser.AnimationParser.JSONDataHash: Invalid Texture Atlas JSON given, missing 'frames' object");
  528. console.log(json);
  529. return;
  530. }
  531. // Let's create some frames then
  532. var data = new Phaser.FrameData();
  533. // By this stage frames is a fully parsed array
  534. var frames = json['frames'];
  535. var newFrame;
  536. var i = 0;
  537. for (var key in frames)
  538. {
  539. var uuid = game.rnd.uuid();
  540. newFrame = data.addFrame(new Phaser.Frame(
  541. i,
  542. frames[key].frame.x,
  543. frames[key].frame.y,
  544. frames[key].frame.w,
  545. frames[key].frame.h,
  546. key,
  547. uuid
  548. ));
  549. PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[cacheKey], {
  550. x: frames[key].frame.x,
  551. y: frames[key].frame.y,
  552. width: frames[key].frame.w,
  553. height: frames[key].frame.h
  554. });
  555. if (frames[key].trimmed)
  556. {
  557. newFrame.setTrim(
  558. frames[key].trimmed,
  559. frames[key].sourceSize.w,
  560. frames[key].sourceSize.h,
  561. frames[key].spriteSourceSize.x,
  562. frames[key].spriteSourceSize.y,
  563. frames[key].spriteSourceSize.w,
  564. frames[key].spriteSourceSize.h
  565. );
  566. PIXI.TextureCache[uuid].trim = new Phaser.Rectangle(frames[key].spriteSourceSize.x, frames[key].spriteSourceSize.y, frames[key].sourceSize.w, frames[key].sourceSize.h);
  567. }
  568. i++;
  569. }
  570. return data;
  571. },
  572. /**
  573. * Parse the XML data and extract the animation frame data from it.
  574. *
  575. * @method Phaser.AnimationParser.XMLData
  576. * @param {Phaser.Game} game - A reference to the currently running game.
  577. * @param {Object} xml - The XML data from the Texture Atlas. Must be in Starling XML format.
  578. * @param {string} cacheKey - The Game.Cache asset key of the texture image.
  579. * @return {Phaser.FrameData} A FrameData object containing the parsed frames.
  580. */
  581. XMLData: function (game, xml, cacheKey) {
  582. // Malformed?
  583. if (!xml.getElementsByTagName('TextureAtlas'))
  584. {
  585. console.warn("Phaser.AnimationParser.XMLData: Invalid Texture Atlas XML given, missing &lt;TextureAtlas> tag");
  586. return;
  587. }
  588. // Let's create some frames then
  589. var data = new Phaser.FrameData();
  590. var frames = xml.getElementsByTagName('SubTexture');
  591. var newFrame;
  592. var uuid;
  593. var name;
  594. var frame;
  595. var x;
  596. var y;
  597. var width;
  598. var height;
  599. var frameX;
  600. var frameY;
  601. var frameWidth;
  602. var frameHeight;
  603. for (var i = 0; i &lt; frames.length; i++)
  604. {
  605. uuid = game.rnd.uuid();
  606. frame = frames[i].attributes;
  607. name = frame.name.nodeValue;
  608. x = parseInt(frame.x.nodeValue, 10);
  609. y = parseInt(frame.y.nodeValue, 10);
  610. width = parseInt(frame.width.nodeValue, 10);
  611. height = parseInt(frame.height.nodeValue, 10);
  612. frameX = null;
  613. frameY = null;
  614. if (frame.frameX)
  615. {
  616. frameX = Math.abs(parseInt(frame.frameX.nodeValue, 10));
  617. frameY = Math.abs(parseInt(frame.frameY.nodeValue, 10));
  618. frameWidth = parseInt(frame.frameWidth.nodeValue, 10);
  619. frameHeight = parseInt(frame.frameHeight.nodeValue, 10);
  620. }
  621. newFrame = data.addFrame(new Phaser.Frame(i, x, y, width, height, name, uuid));
  622. PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[cacheKey], {
  623. x: x,
  624. y: y,
  625. width: width,
  626. height: height
  627. });
  628. // Trimmed?
  629. if (frameX !== null || frameY !== null)
  630. {
  631. newFrame.setTrim(true, width, height, frameX, frameY, frameWidth, frameHeight);
  632. PIXI.TextureCache[uuid].trim = new Phaser.Rectangle(frameX, frameY, width, height);
  633. }
  634. }
  635. return data;
  636. }
  637. };
  638. </pre>
  639. </article>
  640. </section>
  641. </div>
  642. <div class="clearfix"></div>
  643. <footer>
  644. <span class="copyright">
  645. Phaser Copyright © 2012-2014 Photon Storm Ltd.
  646. </span>
  647. <br />
  648. <span class="jsdoc-message">
  649. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-dev</a>
  650. on Fri Apr 11 2014 13:25:02 GMT+0100 (BST) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
  651. </span>
  652. </footer>
  653. </div>
  654. <br clear="both">
  655. </div>
  656. </div>
  657. <script src="scripts/sunlight.js"></script>
  658. <script src="scripts/sunlight.javascript.js"></script>
  659. <script src="scripts/sunlight-plugin.doclinks.js"></script>
  660. <script src="scripts/sunlight-plugin.linenumbers.js"></script>
  661. <script src="scripts/sunlight-plugin.menu.js"></script>
  662. <script src="scripts/jquery.min.js"></script>
  663. <script src="scripts/jquery.scrollTo.js"></script>
  664. <script src="scripts/jquery.localScroll.js"></script>
  665. <script src="scripts/bootstrap-dropdown.js"></script>
  666. <script src="scripts/toc.js"></script>
  667. <script> Sunlight.highlightAll({lineNumbers:true, showMenu: true, enableDoclinks :true}); </script>
  668. <script>
  669. $( function () {
  670. $( "#toc" ).toc( {
  671. anchorName : function(i, heading, prefix) {
  672. return $(heading).attr("id") || ( prefix + i );
  673. },
  674. selectors : "h1,h2,h3,h4",
  675. showAndHide : false,
  676. scrollTo : 60
  677. } );
  678. $( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
  679. $( "#main span[id^='toc']" ).addClass( "toc-shim" );
  680. } );
  681. </script>
  682. </body>
  683. </html>