I'm pretty new to javascript and typescript and I'm having difficulty adding a library to my project.
I have a phaser.io typescript project in VS2017 and I'm trying to add this library to it:
https://github.com/flogvit/phaser-swipe
I've copied the definitions file into my folder "tsDefinitions\\phaser-swipe.d.ts" and copied the js file into "build\\libs\\swipe.js"
I added a reference to the definition file in my project.
/// <reference path="phaser-swipe.d.ts" />
When I try to create the swipe class like in the documents I get the error "Cannot find name Swipe".
My Level01.ts:
export class Level01 extends Phaser.State {
background: Phaser.Sprite;
music: Phaser.Sound;
player: Player;
swipe: Swipe;
create() {
this.background = this.add.sprite(0, 0, 'level01-sprites','background');
this.player = new Player(this.game, this.world.centerX, this.world.centerX);
this.player.anchor.setTo(0, 5);
//Here is where the intellisense error is occurring
this.swipe = new Swipe(this.game);
}
}
Quick Actions adds the following to the top of the file, but it then breaks Phaser.Player and other references by giving the same "Cannot find name Player" error.
import Swipe from "phaser-swipe";
swipe.js: https://github.com/flogvit/phaser-swipe/blob/master/swipe.js
phaser-swipe.d.ts: https://github.com/flogvit/phaser-swipe/blob/master/phaser-swipe.d.ts
Am I missing something here? How can I get the definitions file to work correctly? Thanks!
Just a wild guess that you should try making it a variable like
var Swipe = require('phaser-swipe');
//Then in your create
this.swipe = new Swipe(this.game);
//then in the update it'll be all just depending how you want to use it.
Always check your comas”,” and this”;” cz a simple coma can give you errors trust me I know x) hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.