Resources for animations
This commit is contained in:
parent
5df1670538
commit
2195f9f5db
|
@ -79,6 +79,8 @@ component.sprite = Object.copy(component, {
|
||||||
_enghook: make_sprite,
|
_enghook: make_sprite,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Object.hide(component.sprite, 'rect');
|
||||||
|
|
||||||
component.sprite.impl = {
|
component.sprite.impl = {
|
||||||
set path(x) {
|
set path(x) {
|
||||||
//cmd(12,this.id,prototypes.resani(this.gameobject.__proto__.toString(), x),this.rect);
|
//cmd(12,this.id,prototypes.resani(this.gameobject.__proto__.toString(), x),this.rect);
|
||||||
|
@ -107,6 +109,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; },
|
||||||
pickm() { return this; },
|
pickm() { return this; },
|
||||||
move(d) { this.pos = this.pos.add(d); },
|
move(d) { this.pos = this.pos.add(d); },
|
||||||
|
|
||||||
|
@ -118,9 +121,14 @@ component.sprite.impl = {
|
||||||
},
|
},
|
||||||
|
|
||||||
kill() { cmd(9,this.id); },
|
kill() { cmd(9,this.id); },
|
||||||
dimensions() { return cmd(64,this.path); },
|
dimensions() {
|
||||||
width() { return cmd(64,this.path).x; },
|
var dim = Resources.texture.dimensions(this.path);
|
||||||
height() { return cmd(64,this.path).y; },
|
dim.x *= (this.rect.s1-this.rect.s0);
|
||||||
|
dim.y *= (this.rect.t1-this.rect.t0);
|
||||||
|
return dim;
|
||||||
|
},
|
||||||
|
width() { return this.dimensions().x; },
|
||||||
|
height() { return this.dimensions().y; },
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.freeze(sprite);
|
Object.freeze(sprite);
|
||||||
|
@ -160,7 +168,7 @@ var SpriteAnim = {
|
||||||
var anim = {};
|
var anim = {};
|
||||||
anim.frames = [];
|
anim.frames = [];
|
||||||
anim.path = path;
|
anim.path = path;
|
||||||
var frames = cmd(139,path);
|
var frames = Resources.gif.frames(path);
|
||||||
var yslice = 1/frames;
|
var yslice = 1/frames;
|
||||||
for (var f = 0; f < frames; f++) {
|
for (var f = 0; f < frames; f++) {
|
||||||
var frame = {};
|
var frame = {};
|
||||||
|
@ -174,9 +182,10 @@ var SpriteAnim = {
|
||||||
anim.frames.push(frame);
|
anim.frames.push(frame);
|
||||||
}
|
}
|
||||||
anim.loop = true;
|
anim.loop = true;
|
||||||
var dim = cmd(64,path);
|
var dim = Resources.texture.dimensions(path);
|
||||||
dim.y /= frames;
|
dim.y /= frames;
|
||||||
anim.dim = dim;
|
anim.dim = dim;
|
||||||
|
anim.toJSON = function() { return {}; };
|
||||||
return anim;
|
return anim;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -191,7 +200,7 @@ var SpriteAnim = {
|
||||||
frame.time = time;
|
frame.time = time;
|
||||||
anim.frames.push(frame);
|
anim.frames.push(frame);
|
||||||
}
|
}
|
||||||
anim.dim = cmd(64,path);
|
anim.dim = Resources.texture.dimensions(path);
|
||||||
anim.dim.x /= frames;
|
anim.dim.x /= frames;
|
||||||
return anim;
|
return anim;
|
||||||
},
|
},
|
||||||
|
@ -267,12 +276,7 @@ component.char2dimpl = {
|
||||||
},
|
},
|
||||||
|
|
||||||
anims:{},
|
anims:{},
|
||||||
|
acur:{},
|
||||||
sync() {
|
|
||||||
if (this.path)
|
|
||||||
cmd(12,this.id,this.path,this.rect);
|
|
||||||
},
|
|
||||||
|
|
||||||
frame: 0,
|
frame: 0,
|
||||||
|
|
||||||
play_anim(anim) {
|
play_anim(anim) {
|
||||||
|
@ -301,7 +305,8 @@ component.char2dimpl = {
|
||||||
},
|
},
|
||||||
|
|
||||||
setsprite() {
|
setsprite() {
|
||||||
cmd(12, this.id, this.acur.path, this.acur.frames[this.frame].rect);
|
this.rect = this.acur.frames[this.frame].rect;
|
||||||
|
this.path = this.path;
|
||||||
},
|
},
|
||||||
|
|
||||||
advance() {
|
advance() {
|
||||||
|
@ -340,9 +345,7 @@ component.char2dimpl = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.assign(component.char2d, component.char2dimpl);
|
component.char2dimpl.doc = {
|
||||||
|
|
||||||
component.char2d.doc = {
|
|
||||||
doc: "An animation player for sprites.",
|
doc: "An animation player for sprites.",
|
||||||
frame: "The current frame of animation.",
|
frame: "The current frame of animation.",
|
||||||
anims: "A list of all animations in this player.",
|
anims: "A list of all animations in this player.",
|
||||||
|
@ -357,6 +360,8 @@ component.char2d.doc = {
|
||||||
add_anim: "Add an animation object with the given name."
|
add_anim: "Add an animation object with the given name."
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Object.hide(component.char2dimpl, "doc");
|
||||||
|
|
||||||
/* Returns points specifying this geometry, with ccw */
|
/* Returns points specifying this geometry, with ccw */
|
||||||
var Geometry = {
|
var Geometry = {
|
||||||
box(w, h) {
|
box(w, h) {
|
||||||
|
|
|
@ -870,6 +870,7 @@ editor.inputs['M-t'] = function() { editor.edit_level.objects.forEach(function(x
|
||||||
editor.inputs['M-t'].doc = "Unlock all objects in current level.";
|
editor.inputs['M-t'].doc = "Unlock all objects in current level.";
|
||||||
|
|
||||||
editor.inputs['C-n'] = function() {
|
editor.inputs['C-n'] = function() {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
editor.inputs['C-n'].doc = "Create an empty object.";
|
editor.inputs['C-n'].doc = "Create an empty object.";
|
||||||
|
|
|
@ -480,10 +480,13 @@ var gameobject = {
|
||||||
transform() {
|
transform() {
|
||||||
var t = {};
|
var t = {};
|
||||||
t.pos = this.pos;
|
t.pos = this.pos;
|
||||||
|
if (t.pos.every(x=>x===0)) delete t.pos;
|
||||||
t.angle = Math.places(this.angle,4);
|
t.angle = Math.places(this.angle,4);
|
||||||
|
if (t.angle === 0) delete t.angle;
|
||||||
t.scale = this.scale;
|
t.scale = this.scale;
|
||||||
t.scale = t.scale.map((x,i) => x/this.__proto__.scale[i]);
|
t.scale = t.scale.map((x,i) => x/this.__proto__.scale[i]);
|
||||||
t.scale = t.scale.map(x => Math.places(x,3));
|
t.scale = t.scale.map(x => Math.places(x,3));
|
||||||
|
if (t.scale.every(x=>x===1)) delete t.scale;
|
||||||
return t;
|
return t;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,17 @@ Resources.is_sound = function(path) {
|
||||||
return Resources.sounds.any(x => x === ext);
|
return Resources.sounds.any(x => x === ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Resources.is_animation = function(path)
|
||||||
|
{
|
||||||
|
if (path.ext() === 'gif' && Resources.gif.frames(path) > 1) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Resources.texture = {};
|
||||||
|
Resources.texture.dimensions = function(path) { return cmd(64,path); }
|
||||||
|
|
||||||
|
Resources.gif = {};
|
||||||
|
Resources.gif.frames = function(path) { return cmd(139,path); }
|
||||||
|
|
||||||
var Log = {
|
var Log = {
|
||||||
set level(x) { cmd(92,x); },
|
set level(x) { cmd(92,x); },
|
||||||
get level() { return cmd(93); },
|
get level() { return cmd(93); },
|
||||||
|
|
Loading…
Reference in a new issue