Marwane2185 Posted April 14, 2015 Share Posted April 14, 2015 Hi, i'm using this file in my project : /*Copyright © 2013 Marian Euent Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.*//* @param {Object} object: Any object you want to tween. For example: PIXI.Sprite @param {String} property: the property which needs to be changed. Use "property.property.property..." if the property is little deeper. Pass "" to create a Wait-Tween @param {float} value: targetValue of tweening @param {int} frames: duration of the tween in frames. @param {boolean} autostart: starting when created? Set to false if you use it with ChainedTween use examples: new Tween(sprite, "position.x", 100, 60, true); new Tween(sprite.position, "x", 100, 60, true); */function Tween(object, property, value, frames, autostart) { this.object = object; var properties = property.split("."); this.property = properties[properties.length - 1]; for (var i = 0; i < properties.length - 1; i++) { this.object = this.object[properties]; } this.targetValue = value; this.startValue; this.active = autostart; this.currentFrame = 0; this.endFrame = frames; this.onComplete; this.onCompleteParams; this.easing = Tween.noEase; Tween.tweens.push(this);}Tween.noEase = function (t, b, c, d) { t /= d; return b + c * (t);};Tween.prototype.setOnComplete = function (callback, parameters) { this.onComplete = callback; this.onCompleteParams = parameters;};Tween.prototype.start = function () { this.active = true;};Tween.prototype.initIterations = function () { if (this.property != "") { this.startValue = this.object[this.property]; this.targetValue = this.targetValue - this.object[this.property]; }};Tween.prototype.update = function () { if (!this.active) { return false; } if (this.currentFrame == 0) { this.initIterations(); } this.currentFrame++; if (this.currentFrame <= this.endFrame) { if (this.property != "") { var oldValue = this.object[this.property]; var newValue = this.easing(this.currentFrame, this.startValue, this.targetValue, this.endFrame); this.object[this.property] = newValue; } return false; } else { this.active = false; if (this.onComplete != null) { this.onComplete(this.onCompleteParams); } return true; }};Tween.tweens = [];// Call this every Frame of your Game/Application to keep the tweens running.Tween.runTweens = function () { for (var i = 0; i < Tween.tweens.length; i++) { var tween = Tween.tweens; if (tween.update()) { var index = Tween.tweens.indexOf(tween); if (index != -1) { Tween.tweens.splice(index, 1); } i--; } }};// EASING// use example:// var tween = new Tween(sprite, "alpha", 0, 60, true);// tween.easing = Tween.outElastic;Tween.outElastic = function (t, b, c, d) { var ts = (t /= d) * t; var tc = ts * t; return b + c * (33 * tc * ts + -106 * ts * ts + 126 * tc + -67 * ts + 15 * t);};Tween.inElastic = function (t, b, c, d) { var ts = (t /= d) * t; var tc = ts * t; return b + c * (56 * tc * ts + -105 * ts * ts + 60 * tc + -10 * ts);};Tween.inOutQuintic = function (t, b, c, d) { var ts = (t /= d) * t; var tc = ts * t; return b + c * (6 * tc * ts + -15 * ts * ts + 10 * tc);};Tween.inQuintic = function (t, b, c, d) { var ts = (t /= d) * t; var tc = ts * t; return b + c * (tc * ts);};Tween.outQuintic = function (t, b, c, d) { var ts = (t /= d) * t; var tc = ts * t; return b + c * (tc * ts + -5 * ts * ts + 10 * tc + -10 * ts + 5 * t);};Tween.inCubic = function (t, b, c, d) { var tc = (t /= d) * t * t; return b + c * (tc);};Tween.inOutCubic = function (t, b, c, d) { var ts = (t /= d) * t; var tc = ts * t; return b + c * (-2 * tc + 3 * ts);};Tween.outCubic = function (t, b, c, d) { var ts = (t /= d) * t; var tc = ts * t; return b + c * (tc + -3 * ts + 3 * t);};// CHAINED TWEEN/* @param {Array} tweens: Array of Tweens. example: var tween1 = new Tween(sprite, "position.x", 100, 60, false); var tween2 = new Tween(sprite, "position.x", 0, 60, false); new ChainedTween([tween1, tween2]);*/function ChainedTween(tweens) { this.tweens = tweens; Tween.tweens.push(this);}ChainedTween.prototype.update = function () { if (this.tweens.length == 0) { return true; } var currentTween = this.tweens[0]; if (!currentTween.active) { currentTween.start(); } var finished = currentTween.update(); if (finished) { this.tweens.splice(0, 1); } return false;};// TODO: COMBINED TWEENfunction CombinedTween(tweens) {}CombinedTween.prototype.start = function () {};CombinedTween.prototype.update = function () {}; I have created the following defintion file : /** * * Typescript declaration file for tween.js file * User: Marwane * Date: 09/04/15 */ declare var TWEEN: any;declare module TWEEN_ {export class Tween {object:any;property:string;targetValue:number;startValue:string;active:boolean;currentFrame:number;endFrame:number;tweens:any[]; constructor( object:any, property:string, value:number, frames:number, autostart:boolean); public onComplete:()=>void;public setOnComplete:()=>void;public start:()=>void;public initIterations:()=>void;public update:()=>void;public runTweens:()=>void;public noEase:()=>void;public outElastic:()=>void;public inElastic:()=>void;public inOutQuintic:()=>void;public inQuintic:()=>void;public outQuintic:()=>void;public inCubic:()=>void;public inOutCubic:()=>void;public outCubic:()=>void;} export class ChainedTween{tweens:any[]; constructor(tweens:any[]); public update:()=>void; } } it compiles, however when i run the code i get "Uncaught ReferenceError: TWEEN_ is not defined" Please help me Thanks in advance Quote Link to comment Share on other sites More sharing options...
Marwane2185 Posted April 14, 2015 Author Share Posted April 14, 2015 Sorry, I forget to say, when i called tween.js a did this : .....///<reference path="../core/tween.d.ts" />...........new TWEEN_.Tween(object, "position.x", 200, 25, true); ........ Thanks again for responding Quote Link to comment Share on other sites More sharing options...
Tweeper Posted April 15, 2015 Share Posted April 15, 2015 Try using the DefinitelyTyped typescript file for PIXI instead, that should contain most of the PIXI code and is updated 8 months ago according to github: https://github.com/borisyankov/DefinitelyTyped/tree/master/pixi Quote Link to comment Share on other sites More sharing options...
clark Posted April 16, 2015 Share Posted April 16, 2015 DT is out of date by months and was never good to begin with. Use the new PIXI TypeScript Repo, you will find v2 and v3 upto date definitions there. https://github.com/pixijs/pixi-typescript Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.