{"_id":"bump.js","_rev":"8-3768e224371a5c3bf0f7a786b8c32518","name":"bump.js","description":"A 2D Collision library for Pixi","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.0":{"name":"bump.js","version":"1.0.0","description":"A 2D Collision library for Pixi","main":"bin/bump.js","bin":{"bump.js":"bump.js"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/kittykatattack/bump.git"},"keywords":["collision","2d","pixi"],"author":{"name":"kittykatattack"},"license":"MIT","bugs":{"url":"https://github.com/kittykatattack/bump/issues"},"homepage":"https://github.com/kittykatattack/bump#readme","_id":"bump.js@1.0.0","_shasum":"6b2e43cd5229c3e6a049e9b69bbe40bfee20fe96","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.3.1","_npmUser":{"name":"happierall","email":"happierall@gmail.com"},"dist":{"shasum":"6b2e43cd5229c3e6a049e9b69bbe40bfee20fe96","tarball":"https://registry.npmjs.org/bump.js/-/bump.js-1.0.0.tgz","integrity":"sha512-AMq1OwvUyKNiEpd6I0gtjNDNwFGBM0H10Y2guys8HGVDdk/jmFc8G0BygzQ+tqY+MHFePJ0bV65AGjroP7eTDA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDR5Qwrd38QCOkKfW3zR/dSc/uMtxhYZfMim5N3AXHS1wIgBdxI/miJtgFygtt379sQr4O67xEQ4/OyjcMlPVooRTg="}]},"maintainers":[{"name":"happierall","email":"happierall@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/bump.js-1.0.0.tgz_1476015125113_0.5395232602022588"},"directories":{},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.0.1":{"name":"bump.js","version":"1.0.1","description":"A 2D Collision library for Pixi","main":"bin/bump.js","repository":{"type":"git","url":"git+https://github.com/kittykatattack/bump.git"},"keywords":["collision","2d","pixi"],"author":{"name":"kittykatattack"},"license":"MIT","bugs":{"url":"https://github.com/kittykatattack/bump/issues"},"homepage":"https://github.com/kittykatattack/bump#readme","_id":"bump.js@1.0.1","scripts":{},"_shasum":"f0722175f2b11ad5943baedbcade388add710b48","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.3.1","_npmUser":{"name":"happierall","email":"happierall@gmail.com"},"dist":{"shasum":"f0722175f2b11ad5943baedbcade388add710b48","tarball":"https://registry.npmjs.org/bump.js/-/bump.js-1.0.1.tgz","integrity":"sha512-PeKZdDigglcIt0ZMCMQwFJRseqz8qRds0qU1xDmFbhvLRNIpCY1vA2wcJCCVnq7gjSeXBhwOBbU+Dq8XW7k2RA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICDnhMkm+Hjc3Q3QbsWEEIfi1DnZM3J1ksEY1nw5XTrnAiBSFhnRfUGKR9TFulQ+sdV5vFzECcJyY+H2M24egAtWtQ=="}]},"maintainers":[{"name":"happierall","email":"happierall@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/bump.js-1.0.1.tgz_1476015367001_0.8411219636909664"},"directories":{},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.0.2":{"name":"bump.js","version":"1.0.2","description":"A 2D Collision library for Pixi","main":"bin/bump.js","repository":{"type":"git","url":"git+https://github.com/kittykatattack/bump.git"},"keywords":["collision","2d","pixi"],"author":{"name":"kittykatattack"},"license":"MIT","bugs":{"url":"https://github.com/kittykatattack/bump/issues"},"homepage":"https://github.com/kittykatattack/bump#readme","_id":"bump.js@1.0.2","scripts":{},"_shasum":"6076eb770128e5aa1991cb76128a3d60bc7ca851","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.3.1","_npmUser":{"name":"happierall","email":"happierall@gmail.com"},"dist":{"shasum":"6076eb770128e5aa1991cb76128a3d60bc7ca851","tarball":"https://registry.npmjs.org/bump.js/-/bump.js-1.0.2.tgz","integrity":"sha512-+HZkJnb0RNZJdCS/Iselsq731xb5J8DBQIx1Df0HC0047MVURQveRstJNFg7KD5MRqJg+IJqaIMEJDyhgawG4Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCCvWHsdIfzDBQCVlmHDK+HCkTtoYmeXdfMBykhEqlMYAIhAIIs3VJuKMUmfGgsROfOsjyN9qFye6DzBTqMJ+kRlhiK"}]},"maintainers":[{"name":"happierall","email":"happierall@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/bump.js-1.0.2.tgz_1476015817289_0.5328180112410337"},"directories":{},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."},"1.0.3":{"name":"bump.js","version":"1.0.3","description":"A 2D Collision library for Pixi","main":"bin/bump.js","repository":{"type":"git","url":"git+https://github.com/kittykatattack/bump.git"},"keywords":["collision","2d","pixi"],"author":{"name":"kittykatattack"},"license":"MIT","bugs":{"url":"https://github.com/kittykatattack/bump/issues"},"homepage":"https://github.com/kittykatattack/bump#readme","_id":"bump.js@1.0.3","scripts":{},"_shasum":"e0bd953d1ac46d60ab24610d7c632f92295cf8d4","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.3.1","_npmUser":{"name":"happierall","email":"happierall@gmail.com"},"dist":{"shasum":"e0bd953d1ac46d60ab24610d7c632f92295cf8d4","tarball":"https://registry.npmjs.org/bump.js/-/bump.js-1.0.3.tgz","integrity":"sha512-GVfgJeUbZVHjvxiT/RiFgxsilH9ILqzlr5HWfLVceBS+c26As8QdnjADKZJHbS1hUi0g8maOajjUOJrqCtYlVQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAaBjdSRUOqaqGSwicWVNsigZ7i7aGhoOfI4UY1i/eqxAiEA16OTZ9oX67uibovnN6esUeTXEPS4fYEgc6pSgRvI+SI="}]},"maintainers":[{"name":"happierall","email":"happierall@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/bump.js-1.0.3.tgz_1476016502223_0.12468137196265161"},"directories":{},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."}},"readme":"Bump - A 2D Collision library for Pixi\n========================================\n\nBump is a lightweight suite of easy-to-use 2D collision methods for use with the\nPixi rendering engine. You can use these methods to make almost any\nkind of 2D action or arcade game.\n\n[Setting up](#settingup) <br>\n[Using Bump's collision methods](#using) <br>\n[Hit](#hit): A universal collision detection method <br>\n[hitTestPoint](#hittestpoint): Check whether a point is intersecting a sprite <br>\n[hitTestCircle](#hittestcircle): Check whether 2 circles are touching <br>\n[circleCollision](#circlecollision): Bounce a moving circle against a stationary circle <br>\n[movingCircleCollision](#movingcirclecollision): Bounce two moving circles apart <br>\n[hitTestRectangle](#hittestrectangle): Check whether two rectangular or square sprites are touching <br>\n[rectangleCollision](#rectanglecollision): Prevent two rectangular sprites from intersecting <br>\n[hitTestCircleRectangle](#hittestcirclerectangle): Check whether a rectangular and circular sprite are touching<br>\n[circleRectangleCollision](#circlerectanglecollision): Bounce a circular sprite against a rectangular sprite <br>\n[contain](#contain): Contain a sprite inside the boundaries of another rectangular sprite <br>\n\n<a id=\"settingup\"></a>\nInstalling and setting up Bump\n------------------------------\n\nUse a `<script>` tag to link the `bump.js` file to your HTML document.\n```\n<script src=\"bump.js\"></script>\n```\n(If you prefer, you can load `bump.js` using any JavaScript module\nsystem you might be familiar working with: ES6 modules, SystemJS, AMD or CommonJS.) \nThe Bump source files contain both ES5 and ES6 versions of the\n`bump.js` code. You should probably use the ES5 version for production\ncode.\n\nNext, create a new instance of Bump at the beginning of your program.\nSupply the renderer you want to use in the constructor (the defautl is `PIXI`) like this:\n```\nb = new Bump(PIXI);\n```\nThe variable `b` (for \"bump\", of course!) now represents the running\ninstance of Bump that you can use to access all of Bump’s collision methods.\n\n<a id=\"using\"></a>\nUsing Bump's collision methods\n------------------------------\n\nUsing Bump is just a matter of choosing the collision method you want to\nuse, and applying it based on the examples ahead. Just append `b` (or\nwhatever variable name you chose for the Bump instance) to the\nbeginning of each method, like this:\n```js\nb.hitTestRectangle(spriteOne, spriteTwo);\n```\nHere are all the collision methods you can use:\n\n<a id=\"hit\"></a>\n###`hit`\n\n`hit` is a universal collision function. It automatically detects the\nkinds of sprites that are being used in the collision and chooses the\nappropriate collision function for you. This means that instead of\nhaving to remember which of the many collision functions in Bump's\nlibrary to use, you only need remember one: `hit`.\n\nIn its simplest form, you can use `hit` like this: \n```\nhit(spriteOne, spriteTwo)\n```\nIt will return `true` if the sprites are touching and `false` if they\naren't.\nAnd that’s all you need to know to start making some truly captivating games!\n\nThe sprites can be circles or rectangles. Bump's methods assumes\nthey're rectangular by default. But if you want the methods to\ninterpret a sprite as circular, give it a `circular` property and set\nit to `true`.\n```js\nanySprite.circular = true;\n```\nIf you want the sprites to react to the collision, so that they don’t\nintersect, set the third argument to `true`. \n```js\nhit(spriteOne, spriteTwo, true)\n```\nThis prevents them from overlapping, so it's useful for making walls,\nfloors, or any other kind of solid boundary.\n\nIf you want the sprites to bounce apart, set the fourth argument to `true`. \n```js\nhit(spriteOne, spriteTwo, true, true)\n```\nNow your sprites will bounce!\n\nSetting the fifth argument to `true`  makes the `hit` method  use the\nsprites’ **global coordinates**.\n```\nhit(spriteOne, spriteTwo, true, true, true)\n```\nThe global coordinates are the sprites positions relative to the\ncanvas's top left corner, instead of the top left corner of their\nparent container (their local coordinates.)\n\nIf you want to check a point object for a collision against a sprite, use the point as the first argument,\nlike this:\n```js\nhit({x: 145, y:65}, sprite)\n```\nA point object is just any object with two properties, `x` and `y`, that\ndefine the point's position.\n\nThe `hit` method also lets you check for a collision between a sprite and an array of sprites. Just include\nthe array as the second argument. In this example the array is called\n`bricks.children`:\n```js\nhit(ball, bricks.children, true, true, true);\n```\nYou'll see that `hit` automatically loops through all the sprites in\nthe array for you and checks them against the first sprite. This means\nyou don’t have to write your own `for` loop or `forEach` loop.\n\nThe `hit` function also returns a collision object, with a return\nvalue that matches the kinds of sprites you’re checking. For example, \nif both sprites are rectangles, you could find the side on which the collision occurred like this:\n```js\nlet collision = hit(rectangleOne, rectangleTwo, true);\nmessage.text = \"collision side: \" + collision;\n```\n`collision` will always be `undefined` if there’s no collision.\n\nA final feature is that you can use an optional callback function as\nthe sixth argument. This lets you inject some extra code that should \nrun when the collision occurs. This is especially useful for checking a \ncollision between a single sprite and an array of sprites. If there’s a \ncollision, the callback will run, and you can access both the collision \nreturn value and the sprite involved in the collision. Here’s how you \ncould use this feature to check for a collision between a sprite\ncalled `player` and an array of sprites in an array called `world.platforms`:\n```js\nlet playerVsPlatforms = hit(\n  player, \n  world.platforms, \n  true, false, false, \n  function(collision, platform){\n\n    //`collision` tells you the side on player that the collision occurred on.\n    //`platform` is the sprite from the `world.platforms` array\n    //that the player is colliding with\n  }\n);\n```\nThis is a compact way of doing complex collision checks that gives you a \nlot of information and low-level control but saves you from having to \nmanually loop through all the sprites in the array.\n\nHowever, the `hit` method is just a high-level wrapper for Bump's many\nlower level collision methods. If you prefer to use the lower-level\nmethods, they're all listed next.\n\n<a id=\"hittestpoint\"></a>\n###`hitTestPoint`\n\nThe most basic collision test is to check whether a point is\nintersecting a sprite. `hitTestPoint` will help you to figure this out. \n`hitTestPoint` takes two arguments: a point object with `x` and `y`\nproperties, and a sprite:\n```js\nhitTestPoint(\n  {x: 128, y: 128},  //An object with `x` and `y` properties \n  anySprite          //A sprite\n)\n```\n`hitTestPoint` will return `true` if the point intersects the sprite,\nand `false` if it doesn’t. \n\nThe `hitTestPoint` method works equally well with rectangular and \ncircular sprites. If the sprite has a `radius` property, `hitTestPoint` \nassumes that the sprite is circular and applies a point collision detection \nalgorithm for circles. If the sprite doesn’t have a `radius` property, the \nmethod assumes it is a square. You can give any sprite a `radius`\nproperty. An easy way to do this is to give the sprite a `circular` property and set\nit to `true`.\n```js\nanySprite.circular = true;\n```\nThe sprite will now be interpreted as circular and have a new `radius`\nproperty which is equal to half the sprite's width.\n\n<a id=\"hittestcircle\"></a>\n###`hitTestCircle`\n\nIf you want to check for a collision between two circular sprites, \nuse the `hitTestCircle` method: \n```js\nhitTestCircle(sprite1, sprite2)\n```\nUse it with any sprite that has a `radius` property. It returns `true` \nif the circles are touching, so you can use it with an `if` statement to check for a \ncollision, like this:\n```js\nif (hitTestCircle(sprite1, sprite2)) {\n  //The circles are touching\n}\n```\n\n<a id=\"circlecollision\"></a>\n###`circleCollision`\n\nIf a moving circle hits a non-moving circle, you can create a collision \nreaction using the `circleCollision` method:\n```js\ncircleCollision(circle1, circle2, true);\n```\nThis stops the circles from intersecting.\n\nThe first argument is the moving ball, and the second is the\nnon-moving ball. The third argument is an optional Boolean that\ndetermines whether the first circle should bounce off the second. (The\nBoolean will default to `false` if you leave it out, so if you want the\ncircles to bounce, set it to `true`. You probably want to do this!)\n\nThere's an optional fourth argument that, if you set it to `true`,\nmakes the method use the sprites’ global coordinates. This is important \nif you want to check for collisions between sprites that have different \nparent containers.\n\n<a id=\"movingcirclecollision\"></a>\n###`movingCircleCollision`\n\nYou can create a collision reaction between two moving circles using \nthe `movingCircleCollision` method. Supply two circular sprites as arguments:\n```js\nmovingCircleCollision(circle1, circle2)\n```\nIf the circles have a `mass` property, that value will be used to help \nfigure out the force with which the circles should bounce off each other.\nThe `movingCircleCollision` method makes the sprites bounce apart by default.\nAn important feature of this method is that when two moving circles collide, \nthey transfer their velocities to each other in a way that makes them bounce \napart very realistically. \n\n####Checking for multiple collisions\n\nIf you have a bunch of moving circles, like marbles,\nyou need to check for a collision between each of them on every frame\nof your game loop. To do this you need to make sure that no pair of marbles \nis checked for collisions with each other more than once. The key to making \nthis work is to use a nested `for` loop and to start the counter of the inner \nloop by one greater than the outer loop. Here’s some example code that\nusing the `movingCircleCollision` method to make an array of marbles bounce off \neach other (the marble sprites are in an array called\n`marbles.children`):\n```js\nfor (let i = 0; i < marbles.children.length; i++) {\n\n  //The first marble to use in the collision check\n  var c1 = marbles.children[i];\n  for (let j = i + 1; j < marbles.children.length; j++) {\n\n    //The second marble to use in the collision check\n    let c2 = marbles.children[j];\n\n    //Check for a collision and bounce the marbles apart if they collide\n    movingCircleCollision(c1, c2);\n  }\n}\n```\nYou can see that the inner loop starts at a number that’s one greater than the outer loop:\n```js\nlet j = i + 1\n```\nThis prevents any pair of objects from being checked for collisions more than once.\n\nThe Bump library also has a convenience method called\n`multipleCircleCollision` that automates this entire nested for loop for you. \nYou can use it in a game loop to check all the sprites in an array with all the \nother sprites in the same array, without duplication. Use it like this:\n```js\nmultipleCircleCollision(marbles.children)\n```\nIt will automatically call `movingCircleCollision` on each pair of sprites to make \nthem bounce off one another. You now know most of the important techniques you need \nto make a wide range of games using circular sprites.\n\n<a id=\"hittestrectangle\"></a>\n###`hitTestRectangle`\n\nTo find out whether two rectangular sprites are overlapping, use a function called \n`hitTestRectangle`:\n```js\nhitTestRectangle(rectangle1, rectangle2)\n```\n`hitTestRectangle` returns `true` if the rectangles overlap, and\n`false` if they don't. You can use it in a simple collision test like\nthis:\n```js\nif (hitTestRectangle(rectangle1, rectangle2)) {\n  //The rectangles are touching\n} else {\n  //They're not touching\n}\n```\n\n<a id=\"rectanglecollision\"></a>\n###`rectangleCollision`\n\n`rectangleCollision` make the rectangles behave as though they have\nsolid mass. It prevents any of the rectangular sprites in its first \ntwo arguments from overlapping:\n```js\nrectangleCollision(rectangle1, rectangle2)\n```\n`rectangleCollision` also returns a string, whose value may be \"left\", \n\"right\", \"top\", or \"bottom\", that tells you which side of the first \nrectangle touched the second rectangle. You can assign the return \nvalue to a variable and use the information in your game. Here’s how:\n```js\nlet collision = rectangleCollision(rectangle1, rectangle2);\n\n//On which side of rectangle1 is the collision occuring?\nswitch (collision) {\n  case \"left\":\n    message.text = \"Collision on left\";\n    break;\n  case \"right\":\n    message.text = \"Collision on right\";\n    break;\n  case \"top\":\n    message.text = \"Collision on top\";\n    break;\n  case \"bottom\":\n    message.text = \"Collision on bottom\";\n    break;\n  default:\n    message.text = \"No collision...\";\n}\n```\n`collision` has a default value of `undefined`.\nThis example code will prevent the rectangles from overlapping and\ndisplays the collision side in a text sprite called `message`.\n\nThe `rectangleCollision` method has a very useful side effect. \nThe second sprite in the argument has the ability to push the first \nsprite out of the way. If you need to add a block-pushing or \ntile-sliding feature to a game, use this feature.\n\n`rectangleCollision` has a third, optional Boolean argument, `bounce`: \n```js\nrectangleCollision(rectangle1, rectangle2, true)\n```\nIf `bounce` is `true`, it makes the first sprite bounce off the second \nsprite when they collide. Its default value is `false`. (As with the all \nthe other collision methods, you should set the final optional argument, \n`global`, to `true` if you want to use the sprites’ global coordinates.)\n\n<a id=\"hittestcirclerectangle\"></a>\n###`hitTestCircleRectangle`\n\n`hitTestCircleRectangle` checks for a collision between a circular and\nrectangular sprite. The first argument is the circular sprite, and the \nsecond is the rectangular sprite:\n```js\nlet collision = hitTestCircleRectangle(ball, box);\n```\nIf they’re touching, the return value (collision) will tell you where \nthe circle is hitting the rectangle. It can have the value \"topLeft\", \n\"topMiddle\", \"topRight\", \"leftMiddle\", \"rightMiddle\", \"bottomLeft\", \n\"bottomMiddle\", or \"bottomRight\". If there’s no collision it will be\n`undefined`.\n\n<a id=\"circlerectanglecollision\"></a>\n###`circleRectangleCollision`\n\nUse `circleRectangleCollision` to make a circle bounce off a square’s sides or corners:\n```js\ncircleRectangleCollision(ball, box, true);\n```\nSetting the optional third argument to `true` makes the sprites bounce apart, \nand setting the fourth argument to `true` tells the method to use the \nsprites’ global coordinates.\n\n<a id=\"contain\"></a>\n###`contain`\n\n`contain` can be used to contain a sprite with `x` and\n`y` properties inside a rectangular area.\n\nThe `contain` function takes four arguments: a sprite with `x` and `y`\nproperties, an object literal with `x`, `y`, `width` and `height` properties. The \nthird argument is a Boolean (true/false) value that determines if the sprite\nshould bounce when it hits the edge of the container. The fourth argument\nis an extra user-defined callback function that you can call when the\nsprite hits the container. (Only the first two arguments are required.)\n```js\ncontain(anySprite, {x: 0, y: 0, width: 512, height: 512}, true, callbackFunction);\n```\nThe code above will contain the sprite's position inside the 512 by\n512 pixel area defined by the object. If the sprite hits the edges of\nthe container, it will bounce. The `callBackFunction` will run if \nthere's a collision.\n\nAn additional feature of the `contain` method is that if the sprite\nhas a `mass` property, that value will be used to dampen the sprite's bounce\nin a natural looking way.\n\nIf the sprite bumps into any of the containing object's boundaries,\nthe `contain` function will return a Set of string values that tells you which side\nthe sprite bumped into: “left”, “top”, “right” or “bottom”. Here's how\nyou could keep the sprite contained and also find out which boundary\nit hit:\n```js\n//Contain the sprite and find the collision value\nlet collision = contain(anySprite, {x: 0, y: 0, width: 512, height: 512});\n\n//If there's a collision, display the boundary that the collision happened on\nif(collision) {\n  if collision.has(\"left\") console.log(\"The sprite hit the left\");  \n  if collision.has(\"top\") console.log(\"The sprite hit the top\");  \n  if collision.has(\"right\") console.log(\"The sprite hit the right\");  \n  if collision.has(\"bottom\") console.log(\"The sprite hit the bottom\");  \n}\n```\nIf the sprite doesn't hit a boundary, the value of\n`collision` will be `undefined`. \n\n\n","maintainers":[{"email":"npm@npmjs.com","name":"npm"}],"time":{"modified":"2023-08-21T03:06:56.628Z","created":"2016-10-09T12:12:07.356Z","1.0.0":"2016-10-09T12:12:07.356Z","1.0.1":"2016-10-09T12:16:08.974Z","1.0.2":"2016-10-09T12:23:39.232Z","1.0.3":"2016-10-09T12:35:04.165Z"},"homepage":"https://github.com/kittykatattack/bump#readme","keywords":["collision","2d","pixi"],"repository":{"type":"git","url":"git+https://github.com/kittykatattack/bump.git"},"author":{"name":"kittykatattack"},"bugs":{"url":"https://github.com/kittykatattack/bump/issues"},"license":"MIT","readmeFilename":"README.md"}