Support for hex fade colors.

Fix shake when sprite is not at 0,0.
This commit is contained in:
fire bingo 2018-05-04 10:55:38 -07:00
parent 3b91e57a1c
commit 338d42d2a1
3 changed files with 41 additions and 25 deletions

View File

@ -95,7 +95,6 @@ class commonFunctions {
case "punch": { case "punch": {
if (t === 0 || t === 1) if (t === 0 || t === 1)
return start; return start;
debugger;
let change = end - start; let change = end - start;
let num = 0.3; let num = 0.3;
let rad = Math.PI * 2; let rad = Math.PI * 2;
@ -116,13 +115,26 @@ class commonFunctions {
} }
static getColorFromName(name) { static getColorFromName(name) {
if(!name) { return 0xFFFFFF } if(!name) { return { color: 0xFFFFFF, alpha: 1 } }
if(name.startsWith('#')) {
let alpha = '';
let color = '';
name = name.substring(1);
if(name.length === 8) {
color = name.slice(0, 6);
alpha = name.slice(6, 8);
}
color = parseInt(color, 16);
alpha = parseInt(alpha, 16) / 255;
return { color, alpha };
} else {
switch(name.toLowerCase()) { switch(name.toLowerCase()) {
case 'black': case 'black':
return 0x000000; return { color: 0x000000, alpha: 1 };
case 'white': case 'white':
return 0xFFFFFF; return { color: 0xFFFFFF, alpha: 1 };
}
} }
} }

View File

@ -183,9 +183,8 @@ function missionChanged(value) {
.then((success) => { .then((success) => {
player.resetAll(); player.resetAll();
currentMission = undefined; currentMission = undefined;
debugger;
}, (failure) => { }, (failure) => {
debugger; player.resetAll();
currentMission = undefined; currentMission = undefined;
console.log(failure); console.log(failure);
}); });

View File

@ -292,7 +292,7 @@ class Player {
pos = 1; pos = 1;
toRemove.push(i); toRemove.push(i);
if(l.post) { if(l.post) {
var split = l.post.split('|'); let split = l.post.split('|');
switch(split[0].toLowerCase()) { switch(split[0].toLowerCase()) {
case "destroy": case "destroy":
l.object.destroy(); l.object.destroy();
@ -315,16 +315,16 @@ class Player {
} else { } else {
let x = l.initV.x; let x = l.initV.x;
let y = l.initV.y; let y = l.initV.y;
if(l.initV.x !== l.finalV.x) { if(l.finalV.x) {
x = Math.floor(Math.random() * (l.finalV.x * (1-pos))); x = Math.floor(Math.random() * (l.finalV.x * (1-pos)));
} }
if(l.initV.y !== l.finalV.y) { if(l.finalV.y) {
y = Math.floor(Math.random() * (l.finalV.y * (1-pos))); y = Math.floor(Math.random() * (l.finalV.y * (1-pos)));
} }
if(l.object instanceof HTMLElement) { if(l.object instanceof HTMLElement) {
l.object.style = `transform: translate(${x}px, ${y}px);`; l.object.style = `transform: translate(${x}px, ${y}px);`;
} else { } else {
l.object.position.set(x, y); l.object.position.set(l.initV.x + x, l.initV.y + y);
} }
} }
break; break;
@ -393,19 +393,23 @@ class Player {
break; break;
} }
//FadeTo //FadeTo
case "fadeout": case "fadeout": {
this.text.dialogText(false, ""); this.text.dialogText(false, "");
this.text.characterName(false, ""); this.text.characterName(false, "");
this.waitTime = Number(cur.Arg6) * 1000; this.waitTime = Number(cur.Arg6) * 1000;
this.layers["bg|whiteFade"].sprite.tint = commonFunctions.getColorFromName(cur.Arg1); let fadeColor = commonFunctions.getColorFromName(cur.Arg1);
this.lerpTargets.push({type: 'alpha', object: this.layers["bg|whiteFade"].sprite, curTime: 0, time: this.waitTime, finalV: 1, initV: 0}); this.layers["bg|whiteFade"].sprite.tint = fadeColor.color;
this.lerpTargets.push({type: 'alpha', object: this.layers["bg|whiteFade"].sprite, curTime: 0, time: this.waitTime, finalV: fadeColor.alpha, initV: 0});
break; break;
}
//FadeFrom //FadeFrom
case "fadein": case "fadein": {
this.waitTime = Number(cur.Arg6) * 1000; this.waitTime = Number(cur.Arg6) * 1000;
this.layers["bg|whiteFade"].sprite.tint = commonFunctions.getColorFromName(cur.Arg1); let fadeColor = commonFunctions.getColorFromName(cur.Arg1);
this.lerpTargets.push({type: 'alpha', object: this.layers["bg|whiteFade"].sprite, curTime: 0, time: this.waitTime, finalV: 0, initV: 1}); this.layers["bg|whiteFade"].sprite.tint = fadeColor.color;
this.lerpTargets.push({type: 'alpha', object: this.layers["bg|whiteFade"].sprite, curTime: 0, time: this.waitTime, finalV: 0, initV: fadeColor.alpha});
break; break;
}
case "divalefttorightblackfade": { case "divalefttorightblackfade": {
this.processDivaFade(cur, false, false); this.processDivaFade(cur, false, false);
break; break;
@ -553,15 +557,15 @@ class Player {
this.waitTime = Number(command.Arg6) * 1000; this.waitTime = Number(command.Arg6) * 1000;
let sprite = this.layers["bg|whiteFade"].sprite; let sprite = this.layers["bg|whiteFade"].sprite;
let filter = this.shaders[(rtl ? 'divarighttoleftblackfade' : 'divalefttorightfade')]; let filter = this.shaders[(rtl ? 'divarighttoleftblackfade' : 'divalefttorightfade')];
var color = commonFunctions.getColorFromName(command.Arg1); let color = commonFunctions.getColorFromName(command.Arg1);
let rgbcolor = commonFunctions.hexToRgb(color); let rgbcolor = commonFunctions.hexToRgb(color.color);
sprite.tint = color; sprite.tint = color.color;
sprite.alpha = 1.0; sprite.alpha = color.alpha;
filter.uniforms.time = 0.0; filter.uniforms.time = 0.0;
filter.uniforms.fadeincolor = (clear ? [0.0,0.0,0.0,0.0] : [rgbcolor[0],rgbcolor[1],rgbcolor[2],1.0]); filter.uniforms.fadeincolor = (clear ? [0.0,0.0,0.0,0.0] : [rgbcolor[0],rgbcolor[1],rgbcolor[2],1.0]);
filter.uniforms.fadeoutcolor = (clear ? [rgbcolor[0],rgbcolor[1],rgbcolor[2],1.0] : [0.0,0.0,0.0,0.0]); filter.uniforms.fadeoutcolor = (clear ? [rgbcolor[0],rgbcolor[1],rgbcolor[2],1.0] : [0.0,0.0,0.0,0.0]);
sprite.filters = [filter]; sprite.filters = [filter];
this.lerpTargets.push({type: 'shader', object: sprite, curTime: 0, time: this.waitTime, post: `clearshader|${(clear ? '0' : '1')}`}); this.lerpTargets.push({type: 'shader', object: sprite, curTime: 0, time: this.waitTime, post: `clearshader|${(clear ? '0' : `${color.alpha}`)}`});
} }
//This should mostly be handling things like text //This should mostly be handling things like text
@ -888,8 +892,9 @@ class Player {
} }
} }
if(!curChar) { return; } if(!curChar) { return; }
//The sprite's position should be added to the final x and y when setting the shake position.
this.lerpTargets.push({type: 'shake', object: curChar.sprite, curTime: 0 - (props.delay || 0), time: props.time, this.lerpTargets.push({type: 'shake', object: curChar.sprite, curTime: 0 - (props.delay || 0), time: props.time,
finalV: {x: props.x + curChar.sprite.position.x, y: props.y + curChar.sprite.position.y}, initV: {x: curChar.sprite.position.x, y: curChar.sprite.position.y} }); finalV: {x: props.x, y: props.y}, initV: {x: curChar.sprite.position.x, y: curChar.sprite.position.y} });
} }
} }
} }