53 lines
982 B
Plaintext
53 lines
982 B
Plaintext
// text2d.cm - Text factory
|
|
//
|
|
// Creates text data objects that register with film2d
|
|
|
|
var film2d = use('film2d')
|
|
|
|
var text2d_proto = {
|
|
type: 'text',
|
|
|
|
set_text: function(t) {
|
|
this.text = t
|
|
return this
|
|
},
|
|
|
|
set_pos: function(x, y) {
|
|
this.pos.x = x
|
|
this.pos.y = y
|
|
return this
|
|
},
|
|
|
|
destroy: function() {
|
|
film2d.unregister(this._id)
|
|
}
|
|
}
|
|
|
|
// Factory function - auto-registers with film2d
|
|
return function(props) {
|
|
var defaults = {
|
|
type: 'text',
|
|
text: "",
|
|
pos: {x: 0, y: 0},
|
|
plane: 'default',
|
|
layer: 0,
|
|
groups: [],
|
|
font: "fonts/dos",
|
|
size: 16,
|
|
color: {r: 1, g: 1, b: 1, a: 1},
|
|
opacity: 1,
|
|
tint: {r: 1, g: 1, b: 1, a: 1},
|
|
mode: null,
|
|
sdf: null,
|
|
outline_width: null,
|
|
outline_color: null
|
|
}
|
|
|
|
var data = {}
|
|
for(var k in defaults) data[k] = defaults[k]
|
|
for(var k in props) data[k] = props[k]
|
|
|
|
var newtext = meme(text2d_proto, data)
|
|
film2d.register(newtext)
|
|
return newtext
|
|
} |