You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

core.js 86 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304
  1. "use strict";
  2. var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. /*
  5. Hexi
  6. ====
  7. Welcome to Hexi's source code!
  8. This file, `core.js` is the glue that holds Hexi together. Most of Hexi's functionality comes
  9. from some external libraries, written for Hexi, that `core.js` instantiates and wires
  10. together. Here are the external libraries that Hexi is currently using:
  11. - [Pixi](https://github.com/pixijs/pixi.js/): The world's fastest 2D WebGL and canvas renderer.
  12. - [Bump](https://github.com/kittykatattack/bump): A complete suite of 2D collision functions for games.
  13. - [Tink](https://github.com/kittykatattack/tink): Drag-and-drop, buttons, a universal pointer and other
  14. helpful interactivity tools.
  15. - [Charm](https://github.com/kittykatattack/charm): Easy-to-use tweening animation effects for Pixi sprites.
  16. - [Dust](https://github.com/kittykatattack/dust): Particle effects for creating things like explosions, fire
  17. and magic.
  18. - [Sprite Utilities](https://github.com/kittykatattack/spriteUtilities): Easier and more intuitive ways to
  19. create and use Pixi sprites, as well adding a state machine and animation player
  20. - [Game Utilities](https://github.com/kittykatattack/gameUtilities): A collection of useful methods for games.
  21. - [Tile Utilities](https://github.com/kittykatattack/tileUtilities): A collection of useful methods for making tile-based game worlds with [Tiled Editor](http://www.mapeditor.org).
  22. - [Sound.js](https://github.com/kittykatattack/sound.js): A micro-library for loading, controlling and generating
  23. sound and music effects. Everything you need to add sound to games.
  24. - [fullScreen.js](https://github.com/kittykatattack/fullScreen): Adds an easy-to-implement full screen feature.
  25. - [Smoothie](https://github.com/kittykatattack/smoothie): Ultra-smooth sprite animation using
  26. true delta-time interpolation. It also lets you specify the fps (frames-per-second) at which
  27. your game or application runs, and completely separates your sprite rendering loop from your
  28. application logic loop.
  29. The job of `core.js` (this file!) is to instantiate Hexi, load the assets, start the game loop, and
  30. create top-level access to most of the properties and methods in the external libraries.
  31. It also customizes some of those methods and runs them with some useful side-effects, such as
  32. automatically adding sprites to Hexi's `stage`. (Hexi's `stage` is the root Pixi `Container` for the display list.)
  33. I've divided this `core.js` file into "Chapters" which describes what each major section of code does.
  34. You'll find a "Table of Contents" ahead, which is your guide to this file.
  35. All this code is fully commented, but if there's something you don't understand, please ask
  36. in this repository's Issues and we will do our best to help. All this code is in one single file for now, just for the sake of simplicity,
  37. until the total scope of this project stabilizes.
  38. Hexi's build system
  39. -------------------
  40. All of Hexi's source code is written in JavaScript ES6, transpiled to ES5 using Babel, and minified using Uglify2.
  41. Make is currently being used as the build
  42. system. So, to build Hexi, make sure you have Node, Babel and Uglify2 installed, and call `make` in the
  43. command line from Hexi's root directory. Make will compile the `core.js` file, concatenate all files (including
  44. the modules) and produce the `hexi.min.js` file using Uglify2.
  45. You can also use Make to build individual sections of Hexi's code base.
  46. If you just want to watch and compile the core.js file from ES6 to ES5, run:
  47. make watchSrc
  48. If you want to concatenate all the modules, run:
  49. make concatModules
  50. If you want to concatenate all the files, run:
  51. make concatAllFiles
  52. To watch and compile the example files from ES6 to ES5, run:
  53. make watchExamples
  54. To watch and compile the tutorial files from ES6 to ES5, run:
  55. make watchTutorials
  56. If anyone reading this wishes to contribute a simpler, more automated system using Grunt of Gulp,
  57. we would welcome the contribution!
  58. Table of Contents
  59. -----------------
  60. Here's your handy guide to this `core.js` file.
  61. 1. Setup and instantiation.
  62. 2. The `Hexi` class constructor.
  63. 3. Hexi's engine: `start`, `load` and `update` methods.
  64. 4. Module interfaces: Hexi's top-level access to the module properties and methods.
  65. 5. Sprite creation methods: `sprite`, `tilingSprite`, `text`, `bitmapText`, `rectangle`, `circle`, `line`, `button`.
  66. 6. Display utilities: `group`, `batch`, `grid`, `makeTiledWorld`, `remove`, `flowRight`, `flowDown`, `flowLeft`, `flowUp`.
  67. 7. Sprite properties: Hexi's custom sprite properties (also known as super-powers!).
  68. 8. Utilities: `scaleToWindow`, `log`, `makeProgressBar`, `loadingBar`, `compensateForStageSize`, `image`, `id`, `json`, `xml`, `sound`
  69. */
  70. //1. SETUP AND INSTANTIATION
  71. //---------------------------
  72. //IMPORTANT: Make sure to load Pixi and the modules before instantiating Hexi!
  73. //The high level `hexi` function lets you quickly create an instance
  74. //of Hexi using sensible defaults.
  75. function hexi(width, height, setup) {
  76. var thingsToLoad = arguments.length <= 3 || arguments[3] === undefined ? undefined : arguments[3];
  77. var load = arguments.length <= 4 || arguments[4] === undefined ? undefined : arguments[4];
  78. //If you need to, you can also instantiate Hexi with a configuration
  79. //object, which lets you fine-tune the options.
  80. var hexi = new Hexi({
  81. //Required options:
  82. width: width, //Width, in pixels
  83. height: height, //Height, in pixels
  84. setup: setup, //Function to run when Hexi starts
  85. //Optional options:
  86. assets: thingsToLoad, //Array of assets that should be loaded
  87. load: load, //Function to run while Hexi is loading asssets
  88. /*
  89. renderer: "auto", //"auto", "canvas" or "webgl"
  90. backgroundColor: 0xCCCCCC, //Hexadecimal color code
  91. border: "1px dashed black", //CSS border string
  92. scaleToWindow: true, //Boolean
  93. scaleBorderColor: "gray", //Color string
  94. fps: 30, //The frames per second the logic loop should run at
  95. //An an object of Boolean (true/false) properties that describe which sprite
  96. //properties should be smoothly animated. These can be any of 5
  97. //properties: `position`, `rotation`, `size`, `scale` or `alpha`.
  98. //(Position and rotation are on by default, unless you set Hexi's
  99. //`interpolate` property to `false`)
  100. */
  101. interpolationProperties: {
  102. position: true,
  103. rotation: true,
  104. size: true,
  105. alpha: true
  106. },
  107. interpolate: true
  108. });
  109. //To change PIXI's renderer, set the `renderer` option to
  110. //"auto", "canvas" or "webgl", like this:
  111. //renderer: "auto"
  112. //Add any other Pixi initialization options you need, depending
  113. //on which Pixi renderer you're using
  114. return hexi;
  115. }
  116. //The Hexi main class. It contains all of Hexi's properties and
  117. //methods, and sets up bindings between Hexi and the module libraries.
  118. //If you need more find control over Hexi's initialization options,
  119. //you can create a new instance of the Hexi class directly in your application
  120. //code. See how it's done in the `hexi` function above for a good example
  121. //of how to do that.
  122. //2. THE HEXI CLASS CONSTRUCTOR
  123. //----------------------------
  124. var Hexi = (function () {
  125. /*
  126. Initialize Hexi's constructor with an options object literal called `o`.
  127. Here are the required options:
  128. `width`: Value in pixels that describes the canvas's width
  129. `height`: Value in pixels that describes the canvas's height
  130. `setup`: A function that should run as soon as Hexi is initialized
  131. Here are the optional options:
  132. `assets`: Array of assets (files) that should be loaded
  133. `load`: A function that should run while Hexi is loading assets
  134. `renderer`: The type of renderer to use: "auto" (the default), "canvas" or "webgl"
  135. `backgroundColor`: Hexadecimal color code that defines the canvas color
  136. `border`: The canvas border style as a CSS border string, such as "1px dashed black"
  137. `scaleToWindow`: A Boolean that determines whether the canvas should scale to maximum window size.
  138. `scaleBorderColor`: Color string that defines the color of the border around a scaled canvas.
  139. `interpolationProperties: An object that defines 5 Boolean properties that determines which sprite properties are interpolated
  140. (smoothly animated) by Hexi's rendering engine (Smoothie): `position`, `size`, `rotation`, `scale` or `alpha`
  141. `interpolate`: A Boolean which should be `false` if you *don't* want any sprite animation smoothing.
  142. `fps`: The frames-per-second the engine's game logic loop should run at (the default is 60).
  143. `renderFps`: Clamps the fps rendering to the supplied frame rate.
  144. You can also add any of Pixi's initialization options, and those will be applied
  145. to Pixi's renderer when Hexi creates it.
  146. */
  147. function Hexi(o) {
  148. _classCallCheck(this, Hexi);
  149. //Initialize all the helper modules.
  150. //(See Hexi's README.md on information about these libraries)
  151. this.charm = new Charm(PIXI);
  152. this.dust = new Dust(PIXI);
  153. this.bump = new Bump(PIXI);
  154. this.spriteUtilities = new SpriteUtilities(PIXI);
  155. this.tileUtilities = new TileUtilities(PIXI);
  156. this.gameUtilities = new GameUtilities();
  157. //Any modules that have an `update` method that should updated
  158. //each frame in the game loop should be added to the
  159. //`modulesToUpdate` array. The game loop will call the `update`
  160. //method on each of these modules while the game is running.
  161. //This is very efficient and does not effect performance: no modules are updated unless they
  162. //contain objects that need updating.
  163. this.modulesToUpdate = [];
  164. this.modulesToUpdate.push(this.charm);
  165. this.modulesToUpdate.push(this.dust);
  166. this.modulesToUpdate.push(this.spriteUtilities);
  167. //Create the stage and renderer
  168. //Auto renderer (default)
  169. if (o.renderer === "auto" || o.renderer === undefined) {
  170. this.renderer = PIXI.autoDetectRenderer(o.width, o.height, o, o.noWebGL);
  171. //Canvas renderer
  172. } else if (o.renderer === "canvas") {
  173. this.renderer = new PIXI.CanvasRenderer(o.width, o.height, o);
  174. //WebGL renderer
  175. } else if (o.renderer === "webgl") {
  176. this.renderer = new PIXI.WebGLRenderer(o.width, o.height, o);
  177. }
  178. //Get a reference to the `renderer.view`, which is the
  179. //HTML canvas element
  180. this.canvas = this.renderer.view;
  181. //Initialize the Tink interactive module (it needs a reference to the canvas)
  182. this.tink = new Tink(PIXI, this.canvas);
  183. this.modulesToUpdate.push(this.tink);
  184. //Create local aliases for the important methods and properties of
  185. //these libraries, including the most useful Pixi properties.
  186. //Take a look at Hexi's `createModulePropertyAliases` method in the
  187. //source code ahead to see how this works
  188. this.createModulePropertyAliases();
  189. //Add `halfWidth` and `halfHeight` properties to the canvas
  190. Object.defineProperties.bind(this, this.canvas, {
  191. "halfWidth": {
  192. get: function get() {
  193. return this.canvas.width / 2;
  194. },
  195. enumerable: true,
  196. configurable: true
  197. },
  198. "halfHeight": {
  199. get: function get() {
  200. return this.canvas.height / 2;
  201. },
  202. enumerable: true,
  203. configurable: true
  204. }
  205. });
  206. //A Boolean to flag whether the canvas has been scaled
  207. this.canvas.scaled = false;
  208. //Add the FullScreen module and supply it with the canvas element
  209. //this.fullScreen = new FullScreen(this.canvas);
  210. //Note: Hexi's `update` function checks whether we're in full screen
  211. //mode and updates the global scale value accordingly
  212. //Set the canvas's optional background color and border style
  213. if (o.backgroundColor) {
  214. this.renderer.backgroundColor = this.color(o.backgroundColor);
  215. } else {
  216. this.renderer.backgroundColor = 0xFFFFFF;
  217. }
  218. if (o.border) this.canvas.style.border = o.border;
  219. //Add the canvas to the HTML document
  220. document.body.appendChild(this.canvas);
  221. //Create a container object called the `stage`
  222. this.stage = new this.Container();
  223. //Add Hexi's special sprite properties to the stage
  224. this.addProperties(this.stage);
  225. this.stage._stage = true;
  226. //The game's scale
  227. if (o.scaleToWindow) {
  228. this.scaleToWindow(o.scaleBorderColor);
  229. } else {
  230. this.scale = 1;
  231. }
  232. //Make the pointer
  233. this.pointer = this.makePointer(this.canvas, this.scale);
  234. //Set the game `state`
  235. this.state = undefined;
  236. //Set the user-defined `load` and `setup` states
  237. if (o.load !== undefined) this.loadState = o.load;
  238. //The `setup` function is required, so throw an error if it's
  239. //missing
  240. if (!o.setup) {
  241. throw new Error("Please supply the setup option in the constructor to tell Hexi which function should run first when it starts.");
  242. } else {
  243. this.setupState = o.setup;
  244. }
  245. //A variable to track the current percentage of loading assets
  246. this.loadingProgress = 0;
  247. //A variable to track the currently loading asset
  248. this.loadingFile = "";
  249. //Load any assets if they've been provided
  250. if (o.assets !== undefined) {
  251. this.assetsToLoad = o.assets;
  252. }
  253. //Tell Hexi that we're not using a loading progress bar.
  254. //(This will be set to `true` if the user invokes the `loadingBar`
  255. //function, which you'll see ahead)
  256. this._progressBarAdded = false;
  257. //The `soundObjects` object is used to store all sounds
  258. this.soundObjects = {};
  259. //Create a new instance of Smoothie, which manages Hexi's game
  260. //loop and adds smooth sprite interpolation
  261. this.smoothie = new Smoothie({
  262. engine: PIXI,
  263. renderer: this.renderer,
  264. root: this.stage,
  265. update: this.update.bind(this),
  266. properties: o.interpolationProperties,
  267. interpolate: o.interpolate,
  268. fps: o.fps,
  269. renderFps: o.renderFps,
  270. properties: {
  271. position: true,
  272. scale: true,
  273. tile: true
  274. }
  275. });
  276. }
  277. //3. HEXI'S ENGINE: START, LOAD AND SETUP
  278. //---------------------------------------
  279. //The `start` method must be called by the user after Hexi has been
  280. //initialized to start the loading process and turn on the engine.
  281. _createClass(Hexi, [{
  282. key: "start",
  283. value: function start() {
  284. //If there are assets to load, load them, and set the game's state
  285. //to the user-defined `loadState` (which can be supplied by the user in the
  286. //constructor)
  287. if (this.assetsToLoad) {
  288. //Call Hexi's `load` method (ahead) to load the assets
  289. this.load(this.assetsToLoad, this.validateAssets);
  290. //After the assets have been loaded, a method called
  291. //`validateAssets` will run (see `validateAssets` ahead.)
  292. //`validateAssets` checks to see what has been loaded and,
  293. //in the case of sound files, decodes them and creates sound
  294. //objects.
  295. //If the user has supplied Hexi with a `load` function (in
  296. //Hexi's constructor), it will be assigned to Hexi's current
  297. //`state` and, as you'll see ahead, called in a loop while the
  298. //assets load
  299. if (this.loadState) this.state = this.loadState;
  300. } else {
  301. //If there's nothing to load, run the `setup` state, which will
  302. //just run once
  303. this.setupState();
  304. }
  305. //Start the game loop
  306. this.smoothie.start();
  307. }
  308. //Use the `load` method to load any files into Hexi. Pass it a
  309. //callback function as the second argument to launch a function that
  310. //should run when all the assets have finished loading. Hexi's
  311. //default callback function is `validateAssets`, which you'll find
  312. //in the code ahead
  313. }, {
  314. key: "load",
  315. value: function load(assetsToLoad) {
  316. var _this = this;
  317. var callbackFunction = arguments.length <= 1 || arguments[1] === undefined ? undefined : arguments[1];
  318. //Handle special file types that Pixi's loader doesn't understand
  319. //The `findAssets` function will return an array to get an array just
  320. //containing those file source paths you're interested in
  321. var findAssets = function findAssets(fileExtensionArray) {
  322. var fileSourcePaths = assetsToLoad.filter(function (source) {
  323. //Find the file extension of the asset
  324. var extension = source.split(".").pop();
  325. if (fileExtensionArray.indexOf(extension) !== -1) {
  326. return true;
  327. }
  328. });
  329. return fileSourcePaths;
  330. };
  331. /* Load fonts */
  332. //First, define the file extensions for the special file types
  333. //you're interested in
  334. //Fonts
  335. var fontExtensions = ["ttf", "otf", "ttc", "woff"];
  336. //Get the font source paths
  337. var fontFiles = findAssets(fontExtensions);
  338. //If there are any font files, load them into the browser using an
  339. //old trick that forces the browser to load them
  340. if (fontFiles.length > 0) {
  341. this.spanElements = [];
  342. fontFiles.forEach(function (source) {
  343. //Loads the font files by writing CSS code to the HTML document head.
  344. //Use the font's filename as the `fontFamily` name. This code captures
  345. //the font file's name without the extension or file path
  346. var fontFamily = source.split("/").pop().split(".")[0];
  347. //Push the font family name into Hexi's `fontFamilies` array
  348. if (_this.fontFamilies) _this.fontFamilies.push(fontFamily);
  349. //Append an `@afont-face` style rule to the head of the HTML document
  350. var newStyle = document.createElement("style");
  351. var fontFace = "@font-face {font-family: '" + fontFamily + "'; src: url('" + source + "');}";
  352. newStyle.appendChild(document.createTextNode(fontFace));
  353. document.head.appendChild(newStyle);
  354. //Trick the browser into loading the font file by
  355. //displaying an invisible element
  356. var span = document.createElement("span");
  357. span.style.fontFamily = fontFamily;
  358. document.body.appendChild(span);
  359. span.innerHTML = "?";
  360. span.style.display = "block";
  361. span.style.opacity = "0";
  362. _this.spanElements.push(span);
  363. });
  364. }
  365. /* Load sound */
  366. //Set default loading mechanism for sound file extensions to use XHR
  367. var Resource = PIXI.loaders.Resource;
  368. Resource.setExtensionLoadType("wav", Resource.LOAD_TYPE.XHR);
  369. Resource.setExtensionLoadType("mp3", Resource.LOAD_TYPE.XHR);
  370. Resource.setExtensionLoadType("ogg", Resource.LOAD_TYPE.XHR);
  371. Resource.setExtensionLoadType("webm", Resource.LOAD_TYPE.XHR);
  372. //Set default loading type for sound file extensions to be arraybuffer
  373. Resource.setExtensionXhrType("wav", Resource.XHR_RESPONSE_TYPE.BUFFER);
  374. Resource.setExtensionXhrType("mp3", Resource.XHR_RESPONSE_TYPE.BUFFER);
  375. Resource.setExtensionXhrType("ogg", Resource.XHR_RESPONSE_TYPE.BUFFER);
  376. Resource.setExtensionXhrType("webm", Resource.XHR_RESPONSE_TYPE.BUFFER);
  377. /* Load ordinary assets */
  378. var loadProgressHandler = function loadProgressHandler(loader, resource) {
  379. //Display the file `url` currently being loaded
  380. _this.loadingFile = resource.url;
  381. //Display the percentage of files currently loaded
  382. _this.loadingProgress = loader.progress;
  383. };
  384. //Load the files and call the `loadProgressHandler` while they're
  385. //loading
  386. this.loader.reset();
  387. this.loadingProgress = 0;
  388. this.loadingFile = "";
  389. this.loader.add(assetsToLoad).on("progress", loadProgressHandler).load(callbackFunction.bind(this));
  390. }
  391. //The `validateAssets` method runs when all the assets have finished
  392. //loading. It checks to see if there are any sounds files and, if
  393. //there are, decodes them and turns them into sound objects using the
  394. //`sounds.js` module's `makeSound` function. If there are no sounds
  395. //to load, the loading state is finished and the setup state is run.
  396. //But, if there are sounds to load, the setup state will only run
  397. //after the sounds have been decoded.
  398. }, {
  399. key: "validateAssets",
  400. value: function validateAssets() {
  401. var _this2 = this;
  402. console.log("All assets loaded");
  403. //The `finishLoadingState` method will be called if everything has
  404. //finished loading and any possible sounds have been decoded
  405. var finishLoadingState = function finishLoadingState() {
  406. //Reset the `assetsToLoad` array
  407. _this2.assetsToLoad = [];
  408. //Clear the `loadState`
  409. _this2.loadState = undefined;
  410. //Clear the game `state` function for now to stop the loop.
  411. _this2.state = undefined;
  412. //Remove the loading progress bar if the user invoked the `loadingBar`
  413. //function
  414. if (_this2._progressBarAdded) {
  415. _this2.progressBar.remove();
  416. }
  417. //If any fonts were tricked into loading
  418. //make the <span> tags that use them invisible
  419. if (_this2.spanElements) {
  420. _this2.spanElements.forEach(function (element) {
  421. element.style.display = "none";
  422. });
  423. }
  424. //Call the `setup` state
  425. _this2.setupState();
  426. };
  427. //We need to check if any possible sound file have been loaded
  428. //because, if there have, they need to fist be decoded before we
  429. //can launch the `setup` state.
  430. //Variables to count the number of sound files and the sound files
  431. //that have been decoded. If both these numbers are the same at
  432. //some point, then we know all the sounds have been decoded and we
  433. //can call the `finishLoadingState` function
  434. var soundsToDecode = 0,
  435. soundsDecoded = 0;
  436. //First, create a list of the kind of sound files we want to check
  437. var soundExtensions = ["wav", "mp3", "ogg", "webm"];
  438. //The `decodeHandler` will run when each sound file is decoded
  439. var decodeHandler = function decodeHandler() {
  440. //Count 1 more sound as having been decoded
  441. soundsDecoded += 1;
  442. //If the decoded sounds match the number of sounds to decode,
  443. //then we know all the sounds have been decoded and we can call
  444. //`finishLoadingState`
  445. if (soundsToDecode === soundsDecoded) {
  446. finishLoadingState();
  447. }
  448. };
  449. //Loop through all the loader's resources and look for sound files
  450. Object.keys(this.loader.resources).forEach(function (resource) {
  451. //Find the file extension of the asset
  452. var extension = resource.split(".").pop();
  453. //If one of the resource file extensions matches the sound file
  454. //extensions, then we know we have a sound file
  455. if (soundExtensions.indexOf(extension) !== -1) {
  456. //Count one more sound to load
  457. soundsToDecode += 1;
  458. //Create aliases for the sound's `xhr` object and `url` (its
  459. //file name)
  460. var xhr = _this2.loader.resources[resource].xhr,
  461. url = _this2.loader.resources[resource].url;
  462. //Create a sound sprite using the `sound.js` module's
  463. //`makeSound` function. Notice the 4th argument is the loaded
  464. //sound's `xhr` object. Setting the 3rd argument to `false`
  465. //means that `makeSound` won't attempt to load the sounds
  466. //again. When the sound has been decoded, the `decodeHandler`
  467. //(see above!) will be run
  468. var soundSprite = makeSound(url, decodeHandler.bind(_this2), false, xhr);
  469. //Get the sound file name.
  470. soundSprite.name = _this2.loader.resources[resource].name;
  471. //Add the sound object to Hexi's `soundObjects` object.
  472. //You'll be able to access them in your application through
  473. //Hexi's higher-level `sound` method, like this:
  474. //`hexi.sound("soundFileName.wav");`
  475. _this2.soundObjects[soundSprite.name] = soundSprite;
  476. }
  477. });
  478. //If there are no sound files, we can skip the decoding step and
  479. //just call `finishLoadingState` directly
  480. if (soundsToDecode === 0) {
  481. finishLoadingState();
  482. }
  483. }
  484. //The `update` method is run by Hexi's game loop each frame.
  485. //It manages the game state and updates the modules
  486. }, {
  487. key: "update",
  488. value: function update() {
  489. //Update all the modules in the `modulesToUpdate` array.
  490. //These are modules that contain `update` methods that need to be
  491. //called every frame
  492. this.modulesToUpdate.forEach(function (module) {
  493. return module.update();
  494. });
  495. //If the application is in full screen mode, make sure that Hexi
  496. //is using the correct scale value
  497. /*
  498. if (document.fullscreenEnabled === true) {
  499. console.log("fullscreenEnabled")
  500. //Note: Check Firefox's current FullScreen API and specifically:
  501. //https://github.com/neovov/Fullscreen-API-Polyfill/blob/master/fullscreen-api-polyfill.js
  502. //if (this.fullScreen.fullscreenScale !== 1) {
  503. this.scale = this.fullScreen.fullscreenScale;
  504. //console.log("this.fullScreen.fullscreenScale: " + this.fullScreen.fullscreenScale)
  505. this.pointer.scale = this.scale;
  506. //Find out if the pointer scale is propagating to Tink's pointer?
  507. console.log(this.pointer.scale)
  508. } else {
  509. if (!this.canvas.scaled) {
  510. this.scale = 1;
  511. this.pointer.scale = 1;
  512. }
  513. }
  514. */
  515. //Run the current game `state` function if it's been defined and
  516. //the game isn't `paused`
  517. if (this.state && !this.paused) {
  518. this.state();
  519. }
  520. }
  521. //Pause and resume methods
  522. }, {
  523. key: "pause",
  524. value: function pause() {
  525. this.paused = true;
  526. }
  527. }, {
  528. key: "resume",
  529. value: function resume() {
  530. this.paused = false;
  531. }
  532. //4. MODULE INTERFACES
  533. //A method that helpfully creates local, top-level references to the
  534. //most useful properties and methods from the loaded modules
  535. }, {
  536. key: "createModulePropertyAliases",
  537. value: function createModulePropertyAliases() {
  538. var _this3 = this;
  539. //Pixi - Rendering
  540. this.Container = PIXI.Container;
  541. this.loader = PIXI.loader;
  542. this.TextureCache = PIXI.utils.TextureCache;
  543. this.filters = PIXI.filters;
  544. //Filters
  545. this.dropShadowFilter = function () {
  546. return new _this3.filters.DropShadowFilter();
  547. };
  548. this.asciiFilter = function () {
  549. return new _this3.filters.AsciiFilter();
  550. };
  551. this.alphaMaskFilter = function () {
  552. return new _this3.filters.AlphaMaskFilter();
  553. };
  554. this.bloomFilter = function () {
  555. return new _this3.filters.BloomFilter();
  556. };
  557. this.blurDirFilter = function () {
  558. return new _this3.filters.BlurDirFilter();
  559. };
  560. this.blurFilter = function () {
  561. return new _this3.filters.BlurFilter();
  562. };
  563. this.colorMatrixFilter = function () {
  564. return new _this3.filters.ColorMatrixFilter();
  565. };
  566. this.colorStepFilter = function () {
  567. return new _this3.filters.ColorStepFilter();
  568. };
  569. this.crossHatchFilter = function () {
  570. return new _this3.filters.CrossHatchFilter();
  571. };
  572. this.displacementFilter = function () {
  573. return new _this3.filters.DisplacementFilter();
  574. };
  575. this.dotScreenFilter = function () {
  576. return new _this3.filters.DotScreenFilter();
  577. };
  578. this.grayFilter = function () {
  579. return new _this3.filters.GrayFilter();
  580. };
  581. this.invertFilter = function () {
  582. return new _this3.filters.InvertFilter();
  583. };
  584. this.pixelateFilter = function () {
  585. return new _this3.filters.PixelateFilter();
  586. };
  587. this.sepiaFilter = function () {
  588. return new _this3.filters.SepiaFilter();
  589. };
  590. this.shockwaveFilter = function () {
  591. return new _this3.filters.ShockwaveFilter();
  592. };
  593. this.twistFilter = function () {
  594. return new _this3.filters.TwistFilter();
  595. };
  596. this.rgbSplitFilter = function () {
  597. return new _this3.filters.RGBSplitFilter();
  598. };
  599. this.smartBlurFilter = function () {
  600. return new _this3.filters.SmartBlurFilter();
  601. };
  602. this.tiltShiftFilter = function () {
  603. return new _this3.filters.TiltShiftFilter();
  604. };
  605. //Tink - Interactivity
  606. this.draggableSprites = this.tink.draggableSprites;
  607. this.pointers = this.tink.pointers;
  608. this.buttons = this.tink.buttons;
  609. this.makePointer = function (canvas, scale) {
  610. return _this3.tink.makePointer(canvas, scale);
  611. };
  612. this.makeDraggable = function () {
  613. var _tink;
  614. return (_tink = _this3.tink).makeDraggable.apply(_tink, arguments);
  615. };
  616. this.makeUndraggable = function () {
  617. var _tink2;
  618. return (_tink2 = _this3.tink).makeUndraggable.apply(_tink2, arguments);
  619. };
  620. this.makeInteractive = function (o) {
  621. return _this3.tink.makeInteractive(o);
  622. };
  623. this.keyboard = this.tink.keyboard;
  624. this.arrowControl = function (sprite, speed) {
  625. return _this3.tink.arrowControl(sprite, speed);
  626. };
  627. //Add the arrow key objects
  628. /*
  629. this.upArrow = this.keyboard(38);
  630. this.rightArrow = this.keyboard(39);
  631. this.downArrow = this.keyboard(40);
  632. this.leftArrow = this.keyboard(37);
  633. this.spaceBar = this.keyboard(32);
  634. */
  635. //Dust - Particle effects
  636. this.createParticles = function (x, y, spriteFunction, container, numberOfParticles, gravity, randomSpacing, minAngle, maxAngle, minSize, maxSize, minSpeed, maxSpeed, minScaleSpeed, maxScaleSpeed, minAlphaSpeed, maxAlphaSpeed, minRotationSpeed, maxRotationSpeed) {
  637. return _this3.dust.create(x, y, spriteFunction, container, numberOfParticles, gravity, randomSpacing, minAngle, maxAngle, minSize, maxSize, minSpeed, maxSpeed, minScaleSpeed, maxScaleSpeed, minAlphaSpeed, maxAlphaSpeed, minRotationSpeed, maxRotationSpeed);
  638. };
  639. this.particleEmitter = function (interval, particleFunction) {
  640. return _this3.dust.emitter(interval, particleFunction);
  641. };
  642. //SpriteUtilities - Sprite creation tools
  643. this.filmstrip = function (texture, frameWidth, frameHeight, spacing) {
  644. return _this3.spriteUtilities.filmstrip(texture, frameWidth, frameHeight, spacing);
  645. };
  646. this.frame = function (source, x, y, width, height) {
  647. return _this3.spriteUtilities.frame(source, x, y, width, height);
  648. };
  649. this.frames = function (source, coordinates, frameWidth, frameHeight) {
  650. return _this3.spriteUtilities.frames(source, coordinates, frameWidth, frameHeight);
  651. };
  652. this.frameSeries = function (startNumber, endNumber, baseName, extension) {
  653. return _this3.spriteUtilities.frames(startNumber, endNumber, baseName, extension);
  654. };
  655. this.colorToRGBA = function (value) {
  656. return _this3.spriteUtilities.colorToRGBA(value);
  657. };
  658. this.colorToHex = function (value) {
  659. return _this3.spriteUtilities.colorToHex(value);
  660. };
  661. this.byteToHex = function (value) {
  662. return _this3.spriteUtilities.byteToHex(value);
  663. };
  664. this.color = function (value) {
  665. return _this3.spriteUtilities.color(value);
  666. };
  667. this.shoot = function (shooter, angle, x, y, container, bulletSpeed, bulletArray, bulletSprite) {
  668. return _this3.spriteUtilities.shoot(shooter, angle, x, y, container, bulletSpeed, bulletArray, bulletSprite);
  669. };
  670. this.shake = function (sprite) {
  671. var magnitude = arguments.length <= 1 || arguments[1] === undefined ? 16 : arguments[1];
  672. var angular = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
  673. console.log("shake");
  674. return _this3.spriteUtilities.shake(sprite, magnitude, angular);
  675. };
  676. //Charm - Tweening
  677. this.fadeOut = function (sprite) {
  678. var frames = arguments.length <= 1 || arguments[1] === undefined ? 60 : arguments[1];
  679. return _this3.charm.fadeOut(sprite, frames);
  680. };
  681. this.fadeIn = function (sprite) {
  682. var frames = arguments.length <= 1 || arguments[1] === undefined ? 60 : arguments[1];
  683. return _this3.charm.fadeIn(sprite, frames);
  684. };
  685. this.pulse = function (sprite) {
  686. var frames = arguments.length <= 1 || arguments[1] === undefined ? 60 : arguments[1];
  687. var minAlpha = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
  688. return _this3.charm.pulse(sprite, frames, minAlpha);
  689. };
  690. this.slide = function (sprite, endX, endY) {
  691. var frames = arguments.length <= 3 || arguments[3] === undefined ? 60 : arguments[3];
  692. var type = arguments.length <= 4 || arguments[4] === undefined ? "smoothstep" : arguments[4];
  693. var yoyo = arguments.length <= 5 || arguments[5] === undefined ? false : arguments[5];
  694. var delayBeforeRepeat = arguments.length <= 6 || arguments[6] === undefined ? 0 : arguments[6];
  695. return _this3.charm.slide(sprite, endX, endY, frames, type, yoyo, delayBeforeRepeat = 0);
  696. };
  697. this.breathe = function (sprite) {
  698. var endScaleX = arguments.length <= 1 || arguments[1] === undefined ? 0.8 : arguments[1];
  699. var endScaleY = arguments.length <= 2 || arguments[2] === undefined ? 0.8 : arguments[2];
  700. var frames = arguments.length <= 3 || arguments[3] === undefined ? 60 : arguments[3];
  701. var yoyo = arguments.length <= 4 || arguments[4] === undefined ? true : arguments[4];
  702. var delayBeforeRepeat = arguments.length <= 5 || arguments[5] === undefined ? 0 : arguments[5];
  703. return _this3.charm.breathe(sprite, endScaleX, endScaleY, frames, yoyo, delayBeforeRepeat);
  704. };
  705. this.scale = function (sprite) {
  706. var endScaleX = arguments.length <= 1 || arguments[1] === undefined ? 0.5 : arguments[1];
  707. var endScaleY = arguments.length <= 2 || arguments[2] === undefined ? 0.5 : arguments[2];
  708. var frames = arguments.length <= 3 || arguments[3] === undefined ? 60 : arguments[3];
  709. return _this3.charm.scale(sprite, endScaleX, endScaleY, frames);
  710. };
  711. this.strobe = function (sprite) {
  712. var scaleFactor = arguments.length <= 1 || arguments[1] === undefined ? 1.3 : arguments[1];
  713. var startMagnitude = arguments.length <= 2 || arguments[2] === undefined ? 10 : arguments[2];
  714. var endMagnitude = arguments.length <= 3 || arguments[3] === undefined ? 20 : arguments[3];
  715. var frames = arguments.length <= 4 || arguments[4] === undefined ? 10 : arguments[4];
  716. var yoyo = arguments.length <= 5 || arguments[5] === undefined ? true : arguments[5];
  717. var delayBeforeRepeat = arguments.length <= 6 || arguments[6] === undefined ? 0 : arguments[6];
  718. return _this3.charm.strobe(sprite, scaleFactor, startMagnitude, endMagnitude, frames, yoyo, delayBeforeRepeat);
  719. };
  720. this.wobble = function (sprite) {
  721. var scaleFactorX = arguments.length <= 1 || arguments[1] === undefined ? 1.2 : arguments[1];
  722. var scaleFactorY = arguments.length <= 2 || arguments[2] === undefined ? 1.2 : arguments[2];
  723. var frames = arguments.length <= 3 || arguments[3] === undefined ? 10 : arguments[3];
  724. var xStartMagnitude = arguments.length <= 4 || arguments[4] === undefined ? 10 : arguments[4];
  725. var xEndMagnitude = arguments.length <= 5 || arguments[5] === undefined ? 10 : arguments[5];
  726. var yStartMagnitude = arguments.length <= 6 || arguments[6] === undefined ? -10 : arguments[6];
  727. var yEndMagnitude = arguments.length <= 7 || arguments[7] === undefined ? -10 : arguments[7];
  728. var friction = arguments.length <= 8 || arguments[8] === undefined ? 0.98 : arguments[8];
  729. var yoyo = arguments.length <= 9 || arguments[9] === undefined ? true : arguments[9];
  730. var delayBeforeRepeat = arguments.length <= 10 || arguments[10] === undefined ? 0 : arguments[10];
  731. return _this3.charm.wobble(sprite, scaleFactorX = 1.2, scaleFactorY = 1.2, frames = 10, xStartMagnitude = 10, xEndMagnitude = 10, yStartMagnitude = -10, yEndMagnitude = -10, friction = 0.98, yoyo = true, delayBeforeRepeat = 0);
  732. };
  733. this.followCurve = function (sprite, pointsArray, totalFrames) {
  734. var type = arguments.length <= 3 || arguments[3] === undefined ? "smoothstep" : arguments[3];
  735. var yoyo = arguments.length <= 4 || arguments[4] === undefined ? false : arguments[4];
  736. var delayBeforeRepeat = arguments.length <= 5 || arguments[5] === undefined ? 0 : arguments[5];
  737. return _this3.charm.followCurve(sprite, pointsArray, totalFrames, type, yoyo, delayBeforeRepeat);
  738. };
  739. this.walkPath = function (sprite, originalPathArray) {
  740. var totalFrames = arguments.length <= 2 || arguments[2] === undefined ? 300 : arguments[2];
  741. var type = arguments.length <= 3 || arguments[3] === undefined ? "smoothstep" : arguments[3];
  742. var loop = arguments.length <= 4 || arguments[4] === undefined ? false : arguments[4];
  743. var yoyo = arguments.length <= 5 || arguments[5] === undefined ? false : arguments[5];
  744. var delayBetweenSections = arguments.length <= 6 || arguments[6] === undefined ? 0 : arguments[6];
  745. return _this3.charm.walkPath(sprite, originalPathArray, totalFrames, type, loop, yoyo, delayBetweenSections);
  746. };
  747. this.walkCurve = function (sprite, pathArray) {
  748. var totalFrames = arguments.length <= 2 || arguments[2] === undefined ? 300 : arguments[2];
  749. var type = arguments.length <= 3 || arguments[3] === undefined ? "smoothstep" : arguments[3];
  750. var loop = arguments.length <= 4 || arguments[4] === undefined ? false : arguments[4];
  751. var yoyo = arguments.length <= 5 || arguments[5] === undefined ? false : arguments[5];
  752. var delayBeforeContinue = arguments.length <= 6 || arguments[6] === undefined ? 0 : arguments[6];
  753. return _this3.charm.walkCurve(sprite, pathArray, totalFrames, type, loop, yoyo, delayBeforeContinue);
  754. };
  755. this.removeTween = function (tweenObject) {
  756. return _this3.charm.removeTween(tweenObject);
  757. };
  758. this.makeTween = function (tweensToAdd) {
  759. return _this3.charm.makeTween(tweensToAdd);
  760. };
  761. this.tweenProperty = function (sprite, property, startValue, endValue, totalFrames) {
  762. var type = arguments.length <= 5 || arguments[5] === undefined ? "smoothstep" : arguments[5];
  763. var yoyo = arguments.length <= 6 || arguments[6] === undefined ? false : arguments[6];
  764. var delayBeforeRepeat = arguments.length <= 7 || arguments[7] === undefined ? 0 : arguments[7];
  765. return _this3.charm.tweenProperty(sprite, property, startValue, endValue, totalFrames, type, yoyo, delayBeforeRepeat);
  766. };
  767. //Bump - Collision
  768. this.hitTestPoint = function (point, sprite) {
  769. return _this3.bump.hitTestPoint(point, sprite);
  770. };
  771. this.hitTestCircle = function (c1, c2) {
  772. var global = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
  773. return _this3.bump.hitTestCircle(c1, c2, global);
  774. };
  775. this.circleCollision = function (c1, c2) {
  776. var bounce = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
  777. var global = arguments.length <= 3 || arguments[3] === undefined ? false : arguments[3];
  778. return _this3.bump.circleCollision(c1, c2, bounce, global);
  779. };
  780. this.movingCircleCollision = function (c1, c2) {
  781. var global = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
  782. return _this3.bump.movingCircleCollision(c1, c2, global);
  783. };
  784. this.multipleCircleCollision = function (arrayOfCircles) {
  785. var global = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
  786. return _this3.bump.multipleCircleCollision(arrayOfCircles, global);
  787. };
  788. this.rectangleCollision = function (r1, r2) {
  789. var bounce = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
  790. var global = arguments.length <= 3 || arguments[3] === undefined ? true : arguments[3];
  791. return _this3.bump.rectangleCollision(r1, r2, bounce, global);
  792. };
  793. this.hitTestRectangle = function (r1, r2) {
  794. var global = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
  795. return _this3.bump.hitTestRectangle(r1, r2, global);
  796. };
  797. this.hitTestCircleRectangle = function (c1, r1) {
  798. var global = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
  799. return _this3.bump.hitTestCircleRectangle(c1, r1, global);
  800. };
  801. this.hitTestCirclePoint = function (c1, point) {
  802. var global = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
  803. return _this3.bump.hitTestCirclePoint(c1, point, global);
  804. };
  805. this.circleRectangleCollision = function (c1, r1) {
  806. var bounce = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
  807. var global = arguments.length <= 3 || arguments[3] === undefined ? false : arguments[3];
  808. return _this3.bump.circleRectangleCollision(c1, r1, bounce, global);
  809. };
  810. this.circlePointCollision = function (c1, point) {
  811. var bounce = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
  812. var global = arguments.length <= 3 || arguments[3] === undefined ? false : arguments[3];
  813. return _this3.bump.circlePointCollision(c1, point, bounce, global);
  814. };
  815. this.bounceOffSurface = function (o, s) {
  816. return _this3.bump.bounceOffSurface(o, s);
  817. };
  818. this.hit = function (a, b) {
  819. var react = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
  820. var bounce = arguments.length <= 3 || arguments[3] === undefined ? false : arguments[3];
  821. var global = arguments[4];
  822. var extra = arguments.length <= 5 || arguments[5] === undefined ? undefined : arguments[5];
  823. return _this3.bump.hit(a, b, react, bounce, global, extra);
  824. };
  825. this.shortestPath = function (startIndex, destinationIndex, mapArray, mapWidthInTiles) {
  826. var obstacleGids = arguments.length <= 4 || arguments[4] === undefined ? [] : arguments[4];
  827. var heuristic = arguments.length <= 5 || arguments[5] === undefined ? "manhattan" : arguments[5];
  828. var useDiagonalNodes = arguments.length <= 6 || arguments[6] === undefined ? true : arguments[6];
  829. return _this3.tileUtilities.shortestPath(startIndex, destinationIndex, mapArray, mapWidthInTiles, obstacleGids, heuristic, useDiagonalNodes);
  830. };
  831. this.tileBasedLineOfSight = function (spriteOne, spriteTwo, mapArray, world) {
  832. var emptyGid = arguments.length <= 4 || arguments[4] === undefined ? 0 : arguments[4];
  833. var segment = arguments.length <= 5 || arguments[5] === undefined ? 32 : arguments[5];
  834. var angles = arguments.length <= 6 || arguments[6] === undefined ? [] : arguments[6];
  835. return _this3.tileUtilities.tileBasedLineOfSight(spriteOne, spriteTwo, mapArray, world, emptyGid, segment, angles);
  836. };
  837. //Intercept the Bump library's `contain` and `outsideBounds` methods to make sure that
  838. //the stage `width` and `height` match the canvas width and height
  839. this.contain = function (sprite, container) {
  840. var bounce = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
  841. var extra = arguments.length <= 3 || arguments[3] === undefined ? undefined : arguments[3];
  842. var o = {};
  843. if (container._stage) {
  844. o = _this3.compensateForStageSize(container);
  845. } else {
  846. o = container;
  847. }
  848. return _this3.bump.contain(sprite, o, bounce, extra);
  849. };
  850. this.outsideBounds = function (sprite, container) {
  851. var extra = arguments.length <= 2 || arguments[2] === undefined ? undefined : arguments[2];
  852. var o = {};
  853. if (container._stage) {
  854. o = _this3.compensateForStageSize(container);
  855. } else {
  856. o = container;
  857. }
  858. return _this3.bump.outsideBounds(sprite, o, extra);
  859. };
  860. //GameUtilities - Useful utilities
  861. this.distance = function (s1, s2) {
  862. return _this3.gameUtilities.distance(s1, s2);
  863. };
  864. this.followEase = function (follower, leader, speed) {
  865. return _this3.gameUtilities.followEase(follower, leader, speed);
  866. };
  867. this.followConstant = function (follower, leader, speed) {
  868. return _this3.gameUtilities.followConstant(follower, leader, speed);
  869. };
  870. this.angle = function (s1, s2) {
  871. return _this3.gameUtilities.angle(s1, s2);
  872. };
  873. this.rotateAroundSprite = function (rotatingSprite, centerSprite, distance, angle) {
  874. return _this3.gameUtilities.rotateAroundSprite(rotatingSprite, centerSprite, distance, angle);
  875. };
  876. this.rotateAroundPoint = this.gameUtilities.rotateAroundPoint;
  877. this.randomInt = this.gameUtilities.randomInt;
  878. this.randomFloat = this.gameUtilities.randomFloat;
  879. this.move = this.gameUtilities.move;
  880. this.wait = this.gameUtilities.wait;
  881. this.worldCamera = function (world, worldWidth, worldHeight) {
  882. var canvas = arguments.length <= 3 || arguments[3] === undefined ? _this3.canvas : arguments[3];
  883. return _this3.gameUtilities.worldCamera(world, worldWidth, worldHeight, canvas);
  884. };
  885. this.lineOfSight = function (spriteOne, spriteTwo, obstacles) {
  886. var segment = arguments.length <= 3 || arguments[3] === undefined ? 32 : arguments[3];
  887. return _this3.gameUtilities.lineOfSight(spriteOne, spriteTwo, obstacles, segment);
  888. };
  889. //Sound.js - Sound
  890. this.soundEffect = function (frequencyValue, attack, decay, type, volumeValue, panValue, wait, pitchBendAmount, reverse, randomValue, dissonance, echo, reverb) {
  891. return soundEffect(frequencyValue, attack, decay, type, volumeValue, panValue, wait, pitchBendAmount, reverse, randomValue, dissonance, echo, reverb);
  892. };
  893. //FullScreen
  894. //this.enableFullScreen = (exitKeyCodes) => this.fullScreen.enableFullScreen(exitKeyCodes);
  895. //TileUtilities
  896. this.hitTestTile = function (sprite, mapArray, gidToCheck, world, pointsToCheck) {
  897. return _this3.tileUtilities.hitTestTile(sprite, mapArray, gidToCheck, world, pointsToCheck);
  898. };
  899. this.getIndex = function (x, y, tilewidth, tileheight, mapWidthInTiles) {
  900. return _this3.tileUtilities.getIndex(x, y, tilewidth, tileheight, mapWidthInTiles);
  901. };
  902. this.getTile = this.tileUtilities.getTile;
  903. this.surroundingCells = this.tileUtilities.surroundingCells;
  904. this.getPoints = this.tileUtilities.getPoints;
  905. this.updateMap = function (mapArray, spritesToUpdate, world) {
  906. return _this3.tileUtilities.updateMap(mapArray, spritesToUpdate, world);
  907. };
  908. this.byDepth = this.tileUtilities.byDepth;
  909. this.hitTestIsoTile = function (sprite, mapArray, gidToCheck, world, pointsToCheck) {
  910. return _this3.tileUtilities.hitTestIsoTile(sprite, mapArray, gidToCheck, world, pointsToCheck);
  911. };
  912. this.getIsoPoints = this.tileUtilities.getIsoPoints;
  913. this.makeIsoPointer = function (pointer, world) {
  914. return _this3.tileUtilities.makeIsoPointer(pointer, world);
  915. };
  916. this.isoRectangle = function (width, height, fillStyle) {
  917. return _this3.tileUtilities.isoRectangle(width, height, fillStyle);
  918. };
  919. this.addIsoProperties = function (sprite, x, y, width, height) {
  920. return _this3.tileUtilities.addIsoProperties(sprite, x, y, width, height);
  921. };
  922. this.makeIsoTiledWorld = function (jsonTiledMap, tileset) {
  923. return _this3.tileUtilities.makeIsoTiledWorld(jsonTiledMap, tileset);
  924. };
  925. }
  926. //Getters and setters
  927. //Pixi's loader resources
  928. }, {
  929. key: "sprite",
  930. //5. SPRITE CREATION METHODS
  931. //Hexi uses methods from the
  932. //SpriteUtilities module to help create sprites. But, as a helpful bonus, Hexi automatically adds sprites
  933. //to the `stage` container. (The `stage` is Hexi's root container for all
  934. //Hexi sprites.) Hexi also adds a whole bunch of
  935. //extra, useful properties and methods to sprites with the
  936. //`addProperties` method
  937. //Universal sprites
  938. value: function sprite(source) {
  939. var x = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
  940. var y = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
  941. var tiling = arguments.length <= 3 || arguments[3] === undefined ? false : arguments[3];
  942. var width = arguments[4];
  943. var height = arguments[5];
  944. var o = this.spriteUtilities.sprite(source, x, y, tiling, width, height);
  945. this.addProperties(o);
  946. this.stage.addChild(o);
  947. return o;
  948. }
  949. //Tiling sprites
  950. }, {
  951. key: "tilingSprite",
  952. value: function tilingSprite(source, width, height) {
  953. var x = arguments.length <= 3 || arguments[3] === undefined ? 0 : arguments[3];
  954. var y = arguments.length <= 4 || arguments[4] === undefined ? 0 : arguments[4];
  955. var o = this.spriteUtilities.tilingSprite(source, width, height, x, y);
  956. this.addProperties(o);
  957. this.stage.addChild(o);
  958. return o;
  959. }
  960. //Hexi's `text` method is a quick way to create a Pixi Text sprite
  961. //and add it to the stage
  962. }, {
  963. key: "text",
  964. value: function text() {
  965. var content = arguments.length <= 0 || arguments[0] === undefined ? "message" : arguments[0];
  966. var font = arguments.length <= 1 || arguments[1] === undefined ? "16px sans" : arguments[1];
  967. var fillStyle = arguments.length <= 2 || arguments[2] === undefined ? "red" : arguments[2];
  968. var x = arguments.length <= 3 || arguments[3] === undefined ? 0 : arguments[3];
  969. var y = arguments.length <= 4 || arguments[4] === undefined ? 0 : arguments[4];
  970. var message = this.spriteUtilities.text(content, font, fillStyle, x, y);
  971. this.addProperties(message);
  972. this.stage.addChild(message);
  973. return message;
  974. }
  975. //The `bitmapText` method is a quick way to create a Pixi BitmapText sprite
  976. }, {
  977. key: "bitmapText",
  978. value: function bitmapText() {
  979. var content = arguments.length <= 0 || arguments[0] === undefined ? "message" : arguments[0];
  980. var font = arguments[1];
  981. var align = arguments[2];
  982. var tint = arguments[3];
  983. var x = arguments.length <= 4 || arguments[4] === undefined ? 0 : arguments[4];
  984. var y = arguments.length <= 5 || arguments[5] === undefined ? 0 : arguments[5];
  985. var message = this.spriteUtilities.bitmapText(content, font, align, tint, x, y);
  986. this.addProperties(message);
  987. this.stage.addChild(message);
  988. return message;
  989. }
  990. //Make a rectangle and add it to the stage
  991. }, {
  992. key: "rectangle",
  993. value: function rectangle() {
  994. var width = arguments.length <= 0 || arguments[0] === undefined ? 32 : arguments[0];
  995. var height = arguments.length <= 1 || arguments[1] === undefined ? 32 : arguments[1];
  996. var fillStyle = arguments.length <= 2 || arguments[2] === undefined ? 0xFF3300 : arguments[2];
  997. var strokeStyle = arguments.length <= 3 || arguments[3] === undefined ? 0x0033CC : arguments[3];
  998. var lineWidth = arguments.length <= 4 || arguments[4] === undefined ? 0 : arguments[4];
  999. var x = arguments.length <= 5 || arguments[5] === undefined ? 0 : arguments[5];
  1000. var y = arguments.length <= 6 || arguments[6] === undefined ? 0 : arguments[6];
  1001. var o = this.spriteUtilities.rectangle(width, height, fillStyle, strokeStyle, lineWidth, x, y);
  1002. this.addProperties(o);
  1003. this.stage.addChild(o);
  1004. return o;
  1005. }
  1006. //Make a circle and add it to the stage
  1007. }, {
  1008. key: "circle",
  1009. value: function circle() {
  1010. var diameter = arguments.length <= 0 || arguments[0] === undefined ? 32 : arguments[0];
  1011. var fillStyle = arguments.length <= 1 || arguments[1] === undefined ? 0xFF3300 : arguments[1];
  1012. var strokeStyle = arguments.length <= 2 || arguments[2] === undefined ? 0x0033CC : arguments[2];
  1013. var lineWidth = arguments.length <= 3 || arguments[3] === undefined ? 0 : arguments[3];
  1014. var x = arguments.length <= 4 || arguments[4] === undefined ? 0 : arguments[4];
  1015. var y = arguments.length <= 5 || arguments[5] === undefined ? 0 : arguments[5];
  1016. var o = this.spriteUtilities.circle(diameter, fillStyle, strokeStyle, lineWidth, x, y);
  1017. this.addProperties(o);
  1018. //Add diameter and radius properties to the circle
  1019. o.circular = true;
  1020. this.stage.addChild(o);
  1021. return o;
  1022. }
  1023. //Draw a line
  1024. }, {
  1025. key: "line",
  1026. value: function line() {
  1027. var strokeStyle = arguments.length <= 0 || arguments[0] === undefined ? 0x000000 : arguments[0];
  1028. var lineWidth = arguments.length <= 1 || arguments[1] === undefined ? 1 : arguments[1];
  1029. var ax = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
  1030. var ay = arguments.length <= 3 || arguments[3] === undefined ? 0 : arguments[3];
  1031. var bx = arguments.length <= 4 || arguments[4] === undefined ? 32 : arguments[4];
  1032. var by = arguments.length <= 5 || arguments[5] === undefined ? 32 : arguments[5];
  1033. var o = this.spriteUtilities.line(strokeStyle, lineWidth, ax, ay, bx, by);
  1034. this.addProperties(o);
  1035. this.stage.addChild(o);
  1036. return o;
  1037. }
  1038. //Make a button and add it to the stage
  1039. }, {
  1040. key: "button",
  1041. value: function button(source, x, y) {
  1042. var o = this.tink.button(source, x, y);
  1043. this.addProperties(o);
  1044. this.stage.addChild(o);
  1045. return o;
  1046. }
  1047. //6. DISPLAY UTILITIES
  1048. //--------------------
  1049. //Use `group` to create a Container
  1050. }, {
  1051. key: "group",
  1052. value: function group() {
  1053. var _spriteUtilities;
  1054. var o = (_spriteUtilities = this.spriteUtilities).group.apply(_spriteUtilities, arguments);
  1055. this.addProperties(o);
  1056. this.stage.addChild(o);
  1057. return o;
  1058. }
  1059. //`batch` creates a Pixi ParticleContainer
  1060. }, {
  1061. key: "batch",
  1062. value: function batch(size, options) {
  1063. var o = this.spriteUtilities.batch(size, options);
  1064. this.addProperties(o);
  1065. this.stage.addChild(o);
  1066. return o;
  1067. }
  1068. //Create a grid of sprite
  1069. }, {
  1070. key: "grid",
  1071. value: function grid() {
  1072. var columns = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];
  1073. var rows = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
  1074. var cellWidth = arguments.length <= 2 || arguments[2] === undefined ? 32 : arguments[2];
  1075. var cellHeight = arguments.length <= 3 || arguments[3] === undefined ? 32 : arguments[3];
  1076. var centerCell = arguments.length <= 4 || arguments[4] === undefined ? false : arguments[4];
  1077. var xOffset = arguments.length <= 5 || arguments[5] === undefined ? 0 : arguments[5];
  1078. var yOffset = arguments.length <= 6 || arguments[6] === undefined ? 0 : arguments[6];
  1079. var makeSprite = arguments.length <= 7 || arguments[7] === undefined ? undefined : arguments[7];
  1080. var extra = arguments.length <= 8 || arguments[8] === undefined ? undefined : arguments[8];
  1081. var o = this.spriteUtilities.grid(columns, rows, cellWidth, cellHeight, centerCell, xOffset, yOffset, makeSprite, extra);
  1082. this.addProperties(o);
  1083. this.stage.addChild(o);
  1084. return o;
  1085. }
  1086. //`makeTiledWorld` uses a Tiled Editor JSON file to generate a game
  1087. //world. It uses the `makeTiledWorld` method from the
  1088. //`tileUtilities` module to do help do this.
  1089. }, {
  1090. key: "makeTiledWorld",
  1091. value: function makeTiledWorld(jsonTiledMap, tileset) {
  1092. var _this4 = this;
  1093. var o = this.tileUtilities.makeTiledWorld(jsonTiledMap, tileset);
  1094. this.addProperties(o);
  1095. //Add Hexi's special sprite properties to the world object and all
  1096. //its child objects
  1097. var addHexiSpriteProperties = function addHexiSpriteProperties(object) {
  1098. _this4.addProperties(object);
  1099. if (object.children) {
  1100. if (object.children.length > 0) {
  1101. object.children.forEach(function (child) {
  1102. addHexiSpriteProperties(child);
  1103. });
  1104. }
  1105. }
  1106. };
  1107. if (o.children) {
  1108. if (o.children.length > 0) {
  1109. o.children.forEach(function (child) {
  1110. addHexiSpriteProperties(child);
  1111. });
  1112. }
  1113. }
  1114. //Return the world object
  1115. this.stage.addChild(o);
  1116. return o;
  1117. }
  1118. //Use `remove` to remove a sprite from its parent. You can supply a
  1119. //single sprite, a list of sprites, or an array of sprites
  1120. }, {
  1121. key: "remove",
  1122. value: function remove() {
  1123. var _spriteUtilities2;
  1124. (_spriteUtilities2 = this.spriteUtilities).remove.apply(_spriteUtilities2, arguments);
  1125. }
  1126. //The flow methods: `flowRight`, `flowDown`, `flowLeft` and
  1127. //`flowUp`.
  1128. //Use them to easily align a row of sprites horizontally or
  1129. //vertically. The flow methods take two arguments: the padding (in
  1130. //pixels) between the sprites, and list of sprites (or an array
  1131. //containing sprites) that you want to align.
  1132. //(This feature was inspired by the Elm programming language)
  1133. //flowRight
  1134. }, {
  1135. key: "flowRight",
  1136. value: function flowRight(padding) {
  1137. //A function to flow the sprites
  1138. var flowSprites = function flowSprites(spritesToFlow) {
  1139. if (spritesToFlow.length > 0) {
  1140. for (var i = 0; i < spritesToFlow.length - 1; i++) {
  1141. var sprite = spritesToFlow[i];
  1142. sprite.putRight(spritesToFlow[i + 1], +padding);
  1143. }
  1144. }
  1145. };
  1146. //Check if `sprites` is a an array of sprites, or an
  1147. //array containing sprite objects
  1148. for (var _len = arguments.length, sprites = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1149. sprites[_key - 1] = arguments[_key];
  1150. }
  1151. if (!(sprites[0] instanceof Array)) {
  1152. //It's an array of sprites
  1153. flowSprites(sprites);
  1154. } else {
  1155. //It's an array containing sprite objects
  1156. var spritesArray = sprites[0];
  1157. flowSprites(spritesArray);
  1158. }
  1159. }
  1160. //flowDown
  1161. }, {
  1162. key: "flowDown",
  1163. value: function flowDown(padding) {
  1164. var flowSprites = function flowSprites(spritesToFlow) {
  1165. if (spritesToFlow.length > 0) {
  1166. for (var i = 0; i < spritesToFlow.length - 1; i++) {
  1167. var sprite = spritesToFlow[i];
  1168. sprite.putBottom(spritesToFlow[i + 1], 0, +padding);
  1169. }
  1170. }
  1171. };
  1172. for (var _len2 = arguments.length, sprites = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  1173. sprites[_key2 - 1] = arguments[_key2];
  1174. }
  1175. if (!(sprites[0] instanceof Array)) {
  1176. flowSprites(sprites);
  1177. } else {
  1178. var spritesArray = sprites[0];
  1179. flowSprites(spritesArray);
  1180. }
  1181. }
  1182. //flowLeft
  1183. }, {
  1184. key: "flowLeft",
  1185. value: function flowLeft(padding) {
  1186. var flowSprites = function flowSprites(spritesToFlow) {
  1187. if (spritesToFlow.length > 0) {
  1188. for (var i = 0; i < spritesToFlow.length - 1; i++) {
  1189. var sprite = spritesToFlow[i];
  1190. sprite.putLeft(spritesToFlow[i + 1], -padding);
  1191. }
  1192. }
  1193. };
  1194. for (var _len3 = arguments.length, sprites = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
  1195. sprites[_key3 - 1] = arguments[_key3];
  1196. }
  1197. if (!(sprites[0] instanceof Array)) {
  1198. flowSprites(sprites);
  1199. } else {
  1200. var spritesArray = sprites[0];
  1201. flowSprites(spritesArray);
  1202. }
  1203. }
  1204. //flowUp
  1205. }, {
  1206. key: "flowUp",
  1207. value: function flowUp(padding) {
  1208. var flowSprites = function flowSprites(spritesToFlow) {
  1209. if (spritesToFlow.length > 0) {
  1210. for (var i = 0; i < spritesToFlow.length - 1; i++) {
  1211. var sprite = spritesToFlow[i];
  1212. sprite.putTop(spritesToFlow[i + 1], 0, -padding);
  1213. }
  1214. }
  1215. };
  1216. for (var _len4 = arguments.length, sprites = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
  1217. sprites[_key4 - 1] = arguments[_key4];
  1218. }
  1219. if (!(sprites[0] instanceof Array)) {
  1220. flowSprites(sprites);
  1221. } else {
  1222. var spritesArray = sprites[0];
  1223. flowSprites(spritesArray);
  1224. }
  1225. }
  1226. //7. SPRITE PROPERTIES
  1227. //The sprite creation methods above all run the `addProperties`
  1228. //method on each sprite they create. `addProperties` adds special
  1229. //properties and methods (super powers!) to Hexi sprites.
  1230. }, {
  1231. key: "addProperties",
  1232. value: function addProperties(o) {
  1233. var _this5 = this;
  1234. //Velocity
  1235. o.vx = 0;
  1236. o.vy = 0;
  1237. //A "private" `_layer` property
  1238. o._layer = 0;
  1239. //Is the sprite circular? If it is, it will be given a `radius`
  1240. //and `diameter`
  1241. o._circular = false;
  1242. //Is the sprite interactive? Setting this to `true` makes the
  1243. //sprite behave like a button
  1244. o._interact = false;
  1245. //Is the sprite draggable?
  1246. o._draggable = false;
  1247. //Flag this object for compatibility with the Bump collision
  1248. //library
  1249. o._bumpPropertiesAdded = true;
  1250. //Swap the depth layer positions of two child sprites
  1251. o.swapChildren = function (child1, child2) {
  1252. var index1 = o.children.indexOf(child1),
  1253. index2 = o.children.indexOf(child2);
  1254. if (index1 !== -1 && index2 !== -1) {
  1255. //Swap the indexes
  1256. child1.childIndex = index2;
  1257. child2.childIndex = index1;
  1258. //Swap the array positions
  1259. o.children[index1] = child2;
  1260. o.children[index2] = child1;
  1261. } else {
  1262. throw new Error(child + " Both objects must be a child of the caller " + o);
  1263. }
  1264. };
  1265. //`add` and `remove` convenience methods let you add and remove
  1266. //many sprites at the same time.
  1267. o.add = function () {
  1268. for (var _len5 = arguments.length, sprites = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
  1269. sprites[_key5] = arguments[_key5];
  1270. }
  1271. if (sprites.length > 1) {
  1272. sprites.forEach(function (sprite) {
  1273. return o.addChild(sprite);
  1274. });
  1275. } else {
  1276. o.addChild(sprites[0]);
  1277. }
  1278. };
  1279. o.remove = function () {
  1280. for (var _len6 = arguments.length, sprites = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
  1281. sprites[_key6] = arguments[_key6];
  1282. }
  1283. if (sprites.length > 1) {
  1284. sprites.forEach(function (sprite) {
  1285. return o.removeChild(sprite);
  1286. });
  1287. } else {
  1288. o.removeChild(sprites[0]);
  1289. }
  1290. };
  1291. //The `put` methods are conveniences that help you position a
  1292. //another sprite in and around this sprite.
  1293. //First, get a short form reference to the sprite to make the code
  1294. //easier to read
  1295. var a = o;
  1296. //The `nudgeAnchor`, `compensateForAnchor` and
  1297. //`compensateForAnchors` (with an "s"!) methods are used by
  1298. //the `put` methods to adjust the position of the sprite based on
  1299. //its x/y anchor point.
  1300. var nudgeAnchor = function nudgeAnchor(o, value, axis) {
  1301. if (o.anchor !== undefined) {
  1302. if (o.anchor[axis] !== 0) {
  1303. return value * (1 - o.anchor[axis] - o.anchor[axis]);
  1304. } else {
  1305. return value;
  1306. }
  1307. } else {
  1308. return value;
  1309. }
  1310. };
  1311. var compensateForAnchor = function compensateForAnchor(o, value, axis) {
  1312. if (o.anchor !== undefined) {
  1313. if (o.anchor[axis] !== 0) {
  1314. return value * o.anchor[axis];
  1315. } else {
  1316. return 0;
  1317. }
  1318. } else {
  1319. return 0;
  1320. }
  1321. };
  1322. var compensateForAnchors = function compensateForAnchors(a, b, property1, property2) {
  1323. return compensateForAnchor(a, a[property1], property2) + compensateForAnchor(b, b[property1], property2);
  1324. };
  1325. //The `put` methods:
  1326. //Center a sprite inside this sprite. `xOffset` and `yOffset`
  1327. //arguments determine by how much the other sprite's position
  1328. //should be offset from the center. These methods use the
  1329. //sprites' global coordinates (`gx` and `gy`).
  1330. //In all these functions, `b` is the second sprite that is being
  1331. //positioned relative to the first sprite (this one), `a`.
  1332. //Center `b` inside `a`.
  1333. o.putCenter = function (b) {
  1334. var xOffset = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
  1335. var yOffset = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
  1336. if (o._stage) a = _this5.compensateForStageSize(o);
  1337. //b.x = (a.x + a.halfWidth - (b.halfWidth * ((1 - b.anchor.x) - b.anchor.x))) + xOffset;
  1338. b.x = a.x + nudgeAnchor(a, a.halfWidth, "x") - nudgeAnchor(b, b.halfWidth, "x") + xOffset;
  1339. b.y = a.y + nudgeAnchor(a, a.halfHeight, "y") - nudgeAnchor(b, b.halfHeight, "y") + yOffset;
  1340. //Compensate for the parent's position
  1341. if (!o._stage) o.compensateForParentPosition(a, b);
  1342. };
  1343. //Position `b` to the left of `a`.
  1344. o.putLeft = function (b) {
  1345. var xOffset = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
  1346. var yOffset = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
  1347. if (o._stage) a = _this5.compensateForStageSize(o);
  1348. b.x = a.x - nudgeAnchor(b, b.width, "x") + xOffset - compensateForAnchors(a, b, "width", "x");
  1349. b.y = a.y + nudgeAnchor(a, a.halfHeight, "y") - nudgeAnchor(b, b.halfHeight, "y") + yOffset;
  1350. //Compensate for the parent's position
  1351. if (!o._stage) o.compensateForParentPosition(a, b);
  1352. };
  1353. //Position `b` above `a`.
  1354. o.putTop = function (b) {
  1355. var xOffset = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
  1356. var yOffset = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
  1357. if (o._stage) a = _this5.compensateForStageSize(o);
  1358. b.x = a.x + nudgeAnchor(a, a.halfWidth, "x") - nudgeAnchor(b, b.halfWidth, "x") + xOffset;
  1359. b.y = a.y - nudgeAnchor(b, b.height, "y") + yOffset - compensateForAnchors(a, b, "height", "y");
  1360. //Compensate for the parent's position
  1361. if (!o._stage) o.compensateForParentPosition(a, b);
  1362. };
  1363. //Position `b` to the right of `a`.
  1364. o.putRight = function (b) {
  1365. var xOffset = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
  1366. var yOffset = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
  1367. if (o._stage) a = _this5.compensateForStageSize(o);
  1368. b.x = a.x + nudgeAnchor(a, a.width, "x") + xOffset + compensateForAnchors(a, b, "width", "x");
  1369. b.y = a.y + nudgeAnchor(a, a.halfHeight, "y") - nudgeAnchor(b, b.halfHeight, "y") + yOffset;
  1370. //b.x = (a.x + a.width) + xOffset;
  1371. //b.y = (a.y + a.halfHeight - b.halfHeight) + yOffset;
  1372. //Compensate for the parent's position
  1373. if (!o._stage) o.compensateForParentPosition(a, b);
  1374. };
  1375. //Position `b` below `a`.
  1376. o.putBottom = function (b) {
  1377. var xOffset = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
  1378. var yOffset = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
  1379. if (o._stage) a = _this5.compensateForStageSize(o);
  1380. //b.x = (a.x + a.halfWidth - b.halfWidth) + xOffset;
  1381. b.x = a.x + nudgeAnchor(a, a.halfWidth, "x") - nudgeAnchor(b, b.halfWidth, "x") + xOffset;
  1382. //b.y = (a.y + a.height) + yOffset;
  1383. b.y = a.y + nudgeAnchor(a, a.height, "y") + yOffset + compensateForAnchors(a, b, "height", "y");
  1384. //Compensate for the parent's position
  1385. if (!o._stage) o.compensateForParentPosition(a, b);
  1386. };
  1387. //`compensateForParentPosition` is a helper function for the above
  1388. //`put` methods that subracts the parent's global position from
  1389. //the nested child's position.
  1390. o.compensateForParentPosition = function (a, b) {
  1391. if (b.parent.gx !== 0 || b.parent.gy !== 0) {
  1392. b.x -= a.gx;
  1393. b.y -= a.gy;
  1394. }
  1395. };
  1396. var self = this;
  1397. Object.defineProperties(o, {
  1398. "gx": {
  1399. get: function get() {
  1400. return o.getGlobalPosition().x;
  1401. },
  1402. enumerable: true,
  1403. configurable: true
  1404. },
  1405. "gy": {
  1406. get: function get() {
  1407. return o.getGlobalPosition().y;
  1408. },
  1409. enumerable: true,
  1410. configurable: true
  1411. },
  1412. "centerX": {
  1413. get: function get() {
  1414. return o.x + o.width / 2 - o.xAnchorOffset;
  1415. },
  1416. enumerable: true,
  1417. configurable: true
  1418. },
  1419. "centerY": {
  1420. get: function get() {
  1421. return o.y + o.height / 2 - o.yAnchorOffset;
  1422. },
  1423. enumerable: true,
  1424. configurable: true
  1425. },
  1426. "halfWidth": {
  1427. get: function get() {
  1428. return o.width / 2;
  1429. },
  1430. enumerable: true,
  1431. configurable: true
  1432. },
  1433. "halfHeight": {
  1434. get: function get() {
  1435. return o.height / 2;
  1436. },
  1437. enumerable: true,
  1438. configurable: true
  1439. },
  1440. "scaleModeNearest": {
  1441. set: function set(value) {
  1442. if (o.texture.baseTexture) {
  1443. if (value) {
  1444. o.texture.baseTexture.scaleMode = PIXI.SCALE_MODES.NEAREST;
  1445. } else {
  1446. o.texture.baseTexture.scaleMode = PIXI.SCALE_MODES.LINEAR;
  1447. }
  1448. } else {
  1449. throw new Error("The scale mode of " + o + " cannot be modified");
  1450. }
  1451. },
  1452. enumerable: true,
  1453. configurable: true
  1454. },
  1455. "pivotX": {
  1456. get: function get() {
  1457. return o.anchor.x;
  1458. },
  1459. set: function set(value) {
  1460. if (o.anchor === undefined) {
  1461. throw new Error(o + " does not have a PivotX value");
  1462. }
  1463. o.anchor.x = value;
  1464. if (!o._previousPivotX) {
  1465. o.x += value * o.width;
  1466. } else {
  1467. o.x += (value - o._previousPivotX) * o.width;
  1468. }
  1469. o._previousPivotX = value;
  1470. },
  1471. enumerable: true,
  1472. configurable: true
  1473. },
  1474. "pivotY": {
  1475. get: function get() {
  1476. return o.anchor.y;
  1477. },
  1478. set: function set(value) {
  1479. if (o.anchor === undefined) {
  1480. throw new Error(o + " does not have a PivotY value");
  1481. }
  1482. o.anchor.y = value;
  1483. if (!o._previousPivotY) {
  1484. o.y += value * o.height;
  1485. } else {
  1486. o.y += (value - o._previousPivotY) * o.height;
  1487. }
  1488. o._previousPivotY = value;
  1489. },
  1490. enumerable: true,
  1491. configurable: true
  1492. },
  1493. "xAnchorOffset": {
  1494. get: function get() {
  1495. if (o.anchor !== undefined) {
  1496. return o.height * o.anchor.x;
  1497. } else {
  1498. return 0;
  1499. }
  1500. },
  1501. enumerable: true,
  1502. configurable: true
  1503. },
  1504. "yAnchorOffset": {
  1505. get: function get() {
  1506. if (o.anchor !== undefined) {
  1507. return o.width * o.anchor.y;
  1508. } else {
  1509. return 0;
  1510. }
  1511. },
  1512. enumerable: true,
  1513. configurable: true
  1514. },
  1515. "scaleX": {
  1516. get: function get() {
  1517. return o.scale.x;
  1518. },
  1519. set: function set(value) {
  1520. o.scale.x = value;
  1521. },
  1522. enumerable: true,
  1523. configurable: true
  1524. },
  1525. "scaleY": {
  1526. get: function get() {
  1527. return o.scale.y;
  1528. },
  1529. set: function set(value) {
  1530. o.scale.y = value;
  1531. },
  1532. enumerable: true,
  1533. configurable: true
  1534. },
  1535. //Depth layer
  1536. "layer": {
  1537. get: function get() {
  1538. return o._layer;
  1539. },
  1540. set: function set(value) {
  1541. o._layer = value;
  1542. if (o.parent) {
  1543. //Sort the sprite’s parent’s `children` array so that sprites with a
  1544. //higher `layer` value are moved to the end of the array
  1545. o.parent.children.sort(function (a, b) {
  1546. return a.layer - b.layer;
  1547. });
  1548. }
  1549. },
  1550. enumerable: true,
  1551. configurable: true
  1552. },
  1553. //Interactivity
  1554. "interact": {
  1555. get: function get() {
  1556. return o._interact;
  1557. },
  1558. set: function set(value) {
  1559. if (value === true) {
  1560. if (!o._interact) {
  1561. self.makeInteractive(o);
  1562. o._interact = true;
  1563. }
  1564. } else {
  1565. if (self.tink.buttons.indexOf(o) !== -1) {
  1566. self.tink.buttons.splice(self.tink.buttons.indexOf(o), 1);
  1567. o._interact = false;
  1568. }
  1569. }
  1570. },
  1571. enumerable: true,
  1572. configurable: true
  1573. },
  1574. //Drag and drop
  1575. "draggable": {
  1576. get: function get() {
  1577. return o._draggable;
  1578. },
  1579. set: function set(value) {
  1580. if (value === true) {
  1581. if (!o._draggable) {
  1582. self.makeDraggable(o);
  1583. o._draggable = true;
  1584. }
  1585. } else {
  1586. self.makeUndraggable(o);
  1587. o._draggable = false;
  1588. }
  1589. },
  1590. enumerable: true,
  1591. configurable: true
  1592. },
  1593. //The `localBounds` and `globalBounds` methods return an object
  1594. //with `x`, `y`, `width`, and `height` properties that define
  1595. //the dimensions and position of the sprite. This is a convenience
  1596. //to help you set or test boundaries without having to know
  1597. //these numbers or request them specifically in your code.
  1598. "localBounds": {
  1599. get: function get() {
  1600. return {
  1601. x: 0,
  1602. y: 0,
  1603. width: o.width,
  1604. height: o.height
  1605. };
  1606. },
  1607. enumerable: true,
  1608. configurable: true
  1609. },
  1610. "globalBounds": {
  1611. get: function get() {
  1612. return {
  1613. x: o.gx,
  1614. y: o.gy,
  1615. width: o.gx + o.width,
  1616. height: o.gy + o.height
  1617. };
  1618. },
  1619. enumerable: true,
  1620. configurable: true
  1621. },
  1622. //`empty` is a convenience property that will return `true` or
  1623. //`false` depending on whether or not this sprite's `children`
  1624. //array is empty
  1625. "empty": {
  1626. get: function get() {
  1627. if (o.children.length === 0) {
  1628. return true;
  1629. } else {
  1630. return false;
  1631. }
  1632. },
  1633. enumerable: true,
  1634. configurable: true
  1635. },
  1636. //The `circular` property lets you define whether a sprite
  1637. //should be interpreted as a circular object. If you set
  1638. //`circular` to `true`, the sprite is given `radius` and `diameter`
  1639. //properties. If you set `circular` to `false`, the `radius`
  1640. //and `diameter` properties are deleted from the sprite
  1641. "circular": {
  1642. get: function get() {
  1643. return o._circular;
  1644. },
  1645. set: function set(value) {
  1646. //Give the sprite `diameter` and `radius` properties
  1647. //if `circular` is `true`
  1648. if (value === true && o._circular === false) {
  1649. Object.defineProperties(o, {
  1650. "diameter": {
  1651. get: function get() {
  1652. return o.width;
  1653. },
  1654. set: function set(value) {
  1655. o.width = value;
  1656. o.height = value;
  1657. },
  1658. enumerable: true,
  1659. configurable: true
  1660. },
  1661. "radius": {
  1662. get: function get() {
  1663. return o.halfWidth;
  1664. },
  1665. set: function set(value) {
  1666. o.width = value * 2;
  1667. o.height = value * 2;
  1668. },
  1669. enumerable: true,
  1670. configurable: true
  1671. }
  1672. });
  1673. //Set o.sprite's `_circular` property to `true`
  1674. o._circular = true;
  1675. }
  1676. //Remove the sprite's `diameter` and `radius` properties
  1677. //if `circular` is `false`
  1678. if (value === false && o._circular === true) {
  1679. delete o.diameter;
  1680. delete o.radius;
  1681. o._circular = false;
  1682. }
  1683. },
  1684. enumerable: true,
  1685. configurable: true
  1686. }
  1687. });
  1688. //A `setPosition` convenience method to let you set the
  1689. //x any y position of a sprite with one line of code.
  1690. o.setPosition = function (x, y) {
  1691. o.x = x;
  1692. o.y = y;
  1693. };
  1694. //A similar `setScale` convenience method
  1695. o.setScale = function (xScale, yScale) {
  1696. o.scale.x = xScale;
  1697. o.scale.y = yScale;
  1698. };
  1699. //And a matching `setPivot` method
  1700. o.setPivot = function (xPivot, yPivot) {
  1701. o.pivotX = xPivot;
  1702. o.pivotY = yPivot;
  1703. };
  1704. if (o.circular) {
  1705. Object.defineProperty(o, "radius", {
  1706. get: function get() {
  1707. return o.width / 2;
  1708. },
  1709. enumerable: true,
  1710. configurable: true
  1711. });
  1712. }
  1713. }
  1714. //8. Utilities
  1715. //A method to scale and align the canvas in the browser
  1716. //window using the `scaleToWindow.js` function module
  1717. }, {
  1718. key: "scaleToWindow",
  1719. value: (function (_scaleToWindow) {
  1720. function scaleToWindow() {
  1721. return _scaleToWindow.apply(this, arguments);
  1722. }
  1723. scaleToWindow.toString = function () {
  1724. return _scaleToWindow.toString();
  1725. };
  1726. return scaleToWindow;
  1727. })(function () {
  1728. var _this6 = this;
  1729. var scaleBorderColor = arguments.length <= 0 || arguments[0] === undefined ? "#2C3539" : arguments[0];
  1730. //Set the default CSS padding and margins of HTML elements to 0
  1731. //<style>* {padding: 0; margin: 0}</style>
  1732. var newStyle = document.createElement("style");
  1733. var style = "* {padding: 0; margin: 0}";
  1734. newStyle.appendChild(document.createTextNode(style));
  1735. document.head.appendChild(newStyle);
  1736. //Use the `scaleToWindow` function module to scale the canvas to
  1737. //the maximum window size
  1738. this.scale = scaleToWindow(this.canvas, scaleBorderColor);
  1739. this.pointer.scale = this.scale;
  1740. //this.pointer = this.makePointer(this.canvas, this.scale);
  1741. console.log(this.pointer);
  1742. //Re-scale on each browser resize
  1743. window.addEventListener("resize", function (event) {
  1744. //Scale the canvas and update Hexi's global `scale` value and
  1745. //the pointer's `scale` value
  1746. _this6.scale = scaleToWindow(_this6.canvas, scaleBorderColor);
  1747. _this6.pointer.scale = _this6.scale;
  1748. });
  1749. //Flag that the canvas has been scaled
  1750. this.canvas.scaled = true;
  1751. })
  1752. //`log` is a shortcut for `console.log`, so that you have less to
  1753. //type when you're debugging
  1754. }, {
  1755. key: "log",
  1756. value: function log(value) {
  1757. return console.log(value);
  1758. }
  1759. //The `makeProgressBar` method creates a `progressBar` object with
  1760. //`create`, `update` and `remove` methods. It's called by the
  1761. //`loadingBar` method, which should be run inside the `load`
  1762. //function of your application code.
  1763. }, {
  1764. key: "makeProgressBar",
  1765. value: function makeProgressBar(hexiObject) {
  1766. var hexi = hexiObject;
  1767. //The `progressBar` object
  1768. hexi.progressBar = {
  1769. maxWidth: 0,
  1770. height: 0,
  1771. backgroundColor: "0x808080",
  1772. foregroundColor: "0x00FFFF",
  1773. backBar: null,
  1774. frontBar: null,
  1775. percentage: null,
  1776. assets: null,
  1777. initialized: false,
  1778. //Use the `create` method to create the progress bar
  1779. create: function create() {
  1780. //Set the maximum width to half the width of the canvas
  1781. this.maxWidth = hexi.canvas.width / 2;
  1782. //Build the progress bar using two rectangle sprites and
  1783. //one text sprite
  1784. //1. Create the background bar's gray background
  1785. this.backBar = hexi.rectangle(this.maxWidth, 32, this.backgroundColor);
  1786. this.backBar.x = hexi.canvas.width / 2 - this.maxWidth / 2;
  1787. this.backBar.y = hexi.canvas.height / 2 - 16;
  1788. //2. Create the blue foreground bar. This is the element of the
  1789. //progress bar that will increase in width as assets load
  1790. this.frontBar = hexi.rectangle(this.maxWidth, 32, this.foregroundColor);
  1791. this.frontBar.x = hexi.canvas.width / 2 - this.maxWidth / 2;
  1792. this.frontBar.y = hexi.canvas.height / 2 - 16;
  1793. //3. A text sprite that will display the percentage
  1794. //of assets that have loaded
  1795. this.percentage = hexi.text("0%", "28px sans-serif", "black");
  1796. this.percentage.x = hexi.canvas.width / 2 - this.maxWidth / 2 + 12;
  1797. this.percentage.y = hexi.canvas.height / 2 - 17;
  1798. },
  1799. //Use the `update` method to update the width of the bar and
  1800. //percentage loaded each frame
  1801. update: function update() {
  1802. //Change the width of the blue `frontBar` to match the
  1803. //ratio of assets that have loaded.
  1804. var ratio = hexi.loadingProgress / 100;
  1805. //console.log(`ratio: ${ratio}`);
  1806. this.frontBar.width = this.maxWidth * ratio;
  1807. //Display the percentage
  1808. this.percentage.content = Math.round(hexi.loadingProgress) + " %";
  1809. },
  1810. //Use the `remove` method to remove the progress bar when all the
  1811. //game assets have finished loading
  1812. remove: function remove() {
  1813. //Remove the progress bar using the universal sprite `remove`
  1814. //function
  1815. hexi.stage.removeChild(this.frontBar);
  1816. hexi.stage.removeChild(this.backBar);
  1817. hexi.stage.removeChild(this.percentage);
  1818. }
  1819. };
  1820. }
  1821. //The `loadingBar` method should be called inside the user-definable
  1822. //`load` method in the application code. This function will run in a
  1823. //loop. It will create the loading bar, and then call the loading
  1824. //bar's `update` method each frame. After all the assets have been
  1825. //loaded, Hexi's `validateAssets` method removes the loading bar.
  1826. }, {
  1827. key: "loadingBar",
  1828. value: function loadingBar() {
  1829. if (!this._progressBarAdded) {
  1830. //Run the method that creates the progress bar object
  1831. this.makeProgressBar(this);
  1832. //Create the loading bar
  1833. this.progressBar.create();
  1834. //Tell Hexi that a progress bar has been added
  1835. this._progressBarAdded = true;
  1836. } else {
  1837. //Update the progress bar each frame
  1838. this.progressBar.update();
  1839. }
  1840. }
  1841. //Hexi's root `stage` object will have a width and height equal to
  1842. //its contents, not the size of the canvas. So, let's use the more
  1843. //useful canvas width and height for relative positioning instead
  1844. }, {
  1845. key: "compensateForStageSize",
  1846. value: function compensateForStageSize(o) {
  1847. if (o._stage === true) {
  1848. var a = {};
  1849. a.x = 0;
  1850. a.y = 0;
  1851. a.width = this.canvas.width;
  1852. a.height = this.canvas.height;
  1853. a.halfWidth = this.canvas.width / 2;
  1854. a.halfHeight = this.canvas.height / 2;
  1855. a.xAnchorOffset = 0;
  1856. a.yAnchorOffset = 0;
  1857. return a;
  1858. }
  1859. }
  1860. //High level functions for accessing the loaded resources and custom parsed
  1861. //objects, like sounds.
  1862. }, {
  1863. key: "image",
  1864. value: function image(imageFileName) {
  1865. if (this.TextureCache[imageFileName]) {
  1866. return this.TextureCache[imageFileName];
  1867. } else {
  1868. throw new Error(imageFileName + " does not appear to be an image");
  1869. }
  1870. }
  1871. }, {
  1872. key: "id",
  1873. value: function id(textureAtlasFrameId) {
  1874. if (this.TextureCache[textureAtlasFrameId]) {
  1875. return this.TextureCache[textureAtlasFrameId];
  1876. } else {
  1877. throw new Error(textureAtlasFrameId + " does not appear to be a texture atlas frame id");
  1878. }
  1879. }
  1880. }, {
  1881. key: "json",
  1882. value: function json(jsonFileName) {
  1883. if (this.loader.resources[jsonFileName].data) {
  1884. return this.resources[jsonFileName].data;
  1885. } else {
  1886. throw new Error(jsonFileName + " does not appear to be a JSON data file");
  1887. }
  1888. }
  1889. }, {
  1890. key: "xml",
  1891. value: function xml(xmlFileName) {
  1892. if (this.loader.resources[xmlFileName].data) {
  1893. return this.resources[xmlFileName].data;
  1894. } else {
  1895. throw new Error(xmlFileName + " does not appear to be a XML data file");
  1896. }
  1897. }
  1898. }, {
  1899. key: "sound",
  1900. value: function sound(soundFileName) {
  1901. if (this.soundObjects[soundFileName]) {
  1902. return this.soundObjects[soundFileName];
  1903. } else {
  1904. throw new Error(soundFileName + " does not appear to be a sound object");
  1905. }
  1906. }
  1907. }, {
  1908. key: "resources",
  1909. get: function get() {
  1910. return this.loader.resources;
  1911. }
  1912. //Add Smoothie getters and setters to access the `fps`,
  1913. //`properties`, `renderFps` and `interpolate` properties
  1914. }, {
  1915. key: "fps",
  1916. get: function get() {
  1917. return this.smoothie.fps;
  1918. },
  1919. set: function set(value) {
  1920. this.smoothie.fps = value;
  1921. }
  1922. }, {
  1923. key: "renderFps",
  1924. get: function get() {
  1925. return this.smoothie.renderFps;
  1926. },
  1927. set: function set(value) {
  1928. this.smoothie.renderFps = value;
  1929. }
  1930. }, {
  1931. key: "interpolate",
  1932. get: function get() {
  1933. return this.smoothie.interpolate;
  1934. },
  1935. set: function set(value) {
  1936. this.smoothie.interpolate = value;
  1937. }
  1938. }, {
  1939. key: "interpolationProperties",
  1940. get: function get() {
  1941. return this.smoothie.properties;
  1942. },
  1943. set: function set(value) {
  1944. this.smoothie.properties = value;
  1945. }
  1946. //The `border` property lets you set the border style on the canvas
  1947. }, {
  1948. key: "border",
  1949. set: function set(value) {
  1950. this.canvas.style.border = value;
  1951. }
  1952. //The `backgroundColor` property lets you set the background color
  1953. //of the renderer
  1954. }, {
  1955. key: "backgroundColor",
  1956. set: function set(value) {
  1957. this.renderer.backgroundColor = this.color(value);
  1958. }
  1959. }]);
  1960. return Hexi;
  1961. })();
  1962. //# sourceMappingURL=core.js.map