Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest createjs libs, latest canvas, working on recent node version #3

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea
node_modules
examples/output
3 changes: 1 addition & 2 deletions examples/GraphicsTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var fs = require('fs');
var Canvas = require('canvas');
var Image = Canvas.Image;
var { Canvas, Image } = require('canvas');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The canvas API changed in version 2.

Using this destructing syntax will break older versions of node. We can degrade it back to older syntax, if needed. But really a decision needs to be made on the minimum node version, and subsequently it should run on a CI test matrix that includes includes that minimum version of node.


require('../src/node-easel.js');

3 changes: 1 addition & 2 deletions examples/SpriteSheetBuilderTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var fs = require('fs');
var Canvas = require('canvas');
var Image = Canvas.Image;
var { Canvas, Image } = require('canvas');
require('../src/node-easel.js');

var SpriteSheetBuilderTest = function () {
38 changes: 29 additions & 9 deletions examples/SpritesheetTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var Canvas = require('canvas');
var Image = Canvas.Image;
var { Canvas, Image } = require('canvas');
var fs = require('fs');
var exec = require('child_process').exec;

@@ -18,7 +17,7 @@ s.RUNNING_RATE = 2.5;
p.init = function (success) {
var cmd = "find " + __dirname + "/output -name '*.mpg' -exec rm -f {} \\;";
console.log(cmd);
exec(cmd);
exec(cmd, execCallback);

this.success = success;

@@ -30,7 +29,7 @@ p.init = function (success) {
var spriteSheet = {"animations":{"run":[0, 25], "jump":[26, 63]}, "images":[this.loadImage("runningGrant.png")], "frames":{"regX":0, "height":292.5, "count":64, "regY":0, "width":165.75}};

var ss = new createjs.SpriteSheet(spriteSheet);
this.grant = new createjs.BitmapAnimation(ss);
this.grant = new createjs.Sprite(ss);

// Set up looping
ss.getAnimation("run").next = "run";
@@ -68,7 +67,7 @@ p.init = function (success) {

this.tickFunction = this.tick.bind(this);
var fps = 80;
createjs.Ticker.setFPS(fps);
createjs.Ticker.framerate = fps;
createjs.Ticker.addEventListener("tick", this.tickFunction);

var seconds = 10;
@@ -80,14 +79,19 @@ p.init = function (success) {
p.stopCapture = function () {
createjs.Ticker.removeEventListener("tick", this.tickFunction);
console.log('begin video encoding');
exec('cd ' + __dirname + '/output && ffmpeg -f image2 -i test_%d.png -sameq video.mpg', this.handleVideoEncoded.bind(this));
var cmd = 'cd ' + __dirname + '/output && ffmpeg -f image2 -i test_%d.png -qscale 0 video.mpg';
exec(cmd, this.handleVideoEncoded.bind(this));
}

p.handleVideoEncoded = function () {
console.log('Video Encoded');
p.handleVideoEncoded = function (err, stdout, stderr) {
if (err) {
execCallback(err, stdout, stderr);
} else {
console.log('Video Encoded');
}

var cmd = "find " + __dirname + "/output -name '*.png' -exec rm -f {} \\;";
exec(cmd);
exec(cmd, execCallback);
this.success('video.mpg');

createjs.Ticker.halt();
@@ -123,3 +127,19 @@ p.tick = function () {
var fileName = __dirname + '/output/test_' + (this.index++) + '.png';
fs.writeFileSync(fileName, this.canvas.toBuffer(), '');
}

/**
* Helper for reporting back exec errors
*/
function execCallback(error, stdout, stderr) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helped reveal a problem in ffmpeg output. The cli tool has probably changed a bit since this work was originally done.

if (error) {
console.error("exec error:" + error);
return;
}
if (stdout) {
console.log("stdout:" + stdout);
}
if (stderr) {
console.log("stderr:" + stderr);
}
};
5 changes: 1 addition & 4 deletions examples/captcha.js
Original file line number Diff line number Diff line change
@@ -23,8 +23,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
var fs = require('fs');
var Canvas = require('canvas');
var Image = Canvas.Image;
var { Canvas, Image } = require('canvas');
var Rnd = require('./public/com/gskinner/utils/Rnd.js').Rnd;

require('../src/node-easel.js');
@@ -74,7 +73,6 @@ p.init = function (seed) {
}

var g = new createjs.Graphics();
g.initialize(ctx);

var shape = new createjs.Shape(g);
g.setStrokeStyle(1).beginStroke("#00acc");
@@ -86,7 +84,6 @@ p.init = function (seed) {
}

var g2 = new createjs.Graphics();
g2.initialize(ctx);

var shape2 = new createjs.Shape(g2);
length = 40;
Loading