Merge github.com:djdolphin/scratch-html5 into test

Also improved filter performance, fixed edge cases, and implemented stage filters for color, brightness, and ghost.

Conflicts:
	js/Runtime.js
	js/Sprite.js
    js/primitives/LooksPrims.js

Tested with:
	http://scratch.mit.edu/projects/14315832/
This commit is contained in:
Nathan Dinsmore 2013-11-14 23:44:00 -05:00
commit 0e062e7669
3 changed files with 51 additions and 3 deletions

View file

@ -94,6 +94,11 @@ Runtime.prototype.stopAll = function() {
runtime.sprites[s].hideBubble();
}
}
// Reset graphic effects
runtime.stage.resetFilters();
for (var s = 0; s < runtime.sprites.length; s++) {
runtime.sprites[s].resetFilters();
}
};
// Step method for execution - called every 33 milliseconds

View file

@ -89,6 +89,17 @@ var Sprite = function(data) {
this.soundsLoaded = 0;
this.instrument = 1;
// Image effects
this.filters = {
color: 0,
fisheye: 0,
whirl: 0,
pixelate: 0,
mosaic: 0,
brightness: 0,
ghost: 0
};
// Incremented when images are loaded by the browser.
this.costumesLoaded = 0;
@ -308,6 +319,13 @@ Sprite.prototype.updateTransform = function() {
this.updateLayer();
};
Sprite.prototype.updateFilters = function() {
$(this.mesh).css('opacity', 1 - this.filters.ghost / 100);
$(this.mesh).css('-webkit-filter',
'hue-rotate(' + (this.filters.color * 1.8) + 'deg) \
brightness(' + (this.filters.brightness < 0 ? this.filters.brightness / 100 + 1 : Math.min(2.5, this.filters.brightness * .015 + 1)) + ')');
};
Sprite.prototype.getTalkBubbleXY = function() {
var texture = this.textures[this.currentCostumeIndex];
var drawWidth = texture.width * this.scale;
@ -465,3 +483,16 @@ Sprite.prototype.soundNamed = function(name) {
}
return null;
};
Sprite.prototype.resetFilters = function() {
this.filters = {
color: 0,
fisheye: 0,
whirl: 0,
pixelate: 0,
mosaic: 0,
brightness: 0,
ghost: 0
};
this.updateFilters();
};

View file

@ -152,11 +152,23 @@ LooksPrims.prototype.primGoBack = function(b) {
if(s.visible) interp.redraw();
};
LooksPrims.prototype.primChangeEffect = function(b) {};
LooksPrims.prototype.primChangeEffect = function(b) {
var s = interp.targetSprite();
s.filters[interp.arg(b, 0)] += interp.numarg(b, 1);
s.updateFilters();
};
LooksPrims.prototype.primSetEffect = function(b) {};
LooksPrims.prototype.primSetEffect = function(b) {
var s = interp.targetSprite();
s.filters[interp.arg(b, 0)] = interp.numarg(b, 1);
s.updateFilters();
};
LooksPrims.prototype.primClearEffects = function(b) {};
LooksPrims.prototype.primClearEffects = function(b) {
var s = interp.targetSprite();
s.resetFilters();
s.updateFilters();
};
var showBubble = function(b, type) {
var s = interp.targetSprite();