Git Product home page Git Product logo

Comments (10)

drewsilcock avatar drewsilcock commented on May 22, 2024 2

Just submitted a PR (#19) adding the file to the typings directory along with a README telling people how to install using typings. Typings isn't the most up-to-date way to do TypeScript definitions, so ideally you'd have an addition to the DefinitelyTyped repository. Instructions for how to do this are here: https://github.com/DefinitelyTyped/DefinitelyTyped.

Note that I haven't really been able to test this - it's intended as an initial push so that anyone who's using TypeScript can improve and/or fix this as needed. Unfortunately this isn't something I've got time to do at the moment.

from phaser-kinetic-scrolling-plugin.

CyrilleGuimezanes avatar CyrilleGuimezanes commented on May 22, 2024 1

Hello!
If needed, I wrote a quick TS Typings file for the plugin:

declare module Phaser {
module Plugin {
export class KineticScrolling extends Phaser.Plugin {
constructor(game:Phaser.Game, parent:any);
setup(params: any): void;
start();
configure(params: any);
//other methods if needed
}
}
interface Game {
kineticScrolling: Plugin.KineticScrolling;
}
}
declare module 'phaser-kinetic-scrolling-plugin' {
}

(sorry for bad indent)

And then, you juste have to include your JS or require() it for Webpack users.

To be more complete:

  • Define all public plugin methods
  • Define clearly params: any

Have fun!

from phaser-kinetic-scrolling-plugin.

drewsilcock avatar drewsilcock commented on May 22, 2024 1

More detailed typings file for this plugin, with comments copied over from source code:

declare module Phaser {
    module Plugin {
        /**
         * Settings to change behaviour of Kinetic Scrolling plugin.
         */
        interface KineticScrollingSettings {
            /**
             * Enable or disable the kinematic motion.
             */
            kineticMovement?: boolean;

            /**
             * The rate of deceleration for the scrolling.
             */
            timeConstantScroll?: number;

            /**
             * Enable or disable the horizontal scrolling.
             */
            horizontalScroll?: boolean;

            /**
             * Enable or disable the vertical scrolling.
             */
            verticalScroll?: boolean;

            /**
             * Enable or disable the horizontal scrolling with the mouse wheel.
             */
            horizontalWheel?: boolean;

            /**
             * Enable or disable the vertical scrolling with the mouse wheel.
             */
            verticalWheel?: boolean;

            /**
             * Delta increment of the mouse wheel.
             */
            deltaWheel?: number;
        }

        /**
         * Kinetic Scrolling is a Phaser plugin that allows vertical and horizontal scrolling with kinetic motion.
         * It works with the Phaser.Camera
         */
        export class KineticScrolling extends Phaser.Plugin {
            /**
             * @param game The Game object is the instance of the game, where the magic happens.
             * @param parent The object that owns this plugin, usually Phaser.PluginManager.
             */
            constructor(game: Phaser.Game, parent: Phaser.PluginManager);

            /**
             * Start the Plugin.
             */
            public start(): void;

            /**
             * Stop the Plugin.
             */
            public stop(): void;

            /**
             * Change Default Settings of the plugin
             * @param options Object that contain properties to change the behavior of the plugin.
             */
            public configure(options: KineticScrollingSettings): void;
        }
    }

    interface Game {
        /**
         * Instance of the plugin that handles kinetic scrolling with mouse, dragging or mouse wheel.
         */
        kineticScrolling: Plugin.KineticScrolling;
    }
}

declare module "phaser-kinetic-scrolling-plugin" { }

from phaser-kinetic-scrolling-plugin.

jdnichollsc avatar jdnichollsc commented on May 22, 2024

Check the examples! You need to load the plugin into the states 👍

Regards, Nicholls

from phaser-kinetic-scrolling-plugin.

rayhvh avatar rayhvh commented on May 22, 2024

i did not get it to work. i think its because you wrote it in javascript. and im using typescript.

from phaser-kinetic-scrolling-plugin.

jdnichollsc avatar jdnichollsc commented on May 22, 2024

I need to do tests with TypeScript.

from phaser-kinetic-scrolling-plugin.

DanielContreras18881 avatar DanielContreras18881 commented on May 22, 2024

This is not working for me, anybody has a example project with Phaser 2.6 and Typescript?

from phaser-kinetic-scrolling-plugin.

jdnichollsc avatar jdnichollsc commented on May 22, 2024

Ohh I need to add the typings file to support TypeScript...
@drewsilcock do you want to be a collaborator of this project and add your example? 👍

Let me know what you think

from phaser-kinetic-scrolling-plugin.

jdnichollsc avatar jdnichollsc commented on May 22, 2024

@CyrilleGuimezanes @drewsilcock where is the best place in the repository to have the TypeScript definition files? any example of other plugin?

from phaser-kinetic-scrolling-plugin.

jdnichollsc avatar jdnichollsc commented on May 22, 2024

Added, thanks for the help guys!

from phaser-kinetic-scrolling-plugin.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.