├── .gitmodules ├── README.md ├── chapter01 ├── 01_helloWorld.html ├── 02_displayingTheCanvas.html ├── 03_displayingSprites.html ├── 04_monitorLoadProgress.html ├── 05_positionAndRotation.html ├── 06_spriteFromTileset.html ├── 07_spriteFromTextureAtlas.html ├── es5 │ ├── displayingSprites.js │ ├── displayingSprites.js.map │ ├── displayingTheCanvas.js │ ├── displayingTheCanvas.js.map │ ├── monitorLoadProgress.js │ ├── monitorLoadProgress.js.map │ ├── positionAndRotation.js │ ├── positionAndRotation.js.map │ ├── spriteFromTextureAtlas.js │ ├── spriteFromTextureAtlas.js.map │ ├── spriteFromTileset.js │ └── spriteFromTileset.js.map ├── es6 │ ├── displayingSprites.js │ ├── displayingTheCanvas.js │ ├── monitorLoadProgress.js │ ├── positionAndRotation.js │ ├── spriteFromTextureAtlas.js │ └── spriteFromTileset.js └── images │ ├── animals.png │ ├── blob.png │ ├── cat64x64.png │ ├── door.png │ ├── dungeon.png │ ├── explorer.png │ ├── pixie.png │ ├── pixie768x512.png │ ├── pixie96x48.png │ ├── tileset.png │ ├── treasure.png │ ├── treasureHunter.json │ ├── treasureHunter.png │ └── treasureHunter.tps ├── chapter02 ├── .04_keyboardMovement.html.swp ├── .07_ticker.html.swp ├── 01_gameLoop.html ├── 02_velocity.html ├── 03_gameStates.html ├── 04_keyboardMovement.html ├── 05_physics.html ├── 06_containingMovement.html ├── es5 │ ├── containingMovement.js │ ├── containingMovement.js.map │ ├── gameLoop.js │ ├── gameLoop.js.map │ ├── gameStates.js │ ├── gameStates.js.map │ ├── keyboardMovement.js │ ├── keyboardMovement.js.map │ ├── physics.js │ ├── physics.js.map │ ├── ticker.js │ ├── ticker.js.map │ ├── velocity.js │ └── velocity.js.map ├── es6 │ ├── .containingMovement.js.swp │ ├── .gameStates.js.swp │ ├── .keyboardMovement.js.swn │ ├── .keyboardMovement.js.swo │ ├── .keyboardMovement.js.swp │ ├── .ticker.js.swp │ ├── containingMovement.js │ ├── gameLoop.js │ ├── gameStates.js │ ├── keyboardMovement.js │ ├── physics.js │ └── velocity.js └── images │ ├── cat64x64.png │ └── pixie96x48.png ├── chapter03 ├── .bitmapText.html.swp ├── .shapes.html.swp ├── 01_shapes.html ├── 02_singleGraphicsContext.html ├── 03_animatingGraphics.html ├── 04_text.html ├── 05_bitmapText.html ├── 06_groupingSprites.html ├── es5 │ ├── animatingGraphics.js │ ├── animatingGraphics.js.map │ ├── bitmapText.js │ ├── bitmapText.js.map │ ├── groupingSprites.js │ ├── groupingSprites.js.map │ ├── shapes.js │ ├── shapes.js.map │ ├── singleGraphicsContext.js │ ├── singleGraphicsContext.js.map │ ├── text.js │ └── text.js.map ├── es6 │ ├── .animatingGraphics.js.swp │ ├── .bitmapText.js.swp │ ├── .groupingSprites.js.swo │ ├── .groupingSprites.js.swp │ ├── .shapes.js.swo │ ├── .shapes.js.swp │ ├── animatingGraphics.js │ ├── bitmapText.js │ ├── groupingSprites.js │ ├── shapes.js │ ├── singleGraphicsContext.js │ └── text.js ├── fonts │ ├── PetMe.ttf │ ├── SpicyRice.ttf │ ├── disko.png │ ├── disko.xml │ └── puzzler.otf └── images │ ├── animals.json │ ├── animals.png │ ├── animals.tps │ ├── cat.png │ ├── hedgehog.png │ └── tiger.png ├── chapter04 ├── .02_treasureHunter.html.swp ├── 01_rectangleCollision.html ├── 02_treasureHunter.html ├── es5 │ ├── rectangleCollision.js │ ├── rectangleCollision.js.map │ ├── treasureHunter.js │ └── treasureHunter.js.map ├── es6 │ ├── rectangleCollision.js │ └── treasureHunter.js ├── fonts │ ├── PetMe.ttf │ ├── SpicyRice.ttf │ ├── disko.png │ ├── disko.xml │ └── puzzler.otf └── images │ ├── animals.png │ ├── blob.png │ ├── box64x64.png │ ├── cat64x64.png │ ├── door.png │ ├── dungeon.png │ ├── explorer.png │ ├── pixie.png │ ├── pixie768x512.png │ ├── pixie96x48.png │ ├── tileset.png │ ├── treasure.png │ ├── treasureHunter.json │ ├── treasureHunter.png │ └── treasureHunter.tps ├── chapter05 ├── .01_fromTextures.html.swp ├── .03_tilesetFilmstrip.html.swn ├── .04_statePlayer.html.swm ├── .04_statePlayer.html.swn ├── 01_fromTextures.html ├── 02_fromFrames.html ├── 03_tilesetFilmstrip.html ├── 04_statePlayer.html ├── 05_treasureHunter2.html ├── 06_particles.html ├── 07_particleEmitter.html ├── es5 │ ├── fromFrames.js │ ├── fromFrames.js.map │ ├── fromTextures.js │ ├── fromTextures.js.map │ ├── particleEmitter.js │ ├── particleEmitter.js.map │ ├── particles.js │ ├── particles.js.map │ ├── rectangleCollision.js │ ├── rectangleCollision.js.map │ ├── statePlayer.js │ ├── statePlayer.js.map │ ├── tilesetFilmstrip.js │ ├── tilesetFilmstrip.js.map │ ├── treasureHunter.js │ ├── treasureHunter.js.map │ ├── treasureHunter2.js │ └── treasureHunter2.js.map ├── es6 │ ├── .fromTextures.js.swp │ ├── .tilesetFilmstrip.js.swn │ ├── fromFrames.js │ ├── fromTextures.js │ ├── particleEmitter.js │ ├── particles.js │ ├── rectangleCollision.js │ ├── statePlayer.js │ ├── tilesetFilmstrip.js │ └── treasureHunter2.js └── images │ ├── adventuress.png │ ├── pixie0.png │ ├── pixie1.png │ ├── pixie2.png │ ├── pixieAtlas.json │ ├── pixieAtlas.png │ ├── pixieAtlas.tps │ ├── pixieFrames.png │ ├── star.png │ ├── tileset.png │ ├── treasureHunter.json │ └── treasureHunter.png ├── chapter06 ├── 01_tilingSprites.html ├── 02_scrolling.html ├── 03_generateTexture.html ├── 04_renderTexture.html ├── 05_tinting.html ├── 06_masking.html ├── 07_blendModes.html ├── 08_filters.html ├── 09_rope.html ├── 10_tweening.html ├── 11_sceneTransitions.html ├── 12_motionPaths.html ├── es5 │ ├── blendModes.js │ ├── blendModes.js.map │ ├── filters.js │ ├── filters.js.map │ ├── generateTexture.js │ ├── generateTexture.js.map │ ├── masking.js │ ├── masking.js.map │ ├── motionPaths.js │ ├── motionPaths.js.map │ ├── renderTexture.js │ ├── renderTexture.js.map │ ├── rope.js │ ├── rope.js.map │ ├── sceneTransitions.js │ ├── sceneTransitions.js.map │ ├── scrolling.js │ ├── scrolling.js.map │ ├── tilingSprites.js │ ├── tilingSprites.js.map │ ├── tinting.js │ ├── tinting.js.map │ ├── tweening.js │ ├── tweening.js.map │ ├── video.js │ └── video.js.map ├── es6 │ ├── .motionPaths.js.swn │ ├── blendModes.js │ ├── filters.js │ ├── generateTexture.js │ ├── masking.js │ ├── motionPaths.js │ ├── renderTexture.js │ ├── rope.js │ ├── sceneTransitions.js │ ├── scrolling.js │ ├── tilingSprites.js │ ├── tinting.js │ └── tweening.js ├── fonts │ └── puzzler.otf └── images │ ├── animals.json │ ├── animals.png │ ├── clouds.png │ ├── pixie96x48.png │ ├── snake.png │ └── tile.png ├── chapter07 ├── 01_pointer.html ├── 02_spriteInteractivity.html ├── 03_dragAndDrop.html ├── 04_button.html ├── 05_interactiveSprite.html ├── 06_pixiePerilousness.html ├── es5 │ ├── button.js │ ├── button.js.map │ ├── dragAndDrop.js │ ├── dragAndDrop.js.map │ ├── ineractiveSprite.js │ ├── ineractiveSprite.js.map │ ├── interactiveSprite.js │ ├── interactiveSprite.js.map │ ├── pixiePerilousness.js │ ├── pixiePerilousness.js.map │ ├── pointer.js │ ├── pointer.js.map │ ├── spriteInteractivity.js │ └── spriteInteractivity.js.map ├── es6 │ ├── button.js │ ├── dragAndDrop.js │ ├── interactiveSprite.js │ ├── pixiePerilousness.js │ ├── pointer.js │ └── spriteInteractivity.js ├── images │ ├── 0.png │ ├── 1.png │ ├── 2.png │ ├── animals.json │ ├── animals.png │ ├── button.json │ ├── button.png │ ├── clouds.png │ ├── down.png │ ├── finish.png │ ├── green.png │ ├── greenBlock.png │ ├── over.png │ ├── pink.png │ ├── pixiePerilousness.json │ ├── pixiePerilousness.png │ ├── pixiePerilousness.tps │ ├── star.png │ ├── up.png │ ├── violet.png │ └── yellow.png └── texturePackerFiles │ ├── animals.tps │ └── button.tps └── learnPixiJS.zip /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "library/charm"] 2 | path = library/charm 3 | url = https://github.com/kittykatattack/charm 4 | [submodule "library/spriteUtilities"] 5 | path = library/spriteUtilities 6 | url = https://github.com/kittykatattack/spriteUtilities 7 | [submodule "library/keyboard"] 8 | path = library/keyboard 9 | url = https://github.com/kittykatattack/keyboard 10 | [submodule "library/scaleToWindow"] 11 | path = library/scaleToWindow 12 | url = https://github.com/kittykatattack/scaleToWindow 13 | [submodule "library/hitTestRectangle"] 14 | path = library/hitTestRectangle 15 | url = https://github.com/kittykatattack/hitTestRectangle 16 | [submodule "library/plugins/pixi.js"] 17 | path = library/plugins/pixi.js 18 | url = https://github.com/pixijs/pixi.js 19 | [submodule "library/tink"] 20 | path = library/tink 21 | url = https://github.com/kittykatattack/tink 22 | [submodule "library/bump"] 23 | path = library/bump 24 | url = git@github.com:kittykatattack/bump.git 25 | 26 | [submodule "library/contain"] 27 | path = library/contain 28 | url = https://github.com/kittykatattack/contain 29 | [submodule "library/dust"] 30 | path = library/dust 31 | url = git@github.com:kittykatattack/dust.git 32 | -------------------------------------------------------------------------------- /chapter01/01_helloWorld.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
tag called `output` 73 | output.innerHTML = "Pointer properties: \n pointer.x: " + pointer.x + " \n pointer.y: " + pointer.y + " \n pointer.isDown: " + pointer.isDown + " \n pointer.isUp: " + pointer.isUp + " \n pointer.tapped: " + pointer.tapped; 74 | } 75 | //# sourceMappingURL=pointer.js.map -------------------------------------------------------------------------------- /chapter07/es5/pointer.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["../es6/pointer.js"],"names":[],"mappings":";;;AACA,IAAI,SAAS,GAAG,IAAI,CAAC,SAAS;IAC5B,kBAAkB,GAAG,IAAI,CAAC,kBAAkB,CAAC;;;AAG/C,IAAI,KAAK,GAAG,IAAI,SAAS,EAAE;IACzB,QAAQ,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAC1C,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;;;AAGzC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,kBAAkB,CAAC;AAChD,QAAQ,CAAC,eAAe,GAAG,UAAU,CAAC;;;;;AAKtC,IAAI,KAAK,GAAG,IAAI,CAAC;;;AAGjB,IAAI,CAAC,YAAA;IAAE,OAAO,YAAA,CAAC;;AAEf,KAAK,EAAE,CAAC;;AAER,SAAS,KAAK,GAAG;;;AAGf,GAAC,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;;;AAGlC,SAAO,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;;;AAG1B,SAAO,CAAC,KAAK,GAAG;WAAM,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC;GAAA,CAAC;;;AAG7D,SAAO,CAAC,OAAO,GAAG;WAAM,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC;GAAA,CAAC;;;AAGhE,SAAO,CAAC,GAAG,GAAG;WAAM,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC;GAAA,CAAC;;;AAG1D,UAAQ,EAAE,CAAC;CACZ;;AAED,SAAS,QAAQ,GAAE;;;AAGjB,uBAAqB,CAAC,QAAQ,CAAC,CAAC;;;AAGhC,OAAK,EAAE,CAAC;;;AAGR,GAAC,CAAC,MAAM,EAAE,CAAC;;;AAGX,UAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;CACxB;;AAED,SAAS,IAAI,GAAG;;;;AAId,QAAM,CAAC,SAAS,iDAED,OAAO,CAAC,CAAC,8BACT,OAAO,CAAC,CAAC,mCACJ,OAAO,CAAC,MAAM,iCAChB,OAAO,CAAC,IAAI,mCACV,OAAO,CAAC,MAAM,AAAE,CAAC;CACtC","file":"pointer.js","sourcesContent":["//Aliases\nlet Container = PIXI.Container,\n autoDetectRenderer = PIXI.autoDetectRenderer;\n\n//Create a Pixi stage and renderer\nlet stage = new Container(),\n renderer = autoDetectRenderer(512, 512);\ndocument.body.appendChild(renderer.view);\n\n//Set the canvas's border style and background color\nrenderer.view.style.border = \"1px dashed black\";\nrenderer.backgroundColor = \"0xFFFFFF\";\n\n//let scale = scaleToWindow(renderer.view);\n\n//Set the initial game state\nlet state = play;\n\n//Define any variables that are used in more than one function\nlet t, pointer;\n\nsetup();\n \nfunction setup() {\n\n //Create a new instance of Tink\n t = new Tink(PIXI, renderer.view);\n\n //Create a `pointer` object\n pointer = t.makePointer();\n\n //Add a custom `press` method\n pointer.press = () => console.log(\"The pointer was pressed\");\n\n //Add a custom `release` method\n pointer.release = () => console.log(\"The pointer was released\");\n\n //Add a custom `tap` method\n pointer.tap = () => console.log(\"The pointer was tapped\");\n\n //Start the game loop\n gameLoop();\n}\n\nfunction gameLoop(){\n\n //Loop this function 60 times per second\n requestAnimationFrame(gameLoop);\n\n //Run the current state\n state();\n\n //Update Tink\n t.update();\n\n //Render the stage\n renderer.render(stage);\n}\n\nfunction play() {\n\n //Display the pointer properties in the \n //HTML
tag called `output`\n output.innerHTML\n = `Pointer properties: \n pointer.x: ${pointer.x} \n pointer.y: ${pointer.y} \n pointer.isDown: ${pointer.isDown} \n pointer.isUp: ${pointer.isUp} \n pointer.tapped: ${pointer.tapped}`;\n}\n"]} -------------------------------------------------------------------------------- /chapter07/es6/button.js: -------------------------------------------------------------------------------- 1 | //Aliases 2 | let Container = PIXI.Container, 3 | autoDetectRenderer = PIXI.autoDetectRenderer, 4 | Sprite = PIXI.Sprite, 5 | loader = PIXI.loader, 6 | resources = PIXI.loader.resources, 7 | Text = PIXI.Text; 8 | 9 | //Create a Pixi stage and renderer 10 | let stage = new Container(), 11 | renderer = autoDetectRenderer(256, 256); 12 | document.body.appendChild(renderer.view); 13 | 14 | //Set the canvas's border style and background color 15 | renderer.view.style.border = "1px dashed black"; 16 | renderer.backgroundColor = "0xFFFFFF"; 17 | 18 | //let scale = scaleToWindow(renderer.view); 19 | 20 | //load resources 21 | loader 22 | .add("images/button.json") 23 | .load(setup); 24 | 25 | //Set the initial game state 26 | let state = play; 27 | 28 | //Define any variables that are used in more than one function 29 | let t, playButton, id, stateMessage, actionMessage; 30 | 31 | function setup() { 32 | 33 | //Create a new instance of Tink 34 | t = new Tink(PIXI, renderer.view); 35 | 36 | //Get a reference to the texture atlas id's 37 | id = resources["images/button.json"].textures; 38 | 39 | //The button state textures 40 | let buttonFrames = [ 41 | id["up.png"], 42 | id["over.png"], 43 | id["down.png"] 44 | ]; 45 | 46 | //The `playButton` 47 | playButton = t.button(buttonFrames, 32, 96); 48 | 49 | //Add the button to the stage 50 | stage.addChild(playButton); 51 | 52 | //Define the button's actions 53 | playButton.over = () => console.log("over"); 54 | playButton.out = () => console.log("out"); 55 | playButton.press = () => console.log("pressed"); 56 | playButton.release = () => console.log("released"); 57 | playButton.tap = () => console.log("tapped"); 58 | 59 | //Add the `stageMessage` 60 | stateMessage = new Text( 61 | "State: ", 62 | {font: "18px Futura", fill: "black"} 63 | ); 64 | stateMessage.position.set(8, 8); 65 | stage.addChild(stateMessage); 66 | 67 | //Add the `actionMessage` 68 | actionMessage = new Text( 69 | "Action: ", 70 | {font: "18px Futura", fill: "black"} 71 | ); 72 | actionMessage.position.set(8, 32); 73 | stage.addChild(actionMessage); 74 | 75 | //Optionally create a `pointer` object 76 | //pointer = t.makePointer(); 77 | 78 | //Start the game loop 79 | gameLoop(); 80 | } 81 | 82 | function gameLoop(){ 83 | 84 | //Loop this function 60 times per second 85 | requestAnimationFrame(gameLoop); 86 | 87 | //Run the current state 88 | state(); 89 | 90 | //Update Tink 91 | t.update(); 92 | 93 | //Render the stage 94 | renderer.render(stage); 95 | } 96 | 97 | function play() { 98 | stateMessage.text = `State: ${playButton.state}`; 99 | actionMessage.text = `Action: ${playButton.action}`; 100 | } 101 | -------------------------------------------------------------------------------- /chapter07/es6/dragAndDrop.js: -------------------------------------------------------------------------------- 1 | //Aliases 2 | let Container = PIXI.Container, 3 | autoDetectRenderer = PIXI.autoDetectRenderer, 4 | Graphics = PIXI.Graphics, 5 | Sprite = PIXI.Sprite, 6 | loader = PIXI.loader, 7 | resources = PIXI.loader.resources, 8 | Text = PIXI.Text; 9 | 10 | //Create a Pixi stage and renderer 11 | let stage = new Container(), 12 | renderer = autoDetectRenderer(256, 256); 13 | document.body.appendChild(renderer.view); 14 | 15 | //Set the canvas's border style and background color 16 | renderer.view.style.border = "1px dashed black"; 17 | renderer.backgroundColor = "0xFFFFFF"; 18 | 19 | //let scale = scaleToWindow(renderer.view); 20 | 21 | //load resources 22 | loader 23 | .add("images/animals.json") 24 | .load(setup); 25 | 26 | //Set the initial game state 27 | let state = play; 28 | 29 | //Define any variables that are used in more than one function 30 | let t, pointer, rectangle, circle, id, cat, tiger, 31 | hedgehog, draggableObjects; 32 | 33 | function setup() { 34 | 35 | //Create a new instance of Tink 36 | t = new Tink(PIXI, renderer.view); 37 | 38 | //Get a reference to the texture atlas id's 39 | id = resources["images/animals.json"].textures; 40 | 41 | //The cat 42 | cat = new Sprite(id["cat.png"]); 43 | cat.position.set(32, 32); 44 | 45 | //The hedgehog 46 | hedgehog = new Sprite(id["hedgehog.png"]); 47 | hedgehog.position.set(64, 64); 48 | 49 | //The tiger 50 | tiger = new Sprite(id["tiger.png"]); 51 | tiger.position.set(96, 96); 52 | 53 | //Create a container for the draggable objects and 54 | //add the sprites to it 55 | draggableObjects = new Container(); 56 | draggableObjects.addChild(cat); 57 | draggableObjects.addChild(hedgehog); 58 | draggableObjects.addChild(tiger); 59 | 60 | //Add the `draggableObjects` to the stage 61 | stage.addChild(draggableObjects); 62 | 63 | //Make the sprites draggable 64 | t.makeDraggable(cat, tiger, hedgehog); 65 | 66 | //Optionally create a `pointer` object 67 | //pointer = t.makePointer(); 68 | 69 | //Start the game loop 70 | gameLoop(); 71 | } 72 | 73 | function gameLoop(){ 74 | 75 | //Loop this function 60 times per second 76 | requestAnimationFrame(gameLoop); 77 | 78 | //Run the current state 79 | state(); 80 | 81 | //Update Tink 82 | t.update(); 83 | 84 | //Render the stage 85 | renderer.render(stage); 86 | } 87 | 88 | function play() { 89 | 90 | } 91 | -------------------------------------------------------------------------------- /chapter07/es6/pointer.js: -------------------------------------------------------------------------------- 1 | //Aliases 2 | let Container = PIXI.Container, 3 | autoDetectRenderer = PIXI.autoDetectRenderer; 4 | 5 | //Create a Pixi stage and renderer 6 | let stage = new Container(), 7 | renderer = autoDetectRenderer(512, 512); 8 | document.body.appendChild(renderer.view); 9 | 10 | //Set the canvas's border style and background color 11 | renderer.view.style.border = "1px dashed black"; 12 | renderer.backgroundColor = "0xFFFFFF"; 13 | 14 | //let scale = scaleToWindow(renderer.view); 15 | 16 | //Set the initial game state 17 | let state = play; 18 | 19 | //Define any variables that are used in more than one function 20 | let t, pointer; 21 | 22 | setup(); 23 | 24 | function setup() { 25 | 26 | //Create a new instance of Tink 27 | t = new Tink(PIXI, renderer.view); 28 | 29 | //Create a `pointer` object 30 | pointer = t.makePointer(); 31 | 32 | //Add a custom `press` method 33 | pointer.press = () => console.log("The pointer was pressed"); 34 | 35 | //Add a custom `release` method 36 | pointer.release = () => console.log("The pointer was released"); 37 | 38 | //Add a custom `tap` method 39 | pointer.tap = () => console.log("The pointer was tapped"); 40 | 41 | //Start the game loop 42 | gameLoop(); 43 | } 44 | 45 | function gameLoop(){ 46 | 47 | //Loop this function 60 times per second 48 | requestAnimationFrame(gameLoop); 49 | 50 | //Run the current state 51 | state(); 52 | 53 | //Update Tink 54 | t.update(); 55 | 56 | //Render the stage 57 | renderer.render(stage); 58 | } 59 | 60 | function play() { 61 | 62 | //Display the pointer properties in the 63 | //HTML
tag called `output` 64 | output.innerHTML 65 | = `Pointer properties: 66 | pointer.x: ${pointer.x} 67 | pointer.y: ${pointer.y} 68 | pointer.isDown: ${pointer.isDown} 69 | pointer.isUp: ${pointer.isUp} 70 | pointer.tapped: ${pointer.tapped}`; 71 | } 72 | -------------------------------------------------------------------------------- /chapter07/es6/spriteInteractivity.js: -------------------------------------------------------------------------------- 1 | //Aliases 2 | let Container = PIXI.Container, 3 | autoDetectRenderer = PIXI.autoDetectRenderer, 4 | Graphics = PIXI.Graphics, 5 | Sprite = PIXI.Sprite, 6 | Text = PIXI.Text; 7 | 8 | //Create a Pixi stage and renderer 9 | let stage = new Container(), 10 | renderer = autoDetectRenderer(256, 256); 11 | document.body.appendChild(renderer.view); 12 | 13 | //Set the canvas's border style and background color 14 | renderer.view.style.border = "1px dashed black"; 15 | renderer.backgroundColor = "0xFFFFFF"; 16 | 17 | //let scale = scaleToWindow(renderer.view); 18 | 19 | //Set the initial game state 20 | let state = play; 21 | 22 | //Define any variables that are used in more than one function 23 | let t, pointer, rectangle, circle, message; 24 | 25 | setup(); 26 | 27 | function setup() { 28 | 29 | //Create a new instance of Tink 30 | t = new Tink(PIXI, renderer.view); 31 | 32 | //Make a rectangle and circle 33 | rectangle = new Graphics(); 34 | rectangle.beginFill(0x0033CC); 35 | rectangle.drawRect(0, 0, 64, 64); 36 | rectangle.endFill(); 37 | rectangle.x = 32; 38 | rectangle.y = 64; 39 | stage.addChild(rectangle); 40 | 41 | let circleGraphic = new Graphics(); 42 | circleGraphic.beginFill(0xFF0000); 43 | circleGraphic.drawCircle(0, 0, 32); 44 | circleGraphic.endFill(); 45 | 46 | //If you want the graphic to be anti-aliased, 47 | //convert it into a bitmap texture and then use 48 | //that texture to create a new sprite 49 | let circleTexture = circleGraphic.generateTexture(); 50 | circle = new Sprite(circleTexture); 51 | circle.x = 160; 52 | circle.y = 160; 53 | stage.addChild(circle); 54 | 55 | //Add a `circular` property to the circle 56 | circle.circular = true; 57 | 58 | //Create a `pointer` object 59 | pointer = t.makePointer(); 60 | 61 | message = new Text( 62 | "Hello Pixi!", 63 | {font: "18px Futura", fill: "black"} 64 | ); 65 | message.x = 8; 66 | message.y = 8; 67 | 68 | //Add the text to the stage 69 | stage.addChild(message); 70 | 71 | //Start the game loop 72 | gameLoop(); 73 | } 74 | 75 | function gameLoop(){ 76 | 77 | //Loop this function 60 times per second 78 | requestAnimationFrame(gameLoop); 79 | 80 | //Run the current state 81 | state(); 82 | 83 | //Update Tink 84 | t.update(); 85 | 86 | //Render the stage 87 | renderer.render(stage); 88 | } 89 | 90 | function play() { 91 | 92 | if (pointer.hitTestSprite(rectangle)) { 93 | message.text = "Rectangle!"; 94 | pointer.cursor = "pointer"; 95 | } 96 | else if (pointer.hitTestSprite(circle)) { 97 | message.text = "Circle!"; 98 | pointer.cursor = "pointer"; 99 | } 100 | 101 | else { 102 | message.text = "No collision..."; 103 | pointer.cursor = "auto"; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /chapter07/images/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/0.png -------------------------------------------------------------------------------- /chapter07/images/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/1.png -------------------------------------------------------------------------------- /chapter07/images/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/2.png -------------------------------------------------------------------------------- /chapter07/images/animals.json: -------------------------------------------------------------------------------- 1 | {"frames": { 2 | 3 | "cat.png": 4 | { 5 | "frame": {"x":2,"y":2,"w":64,"h":64}, 6 | "rotated": false, 7 | "trimmed": false, 8 | "spriteSourceSize": {"x":0,"y":0,"w":64,"h":64}, 9 | "sourceSize": {"w":64,"h":64}, 10 | "pivot": {"x":0.5,"y":0.5} 11 | }, 12 | "hedgehog.png": 13 | { 14 | "frame": {"x":68,"y":2,"w":64,"h":64}, 15 | "rotated": false, 16 | "trimmed": false, 17 | "spriteSourceSize": {"x":0,"y":0,"w":64,"h":64}, 18 | "sourceSize": {"w":64,"h":64}, 19 | "pivot": {"x":0.5,"y":0.5} 20 | }, 21 | "tiger.png": 22 | { 23 | "frame": {"x":134,"y":2,"w":64,"h":64}, 24 | "rotated": false, 25 | "trimmed": false, 26 | "spriteSourceSize": {"x":0,"y":0,"w":64,"h":64}, 27 | "sourceSize": {"w":64,"h":64}, 28 | "pivot": {"x":0.5,"y":0.5} 29 | }}, 30 | "meta": { 31 | "app": "http://www.codeandweb.com/texturepacker", 32 | "version": "1.0", 33 | "image": "animals.png", 34 | "format": "RGBA8888", 35 | "size": {"w":200,"h":68}, 36 | "scale": "1", 37 | "smartupdate": "$TexturePacker:SmartUpdate:aa42b222ddb3faeafaa3b7c9f66556ee:15b03a4eb0cd5b5d361ef8988283677a:b00d48b51f56eb7c81e25100fcce2828$" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /chapter07/images/animals.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/animals.png -------------------------------------------------------------------------------- /chapter07/images/button.json: -------------------------------------------------------------------------------- 1 | {"frames": { 2 | 3 | "down.png": 4 | { 5 | "frame": {"x":2,"y":2,"w":192,"h":96}, 6 | "rotated": false, 7 | "trimmed": false, 8 | "spriteSourceSize": {"x":0,"y":0,"w":192,"h":96}, 9 | "sourceSize": {"w":192,"h":96}, 10 | "pivot": {"x":0.5,"y":0.5} 11 | }, 12 | "over.png": 13 | { 14 | "frame": {"x":196,"y":2,"w":192,"h":96}, 15 | "rotated": false, 16 | "trimmed": false, 17 | "spriteSourceSize": {"x":0,"y":0,"w":192,"h":96}, 18 | "sourceSize": {"w":192,"h":96}, 19 | "pivot": {"x":0.5,"y":0.5} 20 | }, 21 | "up.png": 22 | { 23 | "frame": {"x":390,"y":2,"w":192,"h":96}, 24 | "rotated": false, 25 | "trimmed": false, 26 | "spriteSourceSize": {"x":0,"y":0,"w":192,"h":96}, 27 | "sourceSize": {"w":192,"h":96}, 28 | "pivot": {"x":0.5,"y":0.5} 29 | }}, 30 | "meta": { 31 | "app": "http://www.codeandweb.com/texturepacker", 32 | "version": "1.0", 33 | "image": "button.png", 34 | "format": "RGBA8888", 35 | "size": {"w":584,"h":100}, 36 | "scale": "1", 37 | "smartupdate": "$TexturePacker:SmartUpdate:11c74cd442a4b677289f3ad399b87054:879e99d58591d2495b4355ec40d3e079:c39245c3a59c1712d97d26c862b4cbc5$" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /chapter07/images/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/button.png -------------------------------------------------------------------------------- /chapter07/images/clouds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/clouds.png -------------------------------------------------------------------------------- /chapter07/images/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/down.png -------------------------------------------------------------------------------- /chapter07/images/finish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/finish.png -------------------------------------------------------------------------------- /chapter07/images/green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/green.png -------------------------------------------------------------------------------- /chapter07/images/greenBlock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/greenBlock.png -------------------------------------------------------------------------------- /chapter07/images/over.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/over.png -------------------------------------------------------------------------------- /chapter07/images/pink.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/pink.png -------------------------------------------------------------------------------- /chapter07/images/pixiePerilousness.json: -------------------------------------------------------------------------------- 1 | {"frames": { 2 | 3 | "0.png": 4 | { 5 | "frame": {"x":188,"y":2,"w":48,"h":32}, 6 | "rotated": false, 7 | "trimmed": false, 8 | "spriteSourceSize": {"x":0,"y":0,"w":48,"h":32}, 9 | "sourceSize": {"w":48,"h":32}, 10 | "pivot": {"x":0.5,"y":0.5} 11 | }, 12 | "1.png": 13 | { 14 | "frame": {"x":138,"y":2,"w":48,"h":32}, 15 | "rotated": false, 16 | "trimmed": false, 17 | "spriteSourceSize": {"x":0,"y":0,"w":48,"h":32}, 18 | "sourceSize": {"w":48,"h":32}, 19 | "pivot": {"x":0.5,"y":0.5} 20 | }, 21 | "2.png": 22 | { 23 | "frame": {"x":238,"y":2,"w":48,"h":32}, 24 | "rotated": false, 25 | "trimmed": false, 26 | "spriteSourceSize": {"x":0,"y":0,"w":48,"h":32}, 27 | "sourceSize": {"w":48,"h":32}, 28 | "pivot": {"x":0.5,"y":0.5} 29 | }, 30 | "clouds.png": 31 | { 32 | "frame": {"x":2,"y":198,"w":512,"h":512}, 33 | "rotated": false, 34 | "trimmed": false, 35 | "spriteSourceSize": {"x":0,"y":0,"w":512,"h":512}, 36 | "sourceSize": {"w":512,"h":512}, 37 | "pivot": {"x":0.5,"y":0.5} 38 | }, 39 | "finish.png": 40 | { 41 | "frame": {"x":2,"y":68,"w":377,"h":128}, 42 | "rotated": false, 43 | "trimmed": false, 44 | "spriteSourceSize": {"x":0,"y":0,"w":377,"h":128}, 45 | "sourceSize": {"w":377,"h":128}, 46 | "pivot": {"x":0.5,"y":0.5} 47 | }, 48 | "green.png": 49 | { 50 | "frame": {"x":70,"y":2,"w":32,"h":32}, 51 | "rotated": false, 52 | "trimmed": false, 53 | "spriteSourceSize": {"x":0,"y":0,"w":32,"h":32}, 54 | "sourceSize": {"w":32,"h":32}, 55 | "pivot": {"x":0.5,"y":0.5} 56 | }, 57 | "greenBlock.png": 58 | { 59 | "frame": {"x":288,"y":2,"w":64,"h":64}, 60 | "rotated": false, 61 | "trimmed": false, 62 | "spriteSourceSize": {"x":0,"y":0,"w":64,"h":64}, 63 | "sourceSize": {"w":64,"h":64}, 64 | "pivot": {"x":0.5,"y":0.5} 65 | }, 66 | "pink.png": 67 | { 68 | "frame": {"x":36,"y":2,"w":32,"h":32}, 69 | "rotated": false, 70 | "trimmed": false, 71 | "spriteSourceSize": {"x":0,"y":0,"w":32,"h":32}, 72 | "sourceSize": {"w":32,"h":32}, 73 | "pivot": {"x":0.5,"y":0.5} 74 | }, 75 | "violet.png": 76 | { 77 | "frame": {"x":2,"y":2,"w":32,"h":32}, 78 | "rotated": false, 79 | "trimmed": false, 80 | "spriteSourceSize": {"x":0,"y":0,"w":32,"h":32}, 81 | "sourceSize": {"w":32,"h":32}, 82 | "pivot": {"x":0.5,"y":0.5} 83 | }, 84 | "yellow.png": 85 | { 86 | "frame": {"x":104,"y":2,"w":32,"h":32}, 87 | "rotated": false, 88 | "trimmed": false, 89 | "spriteSourceSize": {"x":0,"y":0,"w":32,"h":32}, 90 | "sourceSize": {"w":32,"h":32}, 91 | "pivot": {"x":0.5,"y":0.5} 92 | }}, 93 | "meta": { 94 | "app": "http://www.codeandweb.com/texturepacker", 95 | "version": "1.0", 96 | "image": "pixiePerilousness.png", 97 | "format": "RGBA8888", 98 | "size": {"w":516,"h":712}, 99 | "scale": "1", 100 | "smartupdate": "$TexturePacker:SmartUpdate:f3f91be71403592d969834ad5bc7af1f:ce74fa4c4f38312bd308dde2ff0b3670:62ade53eba9d10066f0416c055f3358c$" 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /chapter07/images/pixiePerilousness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/pixiePerilousness.png -------------------------------------------------------------------------------- /chapter07/images/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/star.png -------------------------------------------------------------------------------- /chapter07/images/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/up.png -------------------------------------------------------------------------------- /chapter07/images/violet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/violet.png -------------------------------------------------------------------------------- /chapter07/images/yellow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/chapter07/images/yellow.png -------------------------------------------------------------------------------- /learnPixiJS.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kittykatattack/learnPixiJS/2f91d4bfeba7c6d5ab8057b2585a2cc2b78bcef3/learnPixiJS.zip --------------------------------------------------------------------------------