img anim
This commit is contained in:
parent
2983e9f3c6
commit
4dfaaf2b52
6
docs/primum.md
Normal file
6
docs/primum.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# Primum
|
||||||
|
|
||||||
|
The core tenents of Primum are as follows. When choosing features for Primum, these are the guidelines we follow.
|
||||||
|
- Gameplay first. Visuals are important but should be chosen to be more simple if it makes implementing gameplay more difficult.
|
||||||
|
- Dynamic first. Video games are dynamic, so as much as possible should be dynamically generated. For example, signed distance fields for particle system collision will not be used, as it requires baking sometimes false geometry. We include midi playback, which can be changed in real time far easier than wavs or mp3s.
|
||||||
|
- Marriage of code and editor. Neither completely replaces the other. What is easier to do in code should be done in code, and what should be done in editor should be done in editor. No solutions try to step on the toes of the other solution.
|
|
@ -92,14 +92,16 @@ component.sprite.impl = {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
this.cancel = undefined;
|
this.cancel = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Resources.is_animation(x)) {
|
if (!Resources.is_animation(x)) {
|
||||||
this.rect = component.sprite.rect;
|
this.rect = component.sprite.rect;
|
||||||
cmd(12,this.id,x,this.rect);
|
cmd(12,this.id,x,this.rect);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.rect = SpriteAnim.make(x).frames[0].rect;
|
this.anims = SpriteAnim.make(x);
|
||||||
cmd(12,this.id,x,this.rect);
|
var anim = this.anims[0];
|
||||||
|
this.rect = anim.frames[0].rect;
|
||||||
|
cmd(12,this.id,anim.path,this.rect);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
get path() {
|
get path() {
|
||||||
|
@ -108,17 +110,19 @@ component.sprite.impl = {
|
||||||
return s;
|
return s;
|
||||||
},
|
},
|
||||||
|
|
||||||
play() {
|
play(name) {
|
||||||
|
if (!this.anims) return;
|
||||||
|
if (this.cancel) this.cancel();
|
||||||
|
name ??= 0;
|
||||||
var frame = 0;
|
var frame = 0;
|
||||||
var anim = SpriteAnim.make(this.path);
|
var anim = this.anims[name];
|
||||||
var advance = function() {
|
var advance = function() {
|
||||||
frame = (frame+1)%anim.frames.length;
|
frame = (frame+1)%anim.frames.length;
|
||||||
this.rect = anim.frames[frame].rect;
|
this.rect = anim.frames[frame].rect;
|
||||||
cmd(12,this.id,this.path,this.rect);
|
cmd(12,this.id,anim.path,this.rect);
|
||||||
this.cancel = this.gameobject.delay(advance.bind(this), anim.frames[frame].time);
|
this.cancel = this.gameobject.delay(advance.bind(this), anim.frames[frame].time);
|
||||||
}
|
}
|
||||||
advance.call(this);
|
advance.call(this);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
|
@ -127,11 +131,11 @@ component.sprite.impl = {
|
||||||
this.cancel = undefined;
|
this.cancel = undefined;
|
||||||
},
|
},
|
||||||
setframe(f) {
|
setframe(f) {
|
||||||
|
if (!this.anims) return;
|
||||||
this.stop();
|
this.stop();
|
||||||
var anim = SpriteAnim.make(this.path);
|
var anim = this.anims[0];
|
||||||
if (!anim) return;
|
|
||||||
this.rect = anim.frames[f].rect;
|
this.rect = anim.frames[f].rect;
|
||||||
cmd(12,this.id,this.path,this.rect);
|
cmd(12,this.id,anim.path,this.rect);
|
||||||
},
|
},
|
||||||
|
|
||||||
toString() { return "sprite"; },
|
toString() { return "sprite"; },
|
||||||
|
@ -153,7 +157,7 @@ component.sprite.impl = {
|
||||||
get drawmode() { return cmd(220,this.id); },
|
get drawmode() { return cmd(220,this.id); },
|
||||||
set drawmode(x) { cmd(219,this.id,x); },
|
set drawmode(x) { cmd(219,this.id,x); },
|
||||||
emissive(x) { cmd(170, this.id, x); },
|
emissive(x) { cmd(170, this.id, x); },
|
||||||
sync() { this.path = this.path; },
|
sync() { },
|
||||||
pickm() { return this; },
|
pickm() { return this; },
|
||||||
move(d) { this.pos = this.pos.add(d); },
|
move(d) { this.pos = this.pos.add(d); },
|
||||||
|
|
||||||
|
@ -217,6 +221,8 @@ var SpriteAnim = {
|
||||||
make(path) {
|
make(path) {
|
||||||
if (path.ext() === 'gif')
|
if (path.ext() === 'gif')
|
||||||
return SpriteAnim.gif(path);
|
return SpriteAnim.gif(path);
|
||||||
|
else if (path.ext() === 'ase')
|
||||||
|
return SpriteAnim.aseprite(path);
|
||||||
else
|
else
|
||||||
return undefined;
|
return undefined;
|
||||||
},
|
},
|
||||||
|
@ -244,7 +250,7 @@ var SpriteAnim = {
|
||||||
var dim = Resources.texture.dimensions(path);
|
var dim = Resources.texture.dimensions(path);
|
||||||
dim.y /= frames;
|
dim.y /= frames;
|
||||||
anim.dim = dim;
|
anim.dim = dim;
|
||||||
return anim;
|
return {0:anim};
|
||||||
},
|
},
|
||||||
|
|
||||||
strip(path, frames, time=0.05) {
|
strip(path, frames, time=0.05) {
|
||||||
|
@ -292,9 +298,13 @@ var SpriteAnim = {
|
||||||
var json = IO.slurp(path);
|
var json = IO.slurp(path);
|
||||||
json = JSON.parse(json);
|
json = JSON.parse(json);
|
||||||
var anims = {};
|
var anims = {};
|
||||||
var frames = Array.isArray(json.frames) ? json.frames : Object.values(json.frames);
|
var frames = Array.isArray(json.frames) ? json.frames : Object.values(json.frames);
|
||||||
for (var tag of json.meta.frameTags)
|
var f = 0;
|
||||||
|
for (var tag of json.meta.frameTags) {
|
||||||
anims[tag.name] = aseframeset2anim(frames.slice(tag.from, tag.to+1), json.meta);
|
anims[tag.name] = aseframeset2anim(frames.slice(tag.from, tag.to+1), json.meta);
|
||||||
|
anims[f] = anims[tag.name];
|
||||||
|
f++;
|
||||||
|
}
|
||||||
|
|
||||||
return anims;
|
return anims;
|
||||||
},
|
},
|
||||||
|
|
|
@ -26,6 +26,9 @@ Resources.is_sound = function(path) {
|
||||||
Resources.is_animation = function(path)
|
Resources.is_animation = function(path)
|
||||||
{
|
{
|
||||||
if (path.ext() === 'gif' && Resources.gif.frames(path) > 1) return true;
|
if (path.ext() === 'gif' && Resources.gif.frames(path) > 1) return true;
|
||||||
|
if (path.ext() === 'ase') return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Resources.texture = {};
|
Resources.texture = {};
|
||||||
|
|
Loading…
Reference in a new issue