From 93680e3286ae8c6c07459d977d7d9e48a06c10d9 Mon Sep 17 00:00:00 2001 From: logsol Date: Sat, 7 Feb 2015 15:37:40 +0100 Subject: [PATCH] fixed movieclip speed/fps bug. fixes #35 --- app/Game/Client/GameObjects/Doll.js | 13 +++++++++++++ app/Game/Client/View/Pixi/Layer.js | 1 + app/Lib/Utilities/Channel/Extensions.js | 22 +++++++++++++++++++++ app/Lib/Utilities/Client/Extensions.js | 9 +++++++++ app/Lib/Utilities/Core/Extensions.js | 12 ++++++++++++ app/Lib/Utilities/Extensions.js | 26 ------------------------- channel.js | 2 +- client.js | 2 +- server.js | 2 +- 9 files changed, 60 insertions(+), 29 deletions(-) create mode 100644 app/Lib/Utilities/Channel/Extensions.js create mode 100644 app/Lib/Utilities/Client/Extensions.js create mode 100755 app/Lib/Utilities/Core/Extensions.js delete mode 100755 app/Lib/Utilities/Extensions.js diff --git a/app/Game/Client/GameObjects/Doll.js b/app/Game/Client/GameObjects/Doll.js index 5b54909..a617746 100755 --- a/app/Game/Client/GameObjects/Doll.js +++ b/app/Game/Client/GameObjects/Doll.js @@ -25,6 +25,8 @@ function (Parent, Settings, Nc, Exception, ColorConverter, Layer) { "run": [104,126] } + this.lastStep = Date.now(); + this.animatedMeshesContainer = { withArms: {}, withoutArms: {} @@ -260,12 +262,23 @@ function (Parent, Settings, Nc, Exception, ColorConverter, Layer) { Doll.prototype.render = function() { if(this.actionState) { + + var stepLength = (Date.now() - this.lastStep); + this.lastStep = Date.now(); + + // compare current framerate to wanted and get factor + // (stepLength / 60) * 2 + // * 2 to scale to flash fps + + var factor = stepLength / 30; + Nc.trigger(Nc.ns.client.view.mesh.update, this.layerId, this.animatedMeshes[this.actionState], { x: this.body.GetPosition().x * Settings.RATIO, y: this.body.GetPosition().y * Settings.RATIO, + animationSpeed: factor //rotation: this.body.GetAngle() } ); diff --git a/app/Game/Client/View/Pixi/Layer.js b/app/Game/Client/View/Pixi/Layer.js index 0e9fd67..f9c9d45 100644 --- a/app/Game/Client/View/Pixi/Layer.js +++ b/app/Game/Client/View/Pixi/Layer.js @@ -96,6 +96,7 @@ function (Parent, PIXI, ColorRangeReplaceFilter, Settings) { if (options.visible === true || options.visible === false) mesh.visible = options.visible; if (options.pivot) mesh.pivot = new PIXI.Point(options.pivot.x, options.pivot.y); if (options.anchor) mesh.anchor = options.anchor; + if (options.animationSpeed) mesh.animationSpeed = options.animationSpeed; }; Layer.prototype.addFilter = function(mesh, filterName, options) { diff --git a/app/Lib/Utilities/Channel/Extensions.js b/app/Lib/Utilities/Channel/Extensions.js new file mode 100644 index 0000000..269e880 --- /dev/null +++ b/app/Lib/Utilities/Channel/Extensions.js @@ -0,0 +1,22 @@ +define([ + "Lib/Utilities/Core/Extensions" +], + +function (Parent) { + + //"use strict"; + + console.checkpoint = function (s) { + console.log(" \033[32mbeep - \033[0m" + s); + } + + console.warn = function (s) { + console.log(" \033[33mwarn - \033[0m" + s); + } + + console.error = function (s) { + console.log(" \033[31merror - \033[0m" + s); + } + + +}); \ No newline at end of file diff --git a/app/Lib/Utilities/Client/Extensions.js b/app/Lib/Utilities/Client/Extensions.js new file mode 100644 index 0000000..1f4e7d0 --- /dev/null +++ b/app/Lib/Utilities/Client/Extensions.js @@ -0,0 +1,9 @@ +define([ + "Lib/Utilities/Core/Extensions", + "Lib/Vendor/Pixi" +], + +function (Parent, PIXI) { + + "use strict"; +}); \ No newline at end of file diff --git a/app/Lib/Utilities/Core/Extensions.js b/app/Lib/Utilities/Core/Extensions.js new file mode 100755 index 0000000..1cd8fc4 --- /dev/null +++ b/app/Lib/Utilities/Core/Extensions.js @@ -0,0 +1,12 @@ +define([ +], + +function () { + + "use strict"; + + String.prototype.toUpperCaseFirstChar = function () { + var f = this.charAt(0).toUpperCase(); + return f + this.substr(1); + } +}); \ No newline at end of file diff --git a/app/Lib/Utilities/Extensions.js b/app/Lib/Utilities/Extensions.js deleted file mode 100755 index 1cf9c9b..0000000 --- a/app/Lib/Utilities/Extensions.js +++ /dev/null @@ -1,26 +0,0 @@ -define([ -], - -function() { - - String.prototype.toUpperCaseFirstChar = function () { - var f = this.charAt(0).toUpperCase(); - return f + this.substr(1); - } - - if(typeof process !== 'undefined') { - - console.checkpoint = function (s) { - console.log(' \033[32mbeep - \033[0m' + s); - } - - console.warn = function (s) { - console.log(' \033[33mwarn - \033[0m' + s); - } - - console.error = function (s) { - console.log(' \033[31merror - \033[0m' + s); - } - } - -}); \ No newline at end of file diff --git a/channel.js b/channel.js index 3294623..27305e9 100755 --- a/channel.js +++ b/channel.js @@ -4,7 +4,7 @@ var requirejs = require('requirejs'); requirejs.config({ nodeRequire: require, baseUrl: 'app', - deps: ['Lib/Utilities/Extensions'] + deps: ['Lib/Utilities/Channel/Extensions'] }); var inspector = {}; diff --git a/client.js b/client.js index b9c212f..84452ab 100755 --- a/client.js +++ b/client.js @@ -4,7 +4,7 @@ var GLOBALS = { context: "Client" }; requirejs.config({ baseUrl: 'app', - deps: ['Lib/Utilities/Extensions'], + deps: ['Lib/Utilities/Client/Extensions'], waitSeconds: 0, paths: { screenfull: "/screenfull", diff --git a/server.js b/server.js index bfae3a0..16655ae 100755 --- a/server.js +++ b/server.js @@ -8,7 +8,7 @@ var inspector; requirejs.config({ nodeRequire: require, baseUrl: 'app', - deps: ['Lib/Utilities/Extensions'] + deps: ['Lib/Utilities/Channel/Extensions'] }); var port = process.argv[2]