Comparing version 0.6.3 to 0.6.4
@@ -0,1 +1,5 @@ | ||
#### v0.6.4 | ||
* pinning shortcuts are added to nodes | ||
* entire atlas can be referenced | ||
#### v0.6.2 | ||
@@ -2,0 +6,0 @@ * `atlas.image.url` renamed to `src` |
@@ -192,2 +192,23 @@ #### Application | ||
Following shortcut methods are also available for setting pinning values. | ||
``` | ||
foo.size(width, height); | ||
foo.offset(x, y); | ||
foo.offset({ x : x, y : y }); | ||
foo.scale(x, y = x); | ||
foo.scale({ x : x, y : y }); | ||
foo.rotate(angle); | ||
foo.skew(x, y = x); | ||
foo.skew({ x : x, y : y }); | ||
foo.alpha(alpha); | ||
foo.alpha(alpha, textureAlpha); | ||
``` | ||
#### Events | ||
@@ -194,0 +215,0 @@ |
@@ -17,5 +17,2 @@ /* | ||
function Mouse() { | ||
} | ||
Mouse.CLICK = 'click'; | ||
@@ -28,10 +25,10 @@ Mouse.START = 'touchstart mousedown'; | ||
Mouse.subscribe = function(stage, elem) { | ||
var visitor = null, data = {}; | ||
var abs = null, rel = null; | ||
var clicklist = [], cancellist = []; | ||
if (stage.mouse) { | ||
return; | ||
} | ||
elem = elem || document; | ||
stage.mouse = new Mouse(stage, elem); | ||
// click events are synthesized from start/end events on same nodes | ||
// elem.addEventListener('click', handleClick); | ||
// `click` events are synthesized from start/end events on same nodes | ||
// `mousecancel` events are synthesized on blur or mouseup outside element | ||
@@ -50,23 +47,31 @@ elem.addEventListener('touchstart', handleStart); | ||
var clicklist = [], cancellist = []; | ||
function handleStart(event) { | ||
event.preventDefault(); | ||
locate(elem, event, abs); | ||
DEBUG && console.log('Mouse Start: ' + event.type + ' ' + abs); | ||
publish(event.type, event); | ||
stage.mouse.locate(event); | ||
// DEBUG && console.log('Mouse Start: ' + event.type + ' ' + mouse); | ||
stage.mouse.publish(event.type, event); | ||
lookup('click', clicklist); | ||
lookup('mousecancel', cancellist); | ||
stage.mouse.lookup('click', clicklist); | ||
stage.mouse.lookup('mousecancel', cancellist); | ||
} | ||
function handleMove(event) { | ||
event.preventDefault(); | ||
stage.mouse.locate(event); | ||
stage.mouse.publish(event.type, event); | ||
} | ||
function handleEnd(event) { | ||
event.preventDefault(); | ||
// up/end location is not available, last one is used instead | ||
DEBUG && console.log('Mouse End: ' + event.type + ' ' + abs); | ||
publish(event.type, event); | ||
// DEBUG && console.log('Mouse End: ' + event.type + ' ' + mouse); | ||
stage.mouse.publish(event.type, event); | ||
if (clicklist.length) { | ||
DEBUG && console.log('Mouse Click: ' + clicklist.length); | ||
publish('click', event, clicklist); | ||
cancellist.length = 0; | ||
// DEBUG && console.log('Mouse Click: ' + clicklist.length); | ||
stage.mouse.publish('click', event, clicklist); | ||
} | ||
cancellist.length = 0; | ||
} | ||
@@ -76,11 +81,13 @@ | ||
if (cancellist.length) { | ||
DEBUG && console.log('Mouse Cancel: ' + event.type); | ||
publish('mousecancel', event, cancellist); | ||
// DEBUG && console.log('Mouse Cancel: ' + event.type); | ||
stage.mouse.publish('mousecancel', event, cancellist); | ||
} | ||
clicklist.length = 0; | ||
} | ||
}; | ||
function handleMove(event) { | ||
event.preventDefault(); | ||
locate(elem, event, abs); | ||
publish(event.type, event); | ||
function Mouse(stage, elem) { | ||
if (!(this instanceof Mouse)) { | ||
// old-style mouse subscription | ||
return; | ||
} | ||
@@ -94,59 +101,67 @@ | ||
function locate(elem, event) { | ||
locateElevent(elem, event, abs); | ||
abs.x *= ratio; | ||
abs.y *= ratio; | ||
} | ||
function lookup(type, collect) { | ||
data.type = type; | ||
data.root = stage; | ||
data.event = null; | ||
this.x = 0; | ||
this.y = 0; | ||
this.toString = function() { | ||
return (this.x | 0) + 'x' + (this.y | 0); | ||
}; | ||
this.locate = function(event) { | ||
locateElevent(elem, event, this); | ||
this.x *= ratio; | ||
this.y *= ratio; | ||
}; | ||
this.lookup = function(type, collect) { | ||
this.type = type; | ||
this.root = stage; | ||
this.event = null; | ||
collect.length = 0; | ||
data.collect = collect; | ||
this.collect = collect; | ||
data.root.visit(visitor, data); | ||
} | ||
this.root.visit(this.visitor, this); | ||
}; | ||
this.publish = function(type, event, targets) { | ||
this.type = type; | ||
this.root = stage; | ||
this.event = event; | ||
this.collect = false; | ||
this.timeStamp = Date.now(); | ||
function publish(type, event, targets) { | ||
data.type = type; | ||
data.root = stage; | ||
data.event = event; | ||
data.collect = false; | ||
data.timeStamp = Date.now(); | ||
if (type !== 'mousemove' && type !== 'touchmove') { | ||
DEBUG && console.log(this.type + ' ' + this); | ||
} | ||
if (targets) { | ||
while (targets.length) | ||
if (visitor.end(targets.shift(), data)) | ||
if (this.visitor.end(targets.shift(), this)) | ||
break; | ||
targets.length = 0; | ||
} else { | ||
data.root.visit(visitor, data); | ||
this.root.visit(this.visitor, this); | ||
} | ||
} | ||
visitor = { | ||
}; | ||
this.visitor = { | ||
reverse : true, | ||
visible : true, | ||
start : function(node, data) { | ||
return !node._flag(data.type); | ||
start : function(node, mouse) { | ||
return !node._flag(mouse.type); | ||
}, | ||
end : function(node, data) { | ||
// data: event, type, root, collect | ||
rel.raw = data.event; | ||
rel.type = data.type; | ||
rel.timeStamp = data.timeStamp; | ||
var listeners = node.listeners(data.type); | ||
end : function(node, mouse) { | ||
// mouse: event/collect, type, root | ||
rel.raw = mouse.event; | ||
rel.type = mouse.type; | ||
rel.timeStamp = mouse.timeStamp; | ||
rel.abs.x = mouse.x; | ||
rel.abs.y = mouse.y; | ||
var listeners = node.listeners(mouse.type); | ||
if (!listeners) { | ||
return; | ||
} | ||
node.matrix().inverse().map(abs, rel); | ||
if (!(node === data.root || node.hitTest(rel))) { | ||
node.matrix().inverse().map(mouse, rel); | ||
if (!(node === mouse.root || node.hitTest(rel))) { | ||
return; | ||
} | ||
if (data.collect) { | ||
data.collect.push(node); | ||
if (mouse.collect) { | ||
mouse.collect.push(node); | ||
} | ||
if (data.event) { | ||
if (mouse.event) { | ||
var cancel = false; | ||
@@ -160,36 +175,35 @@ for (var l = 0; l < listeners.length; l++) { | ||
}; | ||
}; | ||
abs = { | ||
x : 0, | ||
y : 0, | ||
toString : function() { | ||
return (this.x | 0) + 'x' + (this.y | 0); | ||
}, | ||
clone : function(clone) { | ||
clone = clone || {}; | ||
clone.x = this.x; | ||
clone.y = this.y; | ||
return clone; | ||
var rel = Object.defineProperties({}, { | ||
'clone' : { | ||
value : function(obj) { | ||
obj = obj || {}, obj.x = this.x, obj.y = this.y; | ||
return obj; | ||
} | ||
}; | ||
rel = { | ||
x : 0, | ||
y : 0, | ||
abs : abs, | ||
toString : function() { | ||
return abs + ' / ' + (this.x | 0) + 'x' + (this.y | 0); | ||
}, | ||
clone : function(clone) { | ||
clone = clone || {}; | ||
clone.x = this.x; | ||
clone.y = this.y; | ||
return clone; | ||
}, | ||
'toString' : { | ||
value : function() { | ||
return (this.x | 0) + 'x' + (this.y | 0) + ' (' + this.abs + ')'; | ||
} | ||
}; | ||
}, | ||
'abs' : { | ||
value : Object.defineProperties({}, { | ||
'clone' : { | ||
value : function(obj) { | ||
obj = obj || {}, obj.x = this.x, obj.y = this.y; | ||
return obj; | ||
} | ||
}, | ||
'toString' : { | ||
value : function() { | ||
return (this.x | 0) + 'x' + (this.y | 0); | ||
} | ||
} | ||
}) | ||
} | ||
}); | ||
}; | ||
function locateElevent(el, ev, loc) { | ||
// TODO: use pageX/Y if available? | ||
// pageX/Y if available? | ||
if (ev.touches && ev.touches.length) { | ||
@@ -196,0 +210,0 @@ loc.x = ev.touches[0].clientX; |
@@ -38,5 +38,4 @@ /* | ||
lastTime = now; | ||
this.touch(); | ||
if (ignore) { | ||
return; | ||
return true; | ||
} | ||
@@ -136,2 +135,4 @@ | ||
Pin._add_shortcuts(Tween); | ||
module.exports = Tween; |
@@ -47,3 +47,6 @@ /* | ||
url && Class.preload(function(done) { | ||
DEBUG && console.log('Loading image: ' + url); | ||
if (def.base) { | ||
url = def.base + url; | ||
} | ||
DEBUG && console.log('Loading atlas: ' + url); | ||
var imageloader = Class.config('image-loader'); | ||
@@ -56,4 +59,4 @@ | ||
}, function(msg) { | ||
DEBUG && console.log('Error loading image: ' + url, msg); | ||
}, function(err) { | ||
DEBUG && console.log('Error loading atlas: ' + url, err); | ||
done(); | ||
@@ -60,0 +63,0 @@ }); |
@@ -15,2 +15,3 @@ /* | ||
var is = require('./util/is'); | ||
var wait = require('./util/wait'); | ||
@@ -102,26 +103,17 @@ stats.create = 0; | ||
var loading = wait(); | ||
DEBUG && console.log('Preloading...'); | ||
var loading = 0; | ||
if (!_preload_queue.length) { | ||
done(); | ||
} else { | ||
while (_preload_queue.length) { | ||
var preload = _preload_queue.shift(); | ||
preload(once(done)); | ||
loading++; | ||
} | ||
while (_preload_queue.length) { | ||
_preload_queue.shift()(loading()); | ||
} | ||
function done() { | ||
if (--loading <= 0) { | ||
DEBUG && console.log('Loading apps...'); | ||
_started = true; | ||
while (_app_queue.length) { | ||
var args = _app_queue.shift(); | ||
Class.app.apply(Class, args); | ||
} | ||
loading.then(function() { | ||
DEBUG && console.log('Loading apps...'); | ||
_started = true; | ||
while (_app_queue.length) { | ||
var args = _app_queue.shift(); | ||
Class.app.apply(Class, args); | ||
} | ||
} | ||
}); | ||
}; | ||
@@ -128,0 +120,0 @@ |
@@ -17,2 +17,4 @@ /* | ||
var once = require('../util/once'); | ||
if (typeof FastContext === 'undefined') { | ||
@@ -24,11 +26,18 @@ FastContext = window.FastContext; | ||
DEBUG && console.log('On load.'); | ||
// var readyTimeout = setTimeout(function() { | ||
// DEBUG && console.log('On deviceready timeout.'); | ||
// Class.start(); | ||
var start = once(function(msg) { | ||
DEBUG && msg && console.log(msg); | ||
Class.start(); | ||
}); | ||
// setTimeout(function() { | ||
// start('On deviceready timeout.'); | ||
// }, 2000); | ||
document.addEventListener('click', function() { | ||
start('Started by click.'); | ||
}, false); | ||
document.addEventListener('deviceready', function() { | ||
DEBUG && console.log('On deviceready.'); | ||
// clearTimeout(readyTimeout); | ||
Class.start(); | ||
start('On deviceready.'); | ||
}, false); | ||
@@ -35,0 +44,0 @@ |
@@ -553,49 +553,64 @@ /* | ||
Class.prototype.size = function(w, h) { | ||
this.pin('width', w); | ||
this.pin('height', h); | ||
return this; | ||
}; | ||
// Used by Tween class. | ||
Pin._add_shortcuts = function(Class) { | ||
Class.prototype.size = function(w, h) { | ||
this.pin('width', w); | ||
this.pin('height', h); | ||
return this; | ||
}; | ||
Class.prototype.offset = function(a, b) { | ||
if (typeof a === 'object') | ||
b = a.y, a = a.x; | ||
this.pin('offsetX', a); | ||
this.pin('offsetY', b); | ||
return this; | ||
}; | ||
Class.prototype.width = function(w) { | ||
this.pin('width', w); | ||
return this; | ||
}; | ||
Class.prototype.rotate = function(a) { | ||
this.pin('rotation', a); | ||
return this; | ||
}; | ||
Class.prototype.height = function(h) { | ||
this.pin('height', h); | ||
return this; | ||
}; | ||
Class.prototype.skew = function(a, b) { | ||
if (typeof a === 'object') | ||
b = a.y, a = a.x; | ||
else if (typeof b === 'undefined') | ||
b = a; | ||
this.pin('skewX', a); | ||
this.pin('skewY', b); | ||
return this; | ||
}; | ||
Class.prototype.offset = function(a, b) { | ||
if (typeof a === 'object') | ||
b = a.y, a = a.x; | ||
this.pin('offsetX', a); | ||
this.pin('offsetY', b); | ||
return this; | ||
}; | ||
Class.prototype.scale = function(a, b) { | ||
if (typeof a === 'object') | ||
b = a.y, a = a.x; | ||
else if (typeof b === 'undefined') | ||
b = a; | ||
this.pin('scaleX', a); | ||
this.pin('scaleY', b); | ||
return this; | ||
}; | ||
Class.prototype.rotate = function(a) { | ||
this.pin('rotation', a); | ||
return this; | ||
}; | ||
Class.prototype.alpha = function(a, ta) { | ||
this.pin('alpha', a); | ||
if (typeof ta !== 'undefined') { | ||
this.pin('textureAlpha', ta); | ||
} | ||
return this; | ||
Class.prototype.skew = function(a, b) { | ||
if (typeof a === 'object') | ||
b = a.y, a = a.x; | ||
else if (typeof b === 'undefined') | ||
b = a; | ||
this.pin('skewX', a); | ||
this.pin('skewY', b); | ||
return this; | ||
}; | ||
Class.prototype.scale = function(a, b) { | ||
if (typeof a === 'object') | ||
b = a.y, a = a.x; | ||
else if (typeof b === 'undefined') | ||
b = a; | ||
this.pin('scaleX', a); | ||
this.pin('scaleY', b); | ||
return this; | ||
}; | ||
Class.prototype.alpha = function(a, ta) { | ||
this.pin('alpha', a); | ||
if (typeof ta !== 'undefined') { | ||
this.pin('textureAlpha', ta); | ||
} | ||
return this; | ||
}; | ||
}; | ||
Pin._add_shortcuts(Class); | ||
module.exports = Pin; |
{ | ||
"name": "stage-js", | ||
"version": "0.6.3", | ||
"version": "0.6.4", | ||
"description": "2D HTML5 JavaScript library for cross-platform game development", | ||
@@ -38,2 +38,3 @@ "homepage": "http://piqnt.com/stage.js/", | ||
"gulp-uglify": "*", | ||
"gulp-util": "^3.0.5", | ||
"gulp-wrap": "*", | ||
@@ -51,4 +52,4 @@ "minimist": "*", | ||
"build": "gulp", | ||
"watch": "gulp build-min watch" | ||
"dev": "gulp dev" | ||
} | ||
} |
@@ -8,3 +8,3 @@ **[Learn More & Browse Examples](http://piqnt.com/stage.js/)** | ||
Platforms CommonJS modules: | ||
CommonJS/Node.js modules: | ||
@@ -24,1 +24,5 @@ platform/web.js | ||
doc/api.md | ||
### License | ||
Copyright (c) 2015 Ali Shakiba, Piqnt LLC | ||
Available under the MIT license |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
144959
52
4699
27
18