项目作者: proyecto26

项目描述 :
Kinetic Scrolling plugin for Canvas using Phaser Framework
高级语言: JavaScript
项目地址: git://github.com/proyecto26/Phaser-Kinetic-Scrolling-Plugin.git
创建时间: 2015-07-10T04:54:31Z
项目社区:https://github.com/proyecto26/Phaser-Kinetic-Scrolling-Plugin

开源协议:MIT License

下载




MIT license


Current npm package version


Maintenance





Downloads


Total downloads


Follow @jdnichollsc

Kinetic Scrolling Plugin for Phaser Framework

Kinetic Scrolling Plugin

The vertical and horizontal scrolling is a very useful feature in the games for example to display a section of levels and with this plugin you can simulate the scrolling within a canvas element of HTML5… so check this awesome plugin for Phaser Framework!

Kinetic scrolling based on http://ariya.ofilabs.com/2013/11/javascript-kinetic-scrolling-part-2.html

Download the Plugin

NPM

Install via bower

bower i phaser-kinetic-scrolling-plugin --save

Install via npm

npm i phaser-kinetic-scrolling-plugin --save

Load the Plugin

  1. this.game.kineticScrolling = this.game.plugins.add(Phaser.Plugin.KineticScrolling);

Change Default Settings of the Plugin - It isn’t necessary, default is horizontal

  1. this.game.kineticScrolling.configure({
  2. kineticMovement: true,
  3. timeConstantScroll: 325, //really mimic iOS
  4. horizontalScroll: true,
  5. verticalScroll: false,
  6. horizontalWheel: true,
  7. verticalWheel: false,
  8. deltaWheel: 40,
  9. onUpdate: null //A function to get the delta values if it's required (deltaX, deltaY)
  10. });

Start the Plugin

  1. this.game.kineticScrolling.start();

Stop the Plugin

  1. this.game.kineticScrolling.stop();

Full Example

  1. var game = new Phaser.Game(1024, 768, Phaser.AUTO, '', {
  2. init: function () {
  3. //Load the plugin
  4. this.game.kineticScrolling = this.game.plugins.add(Phaser.Plugin.KineticScrolling);
  5. //If you want change the default configuration before start the plugin
  6. },
  7. create: function () {
  8. //Starts the plugin
  9. this.game.kineticScrolling.start();
  10. //If you want change the default configuration after start the plugin
  11. this.rectangles = [];
  12. var initX = 50;
  13. for (var i = 0; i < 26; i++) {
  14. this.rectangles.push(this.createRectangle(initX, this.game.world.centerY - 100, 250, 200));
  15. this.index = this.game.add.text(initX + 125, this.game.world.centerY, i + 1,
  16. { font: 'bold 150px Arial', align: "center" });
  17. this.index.anchor.set(0.5);
  18. initX += 300;
  19. }
  20. //Changing the world width
  21. this.game.world.setBounds(0, 0, 320 * this.rectangles.length, this.game.height);
  22. },
  23. createRectangle: function (x, y, w, h) {
  24. var sprite = this.game.add.graphics(x, y);
  25. sprite.beginFill(Phaser.Color.getRandomColor(100, 255), 1);
  26. sprite.bounds = new PIXI.Rectangle(0, 0, w, h);
  27. sprite.drawRect(0, 0, w, h);
  28. return sprite;
  29. }
  30. });

Examples

The repository has some examples of the plugin, to run the examples created by the community execute the command gulp examples from the terminal:

  • Horizontal scrolling
  • Horizontal scrolling with scrollbar
  • Horizontal scrolling and pressing events
  • Horizontal and Vertical scrolling (Mouse wheel too)
  • onUpdate callback to track delta

Other Projects

Contributing ✨

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated ❤️.
You can learn more about how you can contribute to this project in the contribution guide.

Collaborators ✨

jdnichollsc daniel-mf VitaZheltyakov iamchristopher daaaabeen
Nicholls Daniel zhelt@yandex.ru">Vitaliy Chris Wright Daaaabeen

Supporting 🍻

I believe in Unicorns 🦄
Support me, if you do too.

Donate Ethereum, ADA, BNB, SHIBA, USDT/USDC, DOGE, etc:

Wallet address: jdnichollsc.eth

Please let us know your contributions! 🙏

License ⚖️

This repository is available under the MIT License.

Happy scrolling 💯

Made with <3