id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
7,300 | melonjs/melonJS | dist/melonjs.js | isAttachedToRoot | function isAttachedToRoot() {
if (this.root === true) {
return true;
} else {
var ancestor = this.ancestor;
while (ancestor) {
if (ancestor.root === true) {
return true;
}
ancestor = ancestor.ancestor;
}
return false;
}
} | javascript | function isAttachedToRoot() {
if (this.root === true) {
return true;
} else {
var ancestor = this.ancestor;
while (ancestor) {
if (ancestor.root === true) {
return true;
}
ancestor = ancestor.ancestor;
}
return false;
}
} | [
"function",
"isAttachedToRoot",
"(",
")",
"{",
"if",
"(",
"this",
".",
"root",
"===",
"true",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"var",
"ancestor",
"=",
"this",
".",
"ancestor",
";",
"while",
"(",
"ancestor",
")",
"{",
"if",
"(",
"ancestor",
".",
"root",
"===",
"true",
")",
"{",
"return",
"true",
";",
"}",
"ancestor",
"=",
"ancestor",
".",
"ancestor",
";",
"}",
"return",
"false",
";",
"}",
"}"
] | Checks if this container is root or if it's attached to the root container.
@private
@name isAttachedToRoot
@memberOf me.Container.prototype
@function
@returns Boolean | [
"Checks",
"if",
"this",
"container",
"is",
"root",
"or",
"if",
"it",
"s",
"attached",
"to",
"the",
"root",
"container",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L11981-L11997 |
7,301 | melonjs/melonJS | dist/melonjs.js | removeChild | function removeChild(child, keepalive) {
if (this.hasChild(child)) {
me.utils.function.defer(deferredRemove, this, child, keepalive);
} else {
throw new Error("Child is not mine.");
}
} | javascript | function removeChild(child, keepalive) {
if (this.hasChild(child)) {
me.utils.function.defer(deferredRemove, this, child, keepalive);
} else {
throw new Error("Child is not mine.");
}
} | [
"function",
"removeChild",
"(",
"child",
",",
"keepalive",
")",
"{",
"if",
"(",
"this",
".",
"hasChild",
"(",
"child",
")",
")",
"{",
"me",
".",
"utils",
".",
"function",
".",
"defer",
"(",
"deferredRemove",
",",
"this",
",",
"child",
",",
"keepalive",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"\"Child is not mine.\"",
")",
";",
"}",
"}"
] | Invokes the removeChildNow in a defer, to ensure the child is removed safely after the update & draw stack has completed
@name removeChild
@memberOf me.Container.prototype
@public
@function
@param {me.Renderable} child
@param {Boolean} [keepalive=False] True to prevent calling child.destroy() | [
"Invokes",
"the",
"removeChildNow",
"in",
"a",
"defer",
"to",
"ensure",
"the",
"child",
"is",
"removed",
"safely",
"after",
"the",
"update",
"&",
"draw",
"stack",
"has",
"completed"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L12046-L12052 |
7,302 | melonjs/melonJS | dist/melonjs.js | setChildsProperty | function setChildsProperty(prop, val, recursive) {
for (var i = this.children.length; i >= 0; i--) {
var obj = this.children[i];
if (recursive === true && obj instanceof me.Container) {
obj.setChildsProperty(prop, val, recursive);
}
obj[prop] = val;
}
} | javascript | function setChildsProperty(prop, val, recursive) {
for (var i = this.children.length; i >= 0; i--) {
var obj = this.children[i];
if (recursive === true && obj instanceof me.Container) {
obj.setChildsProperty(prop, val, recursive);
}
obj[prop] = val;
}
} | [
"function",
"setChildsProperty",
"(",
"prop",
",",
"val",
",",
"recursive",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"this",
".",
"children",
".",
"length",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"obj",
"=",
"this",
".",
"children",
"[",
"i",
"]",
";",
"if",
"(",
"recursive",
"===",
"true",
"&&",
"obj",
"instanceof",
"me",
".",
"Container",
")",
"{",
"obj",
".",
"setChildsProperty",
"(",
"prop",
",",
"val",
",",
"recursive",
")",
";",
"}",
"obj",
"[",
"prop",
"]",
"=",
"val",
";",
"}",
"}"
] | Automatically set the specified property of all childs to the given value
@name setChildsProperty
@memberOf me.Container.prototype
@function
@param {String} property property name
@param {Object} value property value
@param {Boolean} [recursive=false] recursively apply the value to child containers if true | [
"Automatically",
"set",
"the",
"specified",
"property",
"of",
"all",
"childs",
"to",
"the",
"given",
"value"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L12100-L12110 |
7,303 | melonjs/melonJS | dist/melonjs.js | _sortZ | function _sortZ(a, b) {
return b.pos && a.pos ? b.pos.z - a.pos.z : a.pos ? -Infinity : Infinity;
} | javascript | function _sortZ(a, b) {
return b.pos && a.pos ? b.pos.z - a.pos.z : a.pos ? -Infinity : Infinity;
} | [
"function",
"_sortZ",
"(",
"a",
",",
"b",
")",
"{",
"return",
"b",
".",
"pos",
"&&",
"a",
".",
"pos",
"?",
"b",
".",
"pos",
".",
"z",
"-",
"a",
".",
"pos",
".",
"z",
":",
"a",
".",
"pos",
"?",
"-",
"Infinity",
":",
"Infinity",
";",
"}"
] | Z Sorting function
@ignore | [
"Z",
"Sorting",
"function"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L12230-L12232 |
7,304 | melonjs/melonJS | dist/melonjs.js | setDeadzone | function setDeadzone(w, h) {
if (typeof this.deadzone === "undefined") {
this.deadzone = new me.Rect(0, 0, 0, 0);
} // reusing the old code for now...
this.deadzone.pos.set(~~((this.width - w) / 2), ~~((this.height - h) / 2 - h * 0.25));
this.deadzone.resize(w, h);
this.smoothFollow = false; // force a camera update
this.updateTarget();
this.smoothFollow = true;
} | javascript | function setDeadzone(w, h) {
if (typeof this.deadzone === "undefined") {
this.deadzone = new me.Rect(0, 0, 0, 0);
} // reusing the old code for now...
this.deadzone.pos.set(~~((this.width - w) / 2), ~~((this.height - h) / 2 - h * 0.25));
this.deadzone.resize(w, h);
this.smoothFollow = false; // force a camera update
this.updateTarget();
this.smoothFollow = true;
} | [
"function",
"setDeadzone",
"(",
"w",
",",
"h",
")",
"{",
"if",
"(",
"typeof",
"this",
".",
"deadzone",
"===",
"\"undefined\"",
")",
"{",
"this",
".",
"deadzone",
"=",
"new",
"me",
".",
"Rect",
"(",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
";",
"}",
"// reusing the old code for now...",
"this",
".",
"deadzone",
".",
"pos",
".",
"set",
"(",
"~",
"~",
"(",
"(",
"this",
".",
"width",
"-",
"w",
")",
"/",
"2",
")",
",",
"~",
"~",
"(",
"(",
"this",
".",
"height",
"-",
"h",
")",
"/",
"2",
"-",
"h",
"*",
"0.25",
")",
")",
";",
"this",
".",
"deadzone",
".",
"resize",
"(",
"w",
",",
"h",
")",
";",
"this",
".",
"smoothFollow",
"=",
"false",
";",
"// force a camera update",
"this",
".",
"updateTarget",
"(",
")",
";",
"this",
".",
"smoothFollow",
"=",
"true",
";",
"}"
] | change the deadzone settings.
the "deadzone" defines an area within the current camera in which
the followed renderable can move without scrolling the camera.
@name setDeadzone
@see me.Camera2d.follow
@memberOf me.Camera2d
@function
@param {Number} w deadzone width
@param {Number} h deadzone height | [
"change",
"the",
"deadzone",
"settings",
".",
"the",
"deadzone",
"defines",
"an",
"area",
"within",
"the",
"current",
"camera",
"in",
"which",
"the",
"followed",
"renderable",
"can",
"move",
"without",
"scrolling",
"the",
"camera",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L12548-L12560 |
7,305 | melonjs/melonJS | dist/melonjs.js | resize | function resize(w, h) {
// parent consctructor, resize camera rect
this._super(me.Renderable, "resize", [w, h]); // disable damping while resizing
this.smoothFollow = false; // update bounds
var level = me.levelDirector.getCurrentLevel();
this.setBounds(0, 0, Math.max(w, level ? level.width : 0), Math.max(h, level ? level.height : 0)); // reset everthing
this.setDeadzone(w / 6, h / 6);
this.update();
this.smoothFollow = true;
me.event.publish(me.event.VIEWPORT_ONRESIZE, [this.width, this.height]);
return this;
} | javascript | function resize(w, h) {
// parent consctructor, resize camera rect
this._super(me.Renderable, "resize", [w, h]); // disable damping while resizing
this.smoothFollow = false; // update bounds
var level = me.levelDirector.getCurrentLevel();
this.setBounds(0, 0, Math.max(w, level ? level.width : 0), Math.max(h, level ? level.height : 0)); // reset everthing
this.setDeadzone(w / 6, h / 6);
this.update();
this.smoothFollow = true;
me.event.publish(me.event.VIEWPORT_ONRESIZE, [this.width, this.height]);
return this;
} | [
"function",
"resize",
"(",
"w",
",",
"h",
")",
"{",
"// parent consctructor, resize camera rect",
"this",
".",
"_super",
"(",
"me",
".",
"Renderable",
",",
"\"resize\"",
",",
"[",
"w",
",",
"h",
"]",
")",
";",
"// disable damping while resizing",
"this",
".",
"smoothFollow",
"=",
"false",
";",
"// update bounds",
"var",
"level",
"=",
"me",
".",
"levelDirector",
".",
"getCurrentLevel",
"(",
")",
";",
"this",
".",
"setBounds",
"(",
"0",
",",
"0",
",",
"Math",
".",
"max",
"(",
"w",
",",
"level",
"?",
"level",
".",
"width",
":",
"0",
")",
",",
"Math",
".",
"max",
"(",
"h",
",",
"level",
"?",
"level",
".",
"height",
":",
"0",
")",
")",
";",
"// reset everthing",
"this",
".",
"setDeadzone",
"(",
"w",
"/",
"6",
",",
"h",
"/",
"6",
")",
";",
"this",
".",
"update",
"(",
")",
";",
"this",
".",
"smoothFollow",
"=",
"true",
";",
"me",
".",
"event",
".",
"publish",
"(",
"me",
".",
"event",
".",
"VIEWPORT_ONRESIZE",
",",
"[",
"this",
".",
"width",
",",
"this",
".",
"height",
"]",
")",
";",
"return",
"this",
";",
"}"
] | resize the camera
@name resize
@memberOf me.Camera2d
@function
@param {Number} w new width of the camera
@param {Number} h new height of the camera
@return {me.Camera2d} this camera | [
"resize",
"the",
"camera"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L12571-L12586 |
7,306 | melonjs/melonJS | dist/melonjs.js | move | function move(x, y) {
this.moveTo(this.pos.x + x, this.pos.y + y);
} | javascript | function move(x, y) {
this.moveTo(this.pos.x + x, this.pos.y + y);
} | [
"function",
"move",
"(",
"x",
",",
"y",
")",
"{",
"this",
".",
"moveTo",
"(",
"this",
".",
"pos",
".",
"x",
"+",
"x",
",",
"this",
".",
"pos",
".",
"y",
"+",
"y",
")",
";",
"}"
] | move the camera upper-left position by the specified offset.
@name move
@memberOf me.Camera2d
@see me.Camera2d.focusOn
@function
@param {Number} x
@param {Number} y
@example
// Move the camera up by four pixels
me.game.viewport.move(0, -4); | [
"move",
"the",
"camera",
"upper",
"-",
"left",
"position",
"by",
"the",
"specified",
"offset",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L12668-L12670 |
7,307 | melonjs/melonJS | dist/melonjs.js | shake | function shake(intensity, duration, axis, onComplete, force) {
if (this._shake.duration === 0 || force === true) {
this._shake.intensity = intensity;
this._shake.duration = duration;
this._shake.axis = axis || this.AXIS.BOTH;
this._shake.onComplete = typeof onComplete === "function" ? onComplete : undefined;
}
} | javascript | function shake(intensity, duration, axis, onComplete, force) {
if (this._shake.duration === 0 || force === true) {
this._shake.intensity = intensity;
this._shake.duration = duration;
this._shake.axis = axis || this.AXIS.BOTH;
this._shake.onComplete = typeof onComplete === "function" ? onComplete : undefined;
}
} | [
"function",
"shake",
"(",
"intensity",
",",
"duration",
",",
"axis",
",",
"onComplete",
",",
"force",
")",
"{",
"if",
"(",
"this",
".",
"_shake",
".",
"duration",
"===",
"0",
"||",
"force",
"===",
"true",
")",
"{",
"this",
".",
"_shake",
".",
"intensity",
"=",
"intensity",
";",
"this",
".",
"_shake",
".",
"duration",
"=",
"duration",
";",
"this",
".",
"_shake",
".",
"axis",
"=",
"axis",
"||",
"this",
".",
"AXIS",
".",
"BOTH",
";",
"this",
".",
"_shake",
".",
"onComplete",
"=",
"typeof",
"onComplete",
"===",
"\"function\"",
"?",
"onComplete",
":",
"undefined",
";",
"}",
"}"
] | shake the camera
@name shake
@memberOf me.Camera2d
@function
@param {Number} intensity maximum offset that the screen can be moved
while shaking
@param {Number} duration expressed in milliseconds
@param {me.Camera2d.AXIS} [axis=this.AXIS.BOTH] specify on which axis you
want the shake effect
@param {Function} [onComplete] callback once shaking effect is over
@param {Boolean} [force] if true this will override the current effect
@example
// shake it baby !
me.game.viewport.shake(10, 500, me.game.viewport.AXIS.BOTH); | [
"shake",
"the",
"camera"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L12797-L12804 |
7,308 | melonjs/melonJS | dist/melonjs.js | drawFX | function drawFX(renderer) {
// fading effect
if (this._fadeIn.tween) {
renderer.clearColor(this._fadeIn.color); // remove the tween if over
if (this._fadeIn.color.alpha === 1.0) {
this._fadeIn.tween = null;
me.pool.push(this._fadeIn.color);
this._fadeIn.color = null;
}
} // flashing effect
if (this._fadeOut.tween) {
renderer.clearColor(this._fadeOut.color); // remove the tween if over
if (this._fadeOut.color.alpha === 0.0) {
this._fadeOut.tween = null;
me.pool.push(this._fadeOut.color);
this._fadeOut.color = null;
}
}
} | javascript | function drawFX(renderer) {
// fading effect
if (this._fadeIn.tween) {
renderer.clearColor(this._fadeIn.color); // remove the tween if over
if (this._fadeIn.color.alpha === 1.0) {
this._fadeIn.tween = null;
me.pool.push(this._fadeIn.color);
this._fadeIn.color = null;
}
} // flashing effect
if (this._fadeOut.tween) {
renderer.clearColor(this._fadeOut.color); // remove the tween if over
if (this._fadeOut.color.alpha === 0.0) {
this._fadeOut.tween = null;
me.pool.push(this._fadeOut.color);
this._fadeOut.color = null;
}
}
} | [
"function",
"drawFX",
"(",
"renderer",
")",
"{",
"// fading effect",
"if",
"(",
"this",
".",
"_fadeIn",
".",
"tween",
")",
"{",
"renderer",
".",
"clearColor",
"(",
"this",
".",
"_fadeIn",
".",
"color",
")",
";",
"// remove the tween if over",
"if",
"(",
"this",
".",
"_fadeIn",
".",
"color",
".",
"alpha",
"===",
"1.0",
")",
"{",
"this",
".",
"_fadeIn",
".",
"tween",
"=",
"null",
";",
"me",
".",
"pool",
".",
"push",
"(",
"this",
".",
"_fadeIn",
".",
"color",
")",
";",
"this",
".",
"_fadeIn",
".",
"color",
"=",
"null",
";",
"}",
"}",
"// flashing effect",
"if",
"(",
"this",
".",
"_fadeOut",
".",
"tween",
")",
"{",
"renderer",
".",
"clearColor",
"(",
"this",
".",
"_fadeOut",
".",
"color",
")",
";",
"// remove the tween if over",
"if",
"(",
"this",
".",
"_fadeOut",
".",
"color",
".",
"alpha",
"===",
"0.0",
")",
"{",
"this",
".",
"_fadeOut",
".",
"tween",
"=",
"null",
";",
"me",
".",
"pool",
".",
"push",
"(",
"this",
".",
"_fadeOut",
".",
"color",
")",
";",
"this",
".",
"_fadeOut",
".",
"color",
"=",
"null",
";",
"}",
"}",
"}"
] | render the camera effects
@ignore | [
"render",
"the",
"camera",
"effects"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L12961-L12983 |
7,309 | melonjs/melonJS | dist/melonjs.js | draw | function draw(renderer, container) {
var translateX = this.pos.x + this.offset.x;
var translateY = this.pos.y + this.offset.y; // translate the world coordinates by default to screen coordinates
container.currentTransform.translate(-translateX, -translateY); // clip to camera bounds
renderer.clipRect(0, 0, this.width, this.height);
this.preDraw(renderer);
container.preDraw(renderer); // draw all objects,
// specifying the viewport as the rectangle area to redraw
container.draw(renderer, this); // draw the viewport/camera effects
this.drawFX(renderer);
container.postDraw(renderer);
this.postDraw(renderer); // translate the world coordinates by default to screen coordinates
container.currentTransform.translate(translateX, translateY);
} | javascript | function draw(renderer, container) {
var translateX = this.pos.x + this.offset.x;
var translateY = this.pos.y + this.offset.y; // translate the world coordinates by default to screen coordinates
container.currentTransform.translate(-translateX, -translateY); // clip to camera bounds
renderer.clipRect(0, 0, this.width, this.height);
this.preDraw(renderer);
container.preDraw(renderer); // draw all objects,
// specifying the viewport as the rectangle area to redraw
container.draw(renderer, this); // draw the viewport/camera effects
this.drawFX(renderer);
container.postDraw(renderer);
this.postDraw(renderer); // translate the world coordinates by default to screen coordinates
container.currentTransform.translate(translateX, translateY);
} | [
"function",
"draw",
"(",
"renderer",
",",
"container",
")",
"{",
"var",
"translateX",
"=",
"this",
".",
"pos",
".",
"x",
"+",
"this",
".",
"offset",
".",
"x",
";",
"var",
"translateY",
"=",
"this",
".",
"pos",
".",
"y",
"+",
"this",
".",
"offset",
".",
"y",
";",
"// translate the world coordinates by default to screen coordinates",
"container",
".",
"currentTransform",
".",
"translate",
"(",
"-",
"translateX",
",",
"-",
"translateY",
")",
";",
"// clip to camera bounds",
"renderer",
".",
"clipRect",
"(",
"0",
",",
"0",
",",
"this",
".",
"width",
",",
"this",
".",
"height",
")",
";",
"this",
".",
"preDraw",
"(",
"renderer",
")",
";",
"container",
".",
"preDraw",
"(",
"renderer",
")",
";",
"// draw all objects,",
"// specifying the viewport as the rectangle area to redraw",
"container",
".",
"draw",
"(",
"renderer",
",",
"this",
")",
";",
"// draw the viewport/camera effects",
"this",
".",
"drawFX",
"(",
"renderer",
")",
";",
"container",
".",
"postDraw",
"(",
"renderer",
")",
";",
"this",
".",
"postDraw",
"(",
"renderer",
")",
";",
"// translate the world coordinates by default to screen coordinates",
"container",
".",
"currentTransform",
".",
"translate",
"(",
"translateX",
",",
"translateY",
")",
";",
"}"
] | draw all object visibile in this viewport
@ignore | [
"draw",
"all",
"object",
"visibile",
"in",
"this",
"viewport"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L12989-L13007 |
7,310 | melonjs/melonJS | dist/melonjs.js | distanceTo | function distanceTo(e) {
var a = this.getBounds();
var b = e.getBounds(); // the me.Vector2d object also implements the same function, but
// we have to use here the center of both entities
var dx = a.pos.x + a.width / 2 - (b.pos.x + b.width / 2);
var dy = a.pos.y + a.height / 2 - (b.pos.y + b.height / 2);
return Math.sqrt(dx * dx + dy * dy);
} | javascript | function distanceTo(e) {
var a = this.getBounds();
var b = e.getBounds(); // the me.Vector2d object also implements the same function, but
// we have to use here the center of both entities
var dx = a.pos.x + a.width / 2 - (b.pos.x + b.width / 2);
var dy = a.pos.y + a.height / 2 - (b.pos.y + b.height / 2);
return Math.sqrt(dx * dx + dy * dy);
} | [
"function",
"distanceTo",
"(",
"e",
")",
"{",
"var",
"a",
"=",
"this",
".",
"getBounds",
"(",
")",
";",
"var",
"b",
"=",
"e",
".",
"getBounds",
"(",
")",
";",
"// the me.Vector2d object also implements the same function, but",
"// we have to use here the center of both entities",
"var",
"dx",
"=",
"a",
".",
"pos",
".",
"x",
"+",
"a",
".",
"width",
"/",
"2",
"-",
"(",
"b",
".",
"pos",
".",
"x",
"+",
"b",
".",
"width",
"/",
"2",
")",
";",
"var",
"dy",
"=",
"a",
".",
"pos",
".",
"y",
"+",
"a",
".",
"height",
"/",
"2",
"-",
"(",
"b",
".",
"pos",
".",
"y",
"+",
"b",
".",
"height",
"/",
"2",
")",
";",
"return",
"Math",
".",
"sqrt",
"(",
"dx",
"*",
"dx",
"+",
"dy",
"*",
"dy",
")",
";",
"}"
] | return the distance to the specified entity
@name distanceTo
@memberOf me.Entity
@function
@param {me.Entity} entity Entity
@return {Number} distance | [
"return",
"the",
"distance",
"to",
"the",
"specified",
"entity"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L13146-L13154 |
7,311 | melonjs/melonJS | dist/melonjs.js | distanceToPoint | function distanceToPoint(v) {
var a = this.getBounds(); // the me.Vector2d object also implements the same function, but
// we have to use here the center of both entities
var dx = a.pos.x + a.width / 2 - v.x;
var dy = a.pos.y + a.height / 2 - v.y;
return Math.sqrt(dx * dx + dy * dy);
} | javascript | function distanceToPoint(v) {
var a = this.getBounds(); // the me.Vector2d object also implements the same function, but
// we have to use here the center of both entities
var dx = a.pos.x + a.width / 2 - v.x;
var dy = a.pos.y + a.height / 2 - v.y;
return Math.sqrt(dx * dx + dy * dy);
} | [
"function",
"distanceToPoint",
"(",
"v",
")",
"{",
"var",
"a",
"=",
"this",
".",
"getBounds",
"(",
")",
";",
"// the me.Vector2d object also implements the same function, but",
"// we have to use here the center of both entities",
"var",
"dx",
"=",
"a",
".",
"pos",
".",
"x",
"+",
"a",
".",
"width",
"/",
"2",
"-",
"v",
".",
"x",
";",
"var",
"dy",
"=",
"a",
".",
"pos",
".",
"y",
"+",
"a",
".",
"height",
"/",
"2",
"-",
"v",
".",
"y",
";",
"return",
"Math",
".",
"sqrt",
"(",
"dx",
"*",
"dx",
"+",
"dy",
"*",
"dy",
")",
";",
"}"
] | return the distance to the specified point
@name distanceToPoint
@memberOf me.Entity
@function
@param {me.Vector2d} vector vector
@return {Number} distance | [
"return",
"the",
"distance",
"to",
"the",
"specified",
"point"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L13164-L13171 |
7,312 | melonjs/melonJS | dist/melonjs.js | angleTo | function angleTo(e) {
var a = this.getBounds();
var b = e.getBounds(); // the me.Vector2d object also implements the same function, but
// we have to use here the center of both entities
var ax = b.pos.x + b.width / 2 - (a.pos.x + a.width / 2);
var ay = b.pos.y + b.height / 2 - (a.pos.y + a.height / 2);
return Math.atan2(ay, ax);
} | javascript | function angleTo(e) {
var a = this.getBounds();
var b = e.getBounds(); // the me.Vector2d object also implements the same function, but
// we have to use here the center of both entities
var ax = b.pos.x + b.width / 2 - (a.pos.x + a.width / 2);
var ay = b.pos.y + b.height / 2 - (a.pos.y + a.height / 2);
return Math.atan2(ay, ax);
} | [
"function",
"angleTo",
"(",
"e",
")",
"{",
"var",
"a",
"=",
"this",
".",
"getBounds",
"(",
")",
";",
"var",
"b",
"=",
"e",
".",
"getBounds",
"(",
")",
";",
"// the me.Vector2d object also implements the same function, but",
"// we have to use here the center of both entities",
"var",
"ax",
"=",
"b",
".",
"pos",
".",
"x",
"+",
"b",
".",
"width",
"/",
"2",
"-",
"(",
"a",
".",
"pos",
".",
"x",
"+",
"a",
".",
"width",
"/",
"2",
")",
";",
"var",
"ay",
"=",
"b",
".",
"pos",
".",
"y",
"+",
"b",
".",
"height",
"/",
"2",
"-",
"(",
"a",
".",
"pos",
".",
"y",
"+",
"a",
".",
"height",
"/",
"2",
")",
";",
"return",
"Math",
".",
"atan2",
"(",
"ay",
",",
"ax",
")",
";",
"}"
] | return the angle to the specified entity
@name angleTo
@memberOf me.Entity
@function
@param {me.Entity} entity Entity
@return {Number} angle in radians | [
"return",
"the",
"angle",
"to",
"the",
"specified",
"entity"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L13181-L13189 |
7,313 | melonjs/melonJS | dist/melonjs.js | angleToPoint | function angleToPoint(v) {
var a = this.getBounds(); // the me.Vector2d object also implements the same function, but
// we have to use here the center of both entities
var ax = v.x - (a.pos.x + a.width / 2);
var ay = v.y - (a.pos.y + a.height / 2);
return Math.atan2(ay, ax);
} | javascript | function angleToPoint(v) {
var a = this.getBounds(); // the me.Vector2d object also implements the same function, but
// we have to use here the center of both entities
var ax = v.x - (a.pos.x + a.width / 2);
var ay = v.y - (a.pos.y + a.height / 2);
return Math.atan2(ay, ax);
} | [
"function",
"angleToPoint",
"(",
"v",
")",
"{",
"var",
"a",
"=",
"this",
".",
"getBounds",
"(",
")",
";",
"// the me.Vector2d object also implements the same function, but",
"// we have to use here the center of both entities",
"var",
"ax",
"=",
"v",
".",
"x",
"-",
"(",
"a",
".",
"pos",
".",
"x",
"+",
"a",
".",
"width",
"/",
"2",
")",
";",
"var",
"ay",
"=",
"v",
".",
"y",
"-",
"(",
"a",
".",
"pos",
".",
"y",
"+",
"a",
".",
"height",
"/",
"2",
")",
";",
"return",
"Math",
".",
"atan2",
"(",
"ay",
",",
"ax",
")",
";",
"}"
] | return the angle to the specified point
@name angleToPoint
@memberOf me.Entity
@function
@param {me.Vector2d} vector vector
@return {Number} angle in radians | [
"return",
"the",
"angle",
"to",
"the",
"specified",
"point"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L13199-L13206 |
7,314 | melonjs/melonJS | dist/melonjs.js | updateBoundsPos | function updateBoundsPos(x, y) {
if (typeof this.body !== "undefined") {
var _pos = this.body.pos;
this._super(me.Renderable, "updateBoundsPos", [x + _pos.x, y + _pos.y]);
} else {
this._super(me.Renderable, "updateBoundsPos", [x, y]);
}
return this.getBounds();
} | javascript | function updateBoundsPos(x, y) {
if (typeof this.body !== "undefined") {
var _pos = this.body.pos;
this._super(me.Renderable, "updateBoundsPos", [x + _pos.x, y + _pos.y]);
} else {
this._super(me.Renderable, "updateBoundsPos", [x, y]);
}
return this.getBounds();
} | [
"function",
"updateBoundsPos",
"(",
"x",
",",
"y",
")",
"{",
"if",
"(",
"typeof",
"this",
".",
"body",
"!==",
"\"undefined\"",
")",
"{",
"var",
"_pos",
"=",
"this",
".",
"body",
".",
"pos",
";",
"this",
".",
"_super",
"(",
"me",
".",
"Renderable",
",",
"\"updateBoundsPos\"",
",",
"[",
"x",
"+",
"_pos",
".",
"x",
",",
"y",
"+",
"_pos",
".",
"y",
"]",
")",
";",
"}",
"else",
"{",
"this",
".",
"_super",
"(",
"me",
".",
"Renderable",
",",
"\"updateBoundsPos\"",
",",
"[",
"x",
",",
"y",
"]",
")",
";",
"}",
"return",
"this",
".",
"getBounds",
"(",
")",
";",
"}"
] | update the bounds position when the position is modified
@private
@name updateBoundsPos
@memberOf me.Entity
@function | [
"update",
"the",
"bounds",
"position",
"when",
"the",
"position",
"is",
"modified"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L13224-L13234 |
7,315 | melonjs/melonJS | dist/melonjs.js | preloadTMX | function preloadTMX(tmxData, onload, onerror) {
function addToTMXList(data) {
// set the TMX content
tmxList[tmxData.name] = data; // add the tmx to the levelDirector
if (tmxData.type === "tmx") {
me.levelDirector.addTMXLevel(tmxData.name);
}
} //if the data is in the tmxData object, don't get it via a XMLHTTPRequest
if (tmxData.data) {
addToTMXList(tmxData.data);
onload();
return;
}
var xmlhttp = new XMLHttpRequest(); // check the data format ('tmx', 'json')
var format = me.utils.file.getExtension(tmxData.src);
if (xmlhttp.overrideMimeType) {
if (format === "json") {
xmlhttp.overrideMimeType("application/json");
} else {
xmlhttp.overrideMimeType("text/xml");
}
}
xmlhttp.open("GET", tmxData.src + api.nocache, true);
xmlhttp.withCredentials = me.loader.withCredentials; // set the callbacks
xmlhttp.ontimeout = onerror;
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState === 4) {
// status = 0 when file protocol is used, or cross-domain origin,
// (With Chrome use "--allow-file-access-from-files --disable-web-security")
if (xmlhttp.status === 200 || xmlhttp.status === 0 && xmlhttp.responseText) {
var result = null; // parse response
switch (format) {
case "xml":
case "tmx":
case "tsx":
// ie9 does not fully implement the responseXML
if (me.device.ua.match(/msie/i) || !xmlhttp.responseXML) {
if (window.DOMParser) {
// manually create the XML DOM
result = new DOMParser().parseFromString(xmlhttp.responseText, "text/xml");
} else {
throw new Error("XML file format loading not supported, use the JSON file format instead");
}
} else {
result = xmlhttp.responseXML;
} // converts to a JS object
var data = me.TMXUtils.parse(result);
switch (format) {
case "tmx":
result = data.map;
break;
case "tsx":
result = data.tilesets[0];
break;
}
break;
case "json":
result = JSON.parse(xmlhttp.responseText);
break;
default:
throw new Error("TMX file format " + format + "not supported !");
} //set the TMX content
addToTMXList(result); // fire the callback
onload();
} else {
onerror(tmxData.name);
}
}
}; // send the request
xmlhttp.send();
} | javascript | function preloadTMX(tmxData, onload, onerror) {
function addToTMXList(data) {
// set the TMX content
tmxList[tmxData.name] = data; // add the tmx to the levelDirector
if (tmxData.type === "tmx") {
me.levelDirector.addTMXLevel(tmxData.name);
}
} //if the data is in the tmxData object, don't get it via a XMLHTTPRequest
if (tmxData.data) {
addToTMXList(tmxData.data);
onload();
return;
}
var xmlhttp = new XMLHttpRequest(); // check the data format ('tmx', 'json')
var format = me.utils.file.getExtension(tmxData.src);
if (xmlhttp.overrideMimeType) {
if (format === "json") {
xmlhttp.overrideMimeType("application/json");
} else {
xmlhttp.overrideMimeType("text/xml");
}
}
xmlhttp.open("GET", tmxData.src + api.nocache, true);
xmlhttp.withCredentials = me.loader.withCredentials; // set the callbacks
xmlhttp.ontimeout = onerror;
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState === 4) {
// status = 0 when file protocol is used, or cross-domain origin,
// (With Chrome use "--allow-file-access-from-files --disable-web-security")
if (xmlhttp.status === 200 || xmlhttp.status === 0 && xmlhttp.responseText) {
var result = null; // parse response
switch (format) {
case "xml":
case "tmx":
case "tsx":
// ie9 does not fully implement the responseXML
if (me.device.ua.match(/msie/i) || !xmlhttp.responseXML) {
if (window.DOMParser) {
// manually create the XML DOM
result = new DOMParser().parseFromString(xmlhttp.responseText, "text/xml");
} else {
throw new Error("XML file format loading not supported, use the JSON file format instead");
}
} else {
result = xmlhttp.responseXML;
} // converts to a JS object
var data = me.TMXUtils.parse(result);
switch (format) {
case "tmx":
result = data.map;
break;
case "tsx":
result = data.tilesets[0];
break;
}
break;
case "json":
result = JSON.parse(xmlhttp.responseText);
break;
default:
throw new Error("TMX file format " + format + "not supported !");
} //set the TMX content
addToTMXList(result); // fire the callback
onload();
} else {
onerror(tmxData.name);
}
}
}; // send the request
xmlhttp.send();
} | [
"function",
"preloadTMX",
"(",
"tmxData",
",",
"onload",
",",
"onerror",
")",
"{",
"function",
"addToTMXList",
"(",
"data",
")",
"{",
"// set the TMX content",
"tmxList",
"[",
"tmxData",
".",
"name",
"]",
"=",
"data",
";",
"// add the tmx to the levelDirector",
"if",
"(",
"tmxData",
".",
"type",
"===",
"\"tmx\"",
")",
"{",
"me",
".",
"levelDirector",
".",
"addTMXLevel",
"(",
"tmxData",
".",
"name",
")",
";",
"}",
"}",
"//if the data is in the tmxData object, don't get it via a XMLHTTPRequest",
"if",
"(",
"tmxData",
".",
"data",
")",
"{",
"addToTMXList",
"(",
"tmxData",
".",
"data",
")",
";",
"onload",
"(",
")",
";",
"return",
";",
"}",
"var",
"xmlhttp",
"=",
"new",
"XMLHttpRequest",
"(",
")",
";",
"// check the data format ('tmx', 'json')",
"var",
"format",
"=",
"me",
".",
"utils",
".",
"file",
".",
"getExtension",
"(",
"tmxData",
".",
"src",
")",
";",
"if",
"(",
"xmlhttp",
".",
"overrideMimeType",
")",
"{",
"if",
"(",
"format",
"===",
"\"json\"",
")",
"{",
"xmlhttp",
".",
"overrideMimeType",
"(",
"\"application/json\"",
")",
";",
"}",
"else",
"{",
"xmlhttp",
".",
"overrideMimeType",
"(",
"\"text/xml\"",
")",
";",
"}",
"}",
"xmlhttp",
".",
"open",
"(",
"\"GET\"",
",",
"tmxData",
".",
"src",
"+",
"api",
".",
"nocache",
",",
"true",
")",
";",
"xmlhttp",
".",
"withCredentials",
"=",
"me",
".",
"loader",
".",
"withCredentials",
";",
"// set the callbacks",
"xmlhttp",
".",
"ontimeout",
"=",
"onerror",
";",
"xmlhttp",
".",
"onreadystatechange",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"xmlhttp",
".",
"readyState",
"===",
"4",
")",
"{",
"// status = 0 when file protocol is used, or cross-domain origin,",
"// (With Chrome use \"--allow-file-access-from-files --disable-web-security\")",
"if",
"(",
"xmlhttp",
".",
"status",
"===",
"200",
"||",
"xmlhttp",
".",
"status",
"===",
"0",
"&&",
"xmlhttp",
".",
"responseText",
")",
"{",
"var",
"result",
"=",
"null",
";",
"// parse response",
"switch",
"(",
"format",
")",
"{",
"case",
"\"xml\"",
":",
"case",
"\"tmx\"",
":",
"case",
"\"tsx\"",
":",
"// ie9 does not fully implement the responseXML",
"if",
"(",
"me",
".",
"device",
".",
"ua",
".",
"match",
"(",
"/",
"msie",
"/",
"i",
")",
"||",
"!",
"xmlhttp",
".",
"responseXML",
")",
"{",
"if",
"(",
"window",
".",
"DOMParser",
")",
"{",
"// manually create the XML DOM",
"result",
"=",
"new",
"DOMParser",
"(",
")",
".",
"parseFromString",
"(",
"xmlhttp",
".",
"responseText",
",",
"\"text/xml\"",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"\"XML file format loading not supported, use the JSON file format instead\"",
")",
";",
"}",
"}",
"else",
"{",
"result",
"=",
"xmlhttp",
".",
"responseXML",
";",
"}",
"// converts to a JS object",
"var",
"data",
"=",
"me",
".",
"TMXUtils",
".",
"parse",
"(",
"result",
")",
";",
"switch",
"(",
"format",
")",
"{",
"case",
"\"tmx\"",
":",
"result",
"=",
"data",
".",
"map",
";",
"break",
";",
"case",
"\"tsx\"",
":",
"result",
"=",
"data",
".",
"tilesets",
"[",
"0",
"]",
";",
"break",
";",
"}",
"break",
";",
"case",
"\"json\"",
":",
"result",
"=",
"JSON",
".",
"parse",
"(",
"xmlhttp",
".",
"responseText",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Error",
"(",
"\"TMX file format \"",
"+",
"format",
"+",
"\"not supported !\"",
")",
";",
"}",
"//set the TMX content",
"addToTMXList",
"(",
"result",
")",
";",
"// fire the callback",
"onload",
"(",
")",
";",
"}",
"else",
"{",
"onerror",
"(",
"tmxData",
".",
"name",
")",
";",
"}",
"}",
"}",
";",
"// send the request",
"xmlhttp",
".",
"send",
"(",
")",
";",
"}"
] | preload TMX files
@ignore | [
"preload",
"TMX",
"files"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L14360-L14452 |
7,316 | melonjs/melonJS | dist/melonjs.js | setFont | function setFont(font, size) {
// font name and type
var font_names = font.split(",").map(function (value) {
value = value.trim();
return !/(^".*"$)|(^'.*'$)/.test(value) ? "\"" + value + "\"" : value;
}); // font size
if (typeof size === "number") {
this._fontSize = size;
size += "px";
} else
/* string */
{
// extract the units and convert if necessary
var CSSval = size.match(/([-+]?[\d.]*)(.*)/);
this._fontSize = parseFloat(CSSval[1]);
if (CSSval[2]) {
this._fontSize *= toPX[runits.indexOf(CSSval[2])];
} else {
// no unit define, assume px
size += "px";
}
}
this.height = this._fontSize;
this.font = size + " " + font_names.join(",");
this.isDirty = true;
return this;
} | javascript | function setFont(font, size) {
// font name and type
var font_names = font.split(",").map(function (value) {
value = value.trim();
return !/(^".*"$)|(^'.*'$)/.test(value) ? "\"" + value + "\"" : value;
}); // font size
if (typeof size === "number") {
this._fontSize = size;
size += "px";
} else
/* string */
{
// extract the units and convert if necessary
var CSSval = size.match(/([-+]?[\d.]*)(.*)/);
this._fontSize = parseFloat(CSSval[1]);
if (CSSval[2]) {
this._fontSize *= toPX[runits.indexOf(CSSval[2])];
} else {
// no unit define, assume px
size += "px";
}
}
this.height = this._fontSize;
this.font = size + " " + font_names.join(",");
this.isDirty = true;
return this;
} | [
"function",
"setFont",
"(",
"font",
",",
"size",
")",
"{",
"// font name and type",
"var",
"font_names",
"=",
"font",
".",
"split",
"(",
"\",\"",
")",
".",
"map",
"(",
"function",
"(",
"value",
")",
"{",
"value",
"=",
"value",
".",
"trim",
"(",
")",
";",
"return",
"!",
"/",
"(^\".*\"$)|(^'.*'$)",
"/",
".",
"test",
"(",
"value",
")",
"?",
"\"\\\"\"",
"+",
"value",
"+",
"\"\\\"\"",
":",
"value",
";",
"}",
")",
";",
"// font size",
"if",
"(",
"typeof",
"size",
"===",
"\"number\"",
")",
"{",
"this",
".",
"_fontSize",
"=",
"size",
";",
"size",
"+=",
"\"px\"",
";",
"}",
"else",
"/* string */",
"{",
"// extract the units and convert if necessary",
"var",
"CSSval",
"=",
"size",
".",
"match",
"(",
"/",
"([-+]?[\\d.]*)(.*)",
"/",
")",
";",
"this",
".",
"_fontSize",
"=",
"parseFloat",
"(",
"CSSval",
"[",
"1",
"]",
")",
";",
"if",
"(",
"CSSval",
"[",
"2",
"]",
")",
"{",
"this",
".",
"_fontSize",
"*=",
"toPX",
"[",
"runits",
".",
"indexOf",
"(",
"CSSval",
"[",
"2",
"]",
")",
"]",
";",
"}",
"else",
"{",
"// no unit define, assume px",
"size",
"+=",
"\"px\"",
";",
"}",
"}",
"this",
".",
"height",
"=",
"this",
".",
"_fontSize",
";",
"this",
".",
"font",
"=",
"size",
"+",
"\" \"",
"+",
"font_names",
".",
"join",
"(",
"\",\"",
")",
";",
"this",
".",
"isDirty",
"=",
"true",
";",
"return",
"this",
";",
"}"
] | set the font family and size
@name setFont
@memberOf me.Text.prototype
@function
@param {String} font a CSS font name
@param {Number|String} size size, or size + suffix (px, em, pt)
@return this object for chaining
@example
font.setFont("Arial", 20);
font.setFont("Arial", "1.5em"); | [
"set",
"the",
"font",
"family",
"and",
"size"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L15253-L15282 |
7,317 | melonjs/melonJS | dist/melonjs.js | setText | function setText(value) {
value = "" + value;
if (this._text !== value) {
if (Array.isArray(value)) {
this._text = value.join("\n");
} else {
this._text = value;
}
this.isDirty = true;
}
return this;
} | javascript | function setText(value) {
value = "" + value;
if (this._text !== value) {
if (Array.isArray(value)) {
this._text = value.join("\n");
} else {
this._text = value;
}
this.isDirty = true;
}
return this;
} | [
"function",
"setText",
"(",
"value",
")",
"{",
"value",
"=",
"\"\"",
"+",
"value",
";",
"if",
"(",
"this",
".",
"_text",
"!==",
"value",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"this",
".",
"_text",
"=",
"value",
".",
"join",
"(",
"\"\\n\"",
")",
";",
"}",
"else",
"{",
"this",
".",
"_text",
"=",
"value",
";",
"}",
"this",
".",
"isDirty",
"=",
"true",
";",
"}",
"return",
"this",
";",
"}"
] | change the text to be displayed
@name setText
@memberOf me.Text.prototype
@function
@param {Number|String|String[]} value a string, or an array of strings
@return this object for chaining | [
"change",
"the",
"text",
"to",
"be",
"displayed"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L15292-L15306 |
7,318 | melonjs/melonJS | dist/melonjs.js | measureTextWidth | function measureTextWidth(font, text) {
var characters = text.split("");
var width = 0;
var lastGlyph = null;
for (var i = 0; i < characters.length; i++) {
var ch = characters[i].charCodeAt(0);
var glyph = font.fontData.glyphs[ch];
var kerning = lastGlyph && lastGlyph.kerning ? lastGlyph.getKerning(ch) : 0;
width += (glyph.xadvance + kerning) * font.fontScale.x;
lastGlyph = glyph;
}
return width;
} | javascript | function measureTextWidth(font, text) {
var characters = text.split("");
var width = 0;
var lastGlyph = null;
for (var i = 0; i < characters.length; i++) {
var ch = characters[i].charCodeAt(0);
var glyph = font.fontData.glyphs[ch];
var kerning = lastGlyph && lastGlyph.kerning ? lastGlyph.getKerning(ch) : 0;
width += (glyph.xadvance + kerning) * font.fontScale.x;
lastGlyph = glyph;
}
return width;
} | [
"function",
"measureTextWidth",
"(",
"font",
",",
"text",
")",
"{",
"var",
"characters",
"=",
"text",
".",
"split",
"(",
"\"\"",
")",
";",
"var",
"width",
"=",
"0",
";",
"var",
"lastGlyph",
"=",
"null",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"characters",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"ch",
"=",
"characters",
"[",
"i",
"]",
".",
"charCodeAt",
"(",
"0",
")",
";",
"var",
"glyph",
"=",
"font",
".",
"fontData",
".",
"glyphs",
"[",
"ch",
"]",
";",
"var",
"kerning",
"=",
"lastGlyph",
"&&",
"lastGlyph",
".",
"kerning",
"?",
"lastGlyph",
".",
"getKerning",
"(",
"ch",
")",
":",
"0",
";",
"width",
"+=",
"(",
"glyph",
".",
"xadvance",
"+",
"kerning",
")",
"*",
"font",
".",
"fontScale",
".",
"x",
";",
"lastGlyph",
"=",
"glyph",
";",
"}",
"return",
"width",
";",
"}"
] | Measures the width of a single line of text, does not account for \n
@ignore | [
"Measures",
"the",
"width",
"of",
"a",
"single",
"line",
"of",
"text",
"does",
"not",
"account",
"for",
"\\",
"n"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L15476-L15490 |
7,319 | melonjs/melonJS | dist/melonjs.js | measureTextHeight | function measureTextHeight(font) {
return font.fontData.capHeight * font.lineHeight * font.fontScale.y;
} | javascript | function measureTextHeight(font) {
return font.fontData.capHeight * font.lineHeight * font.fontScale.y;
} | [
"function",
"measureTextHeight",
"(",
"font",
")",
"{",
"return",
"font",
".",
"fontData",
".",
"capHeight",
"*",
"font",
".",
"lineHeight",
"*",
"font",
".",
"fontScale",
".",
"y",
";",
"}"
] | Measures the height of a single line of text, does not account for \n
@ignore | [
"Measures",
"the",
"height",
"of",
"a",
"single",
"line",
"of",
"text",
"does",
"not",
"account",
"for",
"\\",
"n"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L15497-L15499 |
7,320 | melonjs/melonJS | dist/melonjs.js | set | function set(textAlign, scale) {
this.textAlign = textAlign; // updated scaled Size
if (scale) {
this.resize(scale);
}
this.isDirty = true;
return this;
} | javascript | function set(textAlign, scale) {
this.textAlign = textAlign; // updated scaled Size
if (scale) {
this.resize(scale);
}
this.isDirty = true;
return this;
} | [
"function",
"set",
"(",
"textAlign",
",",
"scale",
")",
"{",
"this",
".",
"textAlign",
"=",
"textAlign",
";",
"// updated scaled Size",
"if",
"(",
"scale",
")",
"{",
"this",
".",
"resize",
"(",
"scale",
")",
";",
"}",
"this",
".",
"isDirty",
"=",
"true",
";",
"return",
"this",
";",
"}"
] | change the font settings
@name set
@memberOf me.BitmapText.prototype
@function
@param {String} textAlign ("left", "center", "right")
@param {Number} [scale]
@return this object for chaining | [
"change",
"the",
"font",
"settings"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L15616-L15625 |
7,321 | melonjs/melonJS | dist/melonjs.js | draw | function draw(renderer, text, x, y) {
// allows to provide backward compatibility when
// adding Bitmap Font to an object container
if (typeof this.ancestor === "undefined") {
// update cache
this.setText(text); // force update bounds
this.update(0); // save the previous global alpha value
var _alpha = renderer.globalAlpha();
renderer.setGlobalAlpha(_alpha * this.getOpacity());
} else {
// added directly to an object container
x = this.pos.x;
y = this.pos.y;
}
var strings = ("" + this._text).split("\n");
var lX = x;
var stringHeight = measureTextHeight(this);
var maxWidth = 0;
for (var i = 0; i < strings.length; i++) {
x = lX;
var string = me.utils.string.trimRight(strings[i]); // adjust x pos based on alignment value
var stringWidth = measureTextWidth(this, string);
switch (this.textAlign) {
case "right":
x -= stringWidth;
break;
case "center":
x -= stringWidth * 0.5;
break;
default:
break;
} // adjust y pos based on alignment value
switch (this.textBaseline) {
case "middle":
y -= stringHeight * 0.5;
break;
case "ideographic":
case "alphabetic":
case "bottom":
y -= stringHeight;
break;
default:
break;
} // update initial position if required
if (this.isDirty === true && typeof this.ancestor === "undefined") {
if (i === 0) {
this.pos.y = y;
}
if (maxWidth < stringWidth) {
maxWidth = stringWidth;
this.pos.x = x;
}
} // draw the string
var lastGlyph = null;
for (var c = 0, len = string.length; c < len; c++) {
// calculate the char index
var ch = string.charCodeAt(c);
var glyph = this.fontData.glyphs[ch];
var glyphWidth = glyph.width;
var glyphHeight = glyph.height;
var kerning = lastGlyph && lastGlyph.kerning ? lastGlyph.getKerning(ch) : 0; // draw it
if (glyphWidth !== 0 && glyphHeight !== 0) {
// some browser throw an exception when drawing a 0 width or height image
renderer.drawImage(this.fontImage, glyph.x, glyph.y, glyphWidth, glyphHeight, x + glyph.xoffset, y + glyph.yoffset * this.fontScale.y, glyphWidth * this.fontScale.x, glyphHeight * this.fontScale.y);
} // increment position
x += (glyph.xadvance + kerning) * this.fontScale.x;
lastGlyph = glyph;
} // increment line
y += stringHeight;
}
if (typeof this.ancestor === "undefined") {
// restore the previous global alpha value
renderer.setGlobalAlpha(_alpha);
} // clear the dirty flag
this.isDirty = false;
} | javascript | function draw(renderer, text, x, y) {
// allows to provide backward compatibility when
// adding Bitmap Font to an object container
if (typeof this.ancestor === "undefined") {
// update cache
this.setText(text); // force update bounds
this.update(0); // save the previous global alpha value
var _alpha = renderer.globalAlpha();
renderer.setGlobalAlpha(_alpha * this.getOpacity());
} else {
// added directly to an object container
x = this.pos.x;
y = this.pos.y;
}
var strings = ("" + this._text).split("\n");
var lX = x;
var stringHeight = measureTextHeight(this);
var maxWidth = 0;
for (var i = 0; i < strings.length; i++) {
x = lX;
var string = me.utils.string.trimRight(strings[i]); // adjust x pos based on alignment value
var stringWidth = measureTextWidth(this, string);
switch (this.textAlign) {
case "right":
x -= stringWidth;
break;
case "center":
x -= stringWidth * 0.5;
break;
default:
break;
} // adjust y pos based on alignment value
switch (this.textBaseline) {
case "middle":
y -= stringHeight * 0.5;
break;
case "ideographic":
case "alphabetic":
case "bottom":
y -= stringHeight;
break;
default:
break;
} // update initial position if required
if (this.isDirty === true && typeof this.ancestor === "undefined") {
if (i === 0) {
this.pos.y = y;
}
if (maxWidth < stringWidth) {
maxWidth = stringWidth;
this.pos.x = x;
}
} // draw the string
var lastGlyph = null;
for (var c = 0, len = string.length; c < len; c++) {
// calculate the char index
var ch = string.charCodeAt(c);
var glyph = this.fontData.glyphs[ch];
var glyphWidth = glyph.width;
var glyphHeight = glyph.height;
var kerning = lastGlyph && lastGlyph.kerning ? lastGlyph.getKerning(ch) : 0; // draw it
if (glyphWidth !== 0 && glyphHeight !== 0) {
// some browser throw an exception when drawing a 0 width or height image
renderer.drawImage(this.fontImage, glyph.x, glyph.y, glyphWidth, glyphHeight, x + glyph.xoffset, y + glyph.yoffset * this.fontScale.y, glyphWidth * this.fontScale.x, glyphHeight * this.fontScale.y);
} // increment position
x += (glyph.xadvance + kerning) * this.fontScale.x;
lastGlyph = glyph;
} // increment line
y += stringHeight;
}
if (typeof this.ancestor === "undefined") {
// restore the previous global alpha value
renderer.setGlobalAlpha(_alpha);
} // clear the dirty flag
this.isDirty = false;
} | [
"function",
"draw",
"(",
"renderer",
",",
"text",
",",
"x",
",",
"y",
")",
"{",
"// allows to provide backward compatibility when",
"// adding Bitmap Font to an object container",
"if",
"(",
"typeof",
"this",
".",
"ancestor",
"===",
"\"undefined\"",
")",
"{",
"// update cache",
"this",
".",
"setText",
"(",
"text",
")",
";",
"// force update bounds",
"this",
".",
"update",
"(",
"0",
")",
";",
"// save the previous global alpha value",
"var",
"_alpha",
"=",
"renderer",
".",
"globalAlpha",
"(",
")",
";",
"renderer",
".",
"setGlobalAlpha",
"(",
"_alpha",
"*",
"this",
".",
"getOpacity",
"(",
")",
")",
";",
"}",
"else",
"{",
"// added directly to an object container",
"x",
"=",
"this",
".",
"pos",
".",
"x",
";",
"y",
"=",
"this",
".",
"pos",
".",
"y",
";",
"}",
"var",
"strings",
"=",
"(",
"\"\"",
"+",
"this",
".",
"_text",
")",
".",
"split",
"(",
"\"\\n\"",
")",
";",
"var",
"lX",
"=",
"x",
";",
"var",
"stringHeight",
"=",
"measureTextHeight",
"(",
"this",
")",
";",
"var",
"maxWidth",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"strings",
".",
"length",
";",
"i",
"++",
")",
"{",
"x",
"=",
"lX",
";",
"var",
"string",
"=",
"me",
".",
"utils",
".",
"string",
".",
"trimRight",
"(",
"strings",
"[",
"i",
"]",
")",
";",
"// adjust x pos based on alignment value",
"var",
"stringWidth",
"=",
"measureTextWidth",
"(",
"this",
",",
"string",
")",
";",
"switch",
"(",
"this",
".",
"textAlign",
")",
"{",
"case",
"\"right\"",
":",
"x",
"-=",
"stringWidth",
";",
"break",
";",
"case",
"\"center\"",
":",
"x",
"-=",
"stringWidth",
"*",
"0.5",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"// adjust y pos based on alignment value",
"switch",
"(",
"this",
".",
"textBaseline",
")",
"{",
"case",
"\"middle\"",
":",
"y",
"-=",
"stringHeight",
"*",
"0.5",
";",
"break",
";",
"case",
"\"ideographic\"",
":",
"case",
"\"alphabetic\"",
":",
"case",
"\"bottom\"",
":",
"y",
"-=",
"stringHeight",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"// update initial position if required",
"if",
"(",
"this",
".",
"isDirty",
"===",
"true",
"&&",
"typeof",
"this",
".",
"ancestor",
"===",
"\"undefined\"",
")",
"{",
"if",
"(",
"i",
"===",
"0",
")",
"{",
"this",
".",
"pos",
".",
"y",
"=",
"y",
";",
"}",
"if",
"(",
"maxWidth",
"<",
"stringWidth",
")",
"{",
"maxWidth",
"=",
"stringWidth",
";",
"this",
".",
"pos",
".",
"x",
"=",
"x",
";",
"}",
"}",
"// draw the string",
"var",
"lastGlyph",
"=",
"null",
";",
"for",
"(",
"var",
"c",
"=",
"0",
",",
"len",
"=",
"string",
".",
"length",
";",
"c",
"<",
"len",
";",
"c",
"++",
")",
"{",
"// calculate the char index",
"var",
"ch",
"=",
"string",
".",
"charCodeAt",
"(",
"c",
")",
";",
"var",
"glyph",
"=",
"this",
".",
"fontData",
".",
"glyphs",
"[",
"ch",
"]",
";",
"var",
"glyphWidth",
"=",
"glyph",
".",
"width",
";",
"var",
"glyphHeight",
"=",
"glyph",
".",
"height",
";",
"var",
"kerning",
"=",
"lastGlyph",
"&&",
"lastGlyph",
".",
"kerning",
"?",
"lastGlyph",
".",
"getKerning",
"(",
"ch",
")",
":",
"0",
";",
"// draw it",
"if",
"(",
"glyphWidth",
"!==",
"0",
"&&",
"glyphHeight",
"!==",
"0",
")",
"{",
"// some browser throw an exception when drawing a 0 width or height image",
"renderer",
".",
"drawImage",
"(",
"this",
".",
"fontImage",
",",
"glyph",
".",
"x",
",",
"glyph",
".",
"y",
",",
"glyphWidth",
",",
"glyphHeight",
",",
"x",
"+",
"glyph",
".",
"xoffset",
",",
"y",
"+",
"glyph",
".",
"yoffset",
"*",
"this",
".",
"fontScale",
".",
"y",
",",
"glyphWidth",
"*",
"this",
".",
"fontScale",
".",
"x",
",",
"glyphHeight",
"*",
"this",
".",
"fontScale",
".",
"y",
")",
";",
"}",
"// increment position",
"x",
"+=",
"(",
"glyph",
".",
"xadvance",
"+",
"kerning",
")",
"*",
"this",
".",
"fontScale",
".",
"x",
";",
"lastGlyph",
"=",
"glyph",
";",
"}",
"// increment line",
"y",
"+=",
"stringHeight",
";",
"}",
"if",
"(",
"typeof",
"this",
".",
"ancestor",
"===",
"\"undefined\"",
")",
"{",
"// restore the previous global alpha value",
"renderer",
".",
"setGlobalAlpha",
"(",
"_alpha",
")",
";",
"}",
"// clear the dirty flag",
"this",
".",
"isDirty",
"=",
"false",
";",
"}"
] | draw the bitmap font
@name draw
@memberOf me.BitmapText.prototype
@function
@param {me.CanvasRenderer|me.WebGLRenderer} renderer Reference to the destination renderer instance
@param {String} [text]
@param {Number} [x]
@param {Number} [y] | [
"draw",
"the",
"bitmap",
"font"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L15713-L15816 |
7,322 | melonjs/melonJS | dist/melonjs.js | _getFirstGlyph | function _getFirstGlyph() {
var keys = Object.keys(this.glyphs);
for (var i = 0; i < keys.length; i++) {
if (keys[i] > 32) {
return this.glyphs[keys[i]];
}
}
return null;
} | javascript | function _getFirstGlyph() {
var keys = Object.keys(this.glyphs);
for (var i = 0; i < keys.length; i++) {
if (keys[i] > 32) {
return this.glyphs[keys[i]];
}
}
return null;
} | [
"function",
"_getFirstGlyph",
"(",
")",
"{",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"this",
".",
"glyphs",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"keys",
"[",
"i",
"]",
">",
"32",
")",
"{",
"return",
"this",
".",
"glyphs",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Gets the first glyph in the map that is not a space character
@private
@name _getFirstGlyph
@memberOf me.BitmapTextData
@function
@returns {me.Glyph} | [
"Gets",
"the",
"first",
"glyph",
"in",
"the",
"map",
"that",
"is",
"not",
"a",
"space",
"character"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L15958-L15968 |
7,323 | melonjs/melonJS | dist/melonjs.js | function(id, internal) {
var self = this;
// If the sound hasn't loaded, add it to the load queue to stop when capable.
if (self._state !== 'loaded' || self._playLock) {
self._queue.push({
event: 'stop',
action: function() {
self.stop(id);
}
});
return self;
}
// If no id is passed, get all ID's to be stopped.
var ids = self._getSoundIds(id);
for (var i=0; i<ids.length; i++) {
// Clear the end timer.
self._clearTimer(ids[i]);
// Get the sound.
var sound = self._soundById(ids[i]);
if (sound) {
// Reset the seek position.
sound._seek = sound._start || 0;
sound._rateSeek = 0;
sound._paused = true;
sound._ended = true;
// Stop currently running fades.
self._stopFade(ids[i]);
if (sound._node) {
if (self._webAudio) {
// Make sure the sound's AudioBufferSourceNode has been created.
if (sound._node.bufferSource) {
if (typeof sound._node.bufferSource.stop === 'undefined') {
sound._node.bufferSource.noteOff(0);
} else {
sound._node.bufferSource.stop(0);
}
// Clean up the buffer source.
self._cleanBuffer(sound._node);
}
} else if (!isNaN(sound._node.duration) || sound._node.duration === Infinity) {
sound._node.currentTime = sound._start || 0;
sound._node.pause();
}
}
if (!internal) {
self._emit('stop', sound._id);
}
}
}
return self;
} | javascript | function(id, internal) {
var self = this;
// If the sound hasn't loaded, add it to the load queue to stop when capable.
if (self._state !== 'loaded' || self._playLock) {
self._queue.push({
event: 'stop',
action: function() {
self.stop(id);
}
});
return self;
}
// If no id is passed, get all ID's to be stopped.
var ids = self._getSoundIds(id);
for (var i=0; i<ids.length; i++) {
// Clear the end timer.
self._clearTimer(ids[i]);
// Get the sound.
var sound = self._soundById(ids[i]);
if (sound) {
// Reset the seek position.
sound._seek = sound._start || 0;
sound._rateSeek = 0;
sound._paused = true;
sound._ended = true;
// Stop currently running fades.
self._stopFade(ids[i]);
if (sound._node) {
if (self._webAudio) {
// Make sure the sound's AudioBufferSourceNode has been created.
if (sound._node.bufferSource) {
if (typeof sound._node.bufferSource.stop === 'undefined') {
sound._node.bufferSource.noteOff(0);
} else {
sound._node.bufferSource.stop(0);
}
// Clean up the buffer source.
self._cleanBuffer(sound._node);
}
} else if (!isNaN(sound._node.duration) || sound._node.duration === Infinity) {
sound._node.currentTime = sound._start || 0;
sound._node.pause();
}
}
if (!internal) {
self._emit('stop', sound._id);
}
}
}
return self;
} | [
"function",
"(",
"id",
",",
"internal",
")",
"{",
"var",
"self",
"=",
"this",
";",
"// If the sound hasn't loaded, add it to the load queue to stop when capable.",
"if",
"(",
"self",
".",
"_state",
"!==",
"'loaded'",
"||",
"self",
".",
"_playLock",
")",
"{",
"self",
".",
"_queue",
".",
"push",
"(",
"{",
"event",
":",
"'stop'",
",",
"action",
":",
"function",
"(",
")",
"{",
"self",
".",
"stop",
"(",
"id",
")",
";",
"}",
"}",
")",
";",
"return",
"self",
";",
"}",
"// If no id is passed, get all ID's to be stopped.",
"var",
"ids",
"=",
"self",
".",
"_getSoundIds",
"(",
"id",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"ids",
".",
"length",
";",
"i",
"++",
")",
"{",
"// Clear the end timer.",
"self",
".",
"_clearTimer",
"(",
"ids",
"[",
"i",
"]",
")",
";",
"// Get the sound.",
"var",
"sound",
"=",
"self",
".",
"_soundById",
"(",
"ids",
"[",
"i",
"]",
")",
";",
"if",
"(",
"sound",
")",
"{",
"// Reset the seek position.",
"sound",
".",
"_seek",
"=",
"sound",
".",
"_start",
"||",
"0",
";",
"sound",
".",
"_rateSeek",
"=",
"0",
";",
"sound",
".",
"_paused",
"=",
"true",
";",
"sound",
".",
"_ended",
"=",
"true",
";",
"// Stop currently running fades.",
"self",
".",
"_stopFade",
"(",
"ids",
"[",
"i",
"]",
")",
";",
"if",
"(",
"sound",
".",
"_node",
")",
"{",
"if",
"(",
"self",
".",
"_webAudio",
")",
"{",
"// Make sure the sound's AudioBufferSourceNode has been created.",
"if",
"(",
"sound",
".",
"_node",
".",
"bufferSource",
")",
"{",
"if",
"(",
"typeof",
"sound",
".",
"_node",
".",
"bufferSource",
".",
"stop",
"===",
"'undefined'",
")",
"{",
"sound",
".",
"_node",
".",
"bufferSource",
".",
"noteOff",
"(",
"0",
")",
";",
"}",
"else",
"{",
"sound",
".",
"_node",
".",
"bufferSource",
".",
"stop",
"(",
"0",
")",
";",
"}",
"// Clean up the buffer source.",
"self",
".",
"_cleanBuffer",
"(",
"sound",
".",
"_node",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"isNaN",
"(",
"sound",
".",
"_node",
".",
"duration",
")",
"||",
"sound",
".",
"_node",
".",
"duration",
"===",
"Infinity",
")",
"{",
"sound",
".",
"_node",
".",
"currentTime",
"=",
"sound",
".",
"_start",
"||",
"0",
";",
"sound",
".",
"_node",
".",
"pause",
"(",
")",
";",
"}",
"}",
"if",
"(",
"!",
"internal",
")",
"{",
"self",
".",
"_emit",
"(",
"'stop'",
",",
"sound",
".",
"_id",
")",
";",
"}",
"}",
"}",
"return",
"self",
";",
"}"
] | Stop playback and reset to start.
@param {Number} id The sound ID (empty to stop all in group).
@param {Boolean} internal Internal Use: true prevents event firing.
@return {Howl} | [
"Stop",
"playback",
"and",
"reset",
"to",
"start",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L17140-L17201 |
|
7,324 | melonjs/melonJS | dist/melonjs.js | function() {
var self = this;
// Stop playing any active sounds.
var sounds = self._sounds;
for (var i=0; i<sounds.length; i++) {
// Stop the sound if it is currently playing.
if (!sounds[i]._paused) {
self.stop(sounds[i]._id);
}
// Remove the source or disconnect.
if (!self._webAudio) {
// Set the source to 0-second silence to stop any downloading (except in IE).
var checkIE = /MSIE |Trident\//.test(Howler._navigator && Howler._navigator.userAgent);
if (!checkIE) {
sounds[i]._node.src = 'data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA';
}
// Remove any event listeners.
sounds[i]._node.removeEventListener('error', sounds[i]._errorFn, false);
sounds[i]._node.removeEventListener(Howler._canPlayEvent, sounds[i]._loadFn, false);
// Release the Audio object back to the pool.
Howler._releaseHtml5Audio(sounds[i]._node);
}
// Empty out all of the nodes.
delete sounds[i]._node;
// Make sure all timers are cleared out.
self._clearTimer(sounds[i]._id);
}
// Remove the references in the global Howler object.
var index = Howler._howls.indexOf(self);
if (index >= 0) {
Howler._howls.splice(index, 1);
}
// Delete this sound from the cache (if no other Howl is using it).
var remCache = true;
for (i=0; i<Howler._howls.length; i++) {
if (Howler._howls[i]._src === self._src || self._src.indexOf(Howler._howls[i]._src) >= 0) {
remCache = false;
break;
}
}
if (cache && remCache) {
delete cache[self._src];
}
// Clear global errors.
Howler.noAudio = false;
// Clear out `self`.
self._state = 'unloaded';
self._sounds = [];
self = null;
return null;
} | javascript | function() {
var self = this;
// Stop playing any active sounds.
var sounds = self._sounds;
for (var i=0; i<sounds.length; i++) {
// Stop the sound if it is currently playing.
if (!sounds[i]._paused) {
self.stop(sounds[i]._id);
}
// Remove the source or disconnect.
if (!self._webAudio) {
// Set the source to 0-second silence to stop any downloading (except in IE).
var checkIE = /MSIE |Trident\//.test(Howler._navigator && Howler._navigator.userAgent);
if (!checkIE) {
sounds[i]._node.src = 'data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA';
}
// Remove any event listeners.
sounds[i]._node.removeEventListener('error', sounds[i]._errorFn, false);
sounds[i]._node.removeEventListener(Howler._canPlayEvent, sounds[i]._loadFn, false);
// Release the Audio object back to the pool.
Howler._releaseHtml5Audio(sounds[i]._node);
}
// Empty out all of the nodes.
delete sounds[i]._node;
// Make sure all timers are cleared out.
self._clearTimer(sounds[i]._id);
}
// Remove the references in the global Howler object.
var index = Howler._howls.indexOf(self);
if (index >= 0) {
Howler._howls.splice(index, 1);
}
// Delete this sound from the cache (if no other Howl is using it).
var remCache = true;
for (i=0; i<Howler._howls.length; i++) {
if (Howler._howls[i]._src === self._src || self._src.indexOf(Howler._howls[i]._src) >= 0) {
remCache = false;
break;
}
}
if (cache && remCache) {
delete cache[self._src];
}
// Clear global errors.
Howler.noAudio = false;
// Clear out `self`.
self._state = 'unloaded';
self._sounds = [];
self = null;
return null;
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"// Stop playing any active sounds.",
"var",
"sounds",
"=",
"self",
".",
"_sounds",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"sounds",
".",
"length",
";",
"i",
"++",
")",
"{",
"// Stop the sound if it is currently playing.",
"if",
"(",
"!",
"sounds",
"[",
"i",
"]",
".",
"_paused",
")",
"{",
"self",
".",
"stop",
"(",
"sounds",
"[",
"i",
"]",
".",
"_id",
")",
";",
"}",
"// Remove the source or disconnect.",
"if",
"(",
"!",
"self",
".",
"_webAudio",
")",
"{",
"// Set the source to 0-second silence to stop any downloading (except in IE).",
"var",
"checkIE",
"=",
"/",
"MSIE |Trident\\/",
"/",
".",
"test",
"(",
"Howler",
".",
"_navigator",
"&&",
"Howler",
".",
"_navigator",
".",
"userAgent",
")",
";",
"if",
"(",
"!",
"checkIE",
")",
"{",
"sounds",
"[",
"i",
"]",
".",
"_node",
".",
"src",
"=",
"'data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA'",
";",
"}",
"// Remove any event listeners.",
"sounds",
"[",
"i",
"]",
".",
"_node",
".",
"removeEventListener",
"(",
"'error'",
",",
"sounds",
"[",
"i",
"]",
".",
"_errorFn",
",",
"false",
")",
";",
"sounds",
"[",
"i",
"]",
".",
"_node",
".",
"removeEventListener",
"(",
"Howler",
".",
"_canPlayEvent",
",",
"sounds",
"[",
"i",
"]",
".",
"_loadFn",
",",
"false",
")",
";",
"// Release the Audio object back to the pool.",
"Howler",
".",
"_releaseHtml5Audio",
"(",
"sounds",
"[",
"i",
"]",
".",
"_node",
")",
";",
"}",
"// Empty out all of the nodes.",
"delete",
"sounds",
"[",
"i",
"]",
".",
"_node",
";",
"// Make sure all timers are cleared out.",
"self",
".",
"_clearTimer",
"(",
"sounds",
"[",
"i",
"]",
".",
"_id",
")",
";",
"}",
"// Remove the references in the global Howler object.",
"var",
"index",
"=",
"Howler",
".",
"_howls",
".",
"indexOf",
"(",
"self",
")",
";",
"if",
"(",
"index",
">=",
"0",
")",
"{",
"Howler",
".",
"_howls",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"}",
"// Delete this sound from the cache (if no other Howl is using it).",
"var",
"remCache",
"=",
"true",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"Howler",
".",
"_howls",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"Howler",
".",
"_howls",
"[",
"i",
"]",
".",
"_src",
"===",
"self",
".",
"_src",
"||",
"self",
".",
"_src",
".",
"indexOf",
"(",
"Howler",
".",
"_howls",
"[",
"i",
"]",
".",
"_src",
")",
">=",
"0",
")",
"{",
"remCache",
"=",
"false",
";",
"break",
";",
"}",
"}",
"if",
"(",
"cache",
"&&",
"remCache",
")",
"{",
"delete",
"cache",
"[",
"self",
".",
"_src",
"]",
";",
"}",
"// Clear global errors.",
"Howler",
".",
"noAudio",
"=",
"false",
";",
"// Clear out `self`.",
"self",
".",
"_state",
"=",
"'unloaded'",
";",
"self",
".",
"_sounds",
"=",
"[",
"]",
";",
"self",
"=",
"null",
";",
"return",
"null",
";",
"}"
] | Unload and destroy the current Howl object.
This will immediately stop all sound instances attached to this group. | [
"Unload",
"and",
"destroy",
"the",
"current",
"Howl",
"object",
".",
"This",
"will",
"immediately",
"stop",
"all",
"sound",
"instances",
"attached",
"to",
"this",
"group",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L17792-L17854 |
|
7,325 | melonjs/melonJS | dist/melonjs.js | soundLoadError | function soundLoadError(sound_name, onerror_cb) {
// check the retry counter
if (retry_counter++ > 3) {
// something went wrong
var errmsg = "melonJS: failed loading " + sound_name;
if (me.sys.stopOnAudioError === false) {
// disable audio
me.audio.disable(); // call error callback if defined
if (onerror_cb) {
onerror_cb();
} // warning
console.log(errmsg + ", disabling audio");
} else {
// throw an exception and stop everything !
throw new Error(errmsg);
} // else try loading again !
} else {
audioTracks[sound_name].load();
}
} | javascript | function soundLoadError(sound_name, onerror_cb) {
// check the retry counter
if (retry_counter++ > 3) {
// something went wrong
var errmsg = "melonJS: failed loading " + sound_name;
if (me.sys.stopOnAudioError === false) {
// disable audio
me.audio.disable(); // call error callback if defined
if (onerror_cb) {
onerror_cb();
} // warning
console.log(errmsg + ", disabling audio");
} else {
// throw an exception and stop everything !
throw new Error(errmsg);
} // else try loading again !
} else {
audioTracks[sound_name].load();
}
} | [
"function",
"soundLoadError",
"(",
"sound_name",
",",
"onerror_cb",
")",
"{",
"// check the retry counter",
"if",
"(",
"retry_counter",
"++",
">",
"3",
")",
"{",
"// something went wrong",
"var",
"errmsg",
"=",
"\"melonJS: failed loading \"",
"+",
"sound_name",
";",
"if",
"(",
"me",
".",
"sys",
".",
"stopOnAudioError",
"===",
"false",
")",
"{",
"// disable audio",
"me",
".",
"audio",
".",
"disable",
"(",
")",
";",
"// call error callback if defined",
"if",
"(",
"onerror_cb",
")",
"{",
"onerror_cb",
"(",
")",
";",
"}",
"// warning",
"console",
".",
"log",
"(",
"errmsg",
"+",
"\", disabling audio\"",
")",
";",
"}",
"else",
"{",
"// throw an exception and stop everything !",
"throw",
"new",
"Error",
"(",
"errmsg",
")",
";",
"}",
"// else try loading again !",
"}",
"else",
"{",
"audioTracks",
"[",
"sound_name",
"]",
".",
"load",
"(",
")",
";",
"}",
"}"
] | event listener callback on load error
@ignore | [
"event",
"listener",
"callback",
"on",
"load",
"error"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L19257-L19281 |
7,326 | melonjs/melonJS | dist/melonjs.js | autoDetectRenderer | function autoDetectRenderer(c, width, height, options) {
try {
return new me.WebGLRenderer(c, width, height, options);
} catch (e) {
return new me.CanvasRenderer(c, width, height, options);
}
} | javascript | function autoDetectRenderer(c, width, height, options) {
try {
return new me.WebGLRenderer(c, width, height, options);
} catch (e) {
return new me.CanvasRenderer(c, width, height, options);
}
} | [
"function",
"autoDetectRenderer",
"(",
"c",
",",
"width",
",",
"height",
",",
"options",
")",
"{",
"try",
"{",
"return",
"new",
"me",
".",
"WebGLRenderer",
"(",
"c",
",",
"width",
",",
"height",
",",
"options",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"new",
"me",
".",
"CanvasRenderer",
"(",
"c",
",",
"width",
",",
"height",
",",
"options",
")",
";",
"}",
"}"
] | Auto-detect the best renderer to use
@ignore | [
"Auto",
"-",
"detect",
"the",
"best",
"renderer",
"to",
"use"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L19896-L19902 |
7,327 | melonjs/melonJS | dist/melonjs.js | overlaps | function overlaps(rect) {
return rect.left < this.getWidth() && rect.right > 0 && rect.top < this.getHeight() && rect.bottom > 0;
} | javascript | function overlaps(rect) {
return rect.left < this.getWidth() && rect.right > 0 && rect.top < this.getHeight() && rect.bottom > 0;
} | [
"function",
"overlaps",
"(",
"rect",
")",
"{",
"return",
"rect",
".",
"left",
"<",
"this",
".",
"getWidth",
"(",
")",
"&&",
"rect",
".",
"right",
">",
"0",
"&&",
"rect",
".",
"top",
"<",
"this",
".",
"getHeight",
"(",
")",
"&&",
"rect",
".",
"bottom",
">",
"0",
";",
"}"
] | check if the given rectangle overlaps with the renderer screen coordinates
@name overlaps
@memberOf me.Renderer.prototype
@function
@param {me.Rect} rect
@return {boolean} true if overlaps | [
"check",
"if",
"the",
"given",
"rectangle",
"overlaps",
"with",
"the",
"renderer",
"screen",
"coordinates"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L20572-L20574 |
7,328 | melonjs/melonJS | dist/melonjs.js | stroke | function stroke(shape, fill) {
if (shape.shapeType === "Rectangle") {
this.strokeRect(shape.left, shape.top, shape.width, shape.height, fill);
} else if (shape instanceof me.Line || shape instanceof me.Polygon) {
this.strokePolygon(shape, fill);
} else if (shape instanceof me.Ellipse) {
this.strokeEllipse(shape.pos.x, shape.pos.y, shape.radiusV.x, shape.radiusV.y, fill);
}
} | javascript | function stroke(shape, fill) {
if (shape.shapeType === "Rectangle") {
this.strokeRect(shape.left, shape.top, shape.width, shape.height, fill);
} else if (shape instanceof me.Line || shape instanceof me.Polygon) {
this.strokePolygon(shape, fill);
} else if (shape instanceof me.Ellipse) {
this.strokeEllipse(shape.pos.x, shape.pos.y, shape.radiusV.x, shape.radiusV.y, fill);
}
} | [
"function",
"stroke",
"(",
"shape",
",",
"fill",
")",
"{",
"if",
"(",
"shape",
".",
"shapeType",
"===",
"\"Rectangle\"",
")",
"{",
"this",
".",
"strokeRect",
"(",
"shape",
".",
"left",
",",
"shape",
".",
"top",
",",
"shape",
".",
"width",
",",
"shape",
".",
"height",
",",
"fill",
")",
";",
"}",
"else",
"if",
"(",
"shape",
"instanceof",
"me",
".",
"Line",
"||",
"shape",
"instanceof",
"me",
".",
"Polygon",
")",
"{",
"this",
".",
"strokePolygon",
"(",
"shape",
",",
"fill",
")",
";",
"}",
"else",
"if",
"(",
"shape",
"instanceof",
"me",
".",
"Ellipse",
")",
"{",
"this",
".",
"strokeEllipse",
"(",
"shape",
".",
"pos",
".",
"x",
",",
"shape",
".",
"pos",
".",
"y",
",",
"shape",
".",
"radiusV",
".",
"x",
",",
"shape",
".",
"radiusV",
".",
"y",
",",
"fill",
")",
";",
"}",
"}"
] | stroke the given shape
@name stroke
@memberOf me.Renderer.prototype
@function
@param {me.Rect|me.Polygon|me.Line|me.Ellipse} shape a shape object to stroke | [
"stroke",
"the",
"given",
"shape"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L20632-L20640 |
7,329 | melonjs/melonJS | dist/melonjs.js | createAtlas | function createAtlas(width, height, name, repeat) {
return {
"meta": {
"app": "melonJS",
"size": {
"w": width,
"h": height
},
"repeat": repeat || "no-repeat",
"image": "default"
},
"frames": [{
"filename": name || "default",
"frame": {
"x": 0,
"y": 0,
"w": width,
"h": height
}
}]
};
} | javascript | function createAtlas(width, height, name, repeat) {
return {
"meta": {
"app": "melonJS",
"size": {
"w": width,
"h": height
},
"repeat": repeat || "no-repeat",
"image": "default"
},
"frames": [{
"filename": name || "default",
"frame": {
"x": 0,
"y": 0,
"w": width,
"h": height
}
}]
};
} | [
"function",
"createAtlas",
"(",
"width",
",",
"height",
",",
"name",
",",
"repeat",
")",
"{",
"return",
"{",
"\"meta\"",
":",
"{",
"\"app\"",
":",
"\"melonJS\"",
",",
"\"size\"",
":",
"{",
"\"w\"",
":",
"width",
",",
"\"h\"",
":",
"height",
"}",
",",
"\"repeat\"",
":",
"repeat",
"||",
"\"no-repeat\"",
",",
"\"image\"",
":",
"\"default\"",
"}",
",",
"\"frames\"",
":",
"[",
"{",
"\"filename\"",
":",
"name",
"||",
"\"default\"",
",",
"\"frame\"",
":",
"{",
"\"x\"",
":",
"0",
",",
"\"y\"",
":",
"0",
",",
"\"w\"",
":",
"width",
",",
"\"h\"",
":",
"height",
"}",
"}",
"]",
"}",
";",
"}"
] | create a simple 1 frame texture atlas based on the given parameters
@ignore | [
"create",
"a",
"simple",
"1",
"frame",
"texture",
"atlas",
"based",
"on",
"the",
"given",
"parameters"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L20876-L20897 |
7,330 | melonjs/melonJS | dist/melonjs.js | getAtlas | function getAtlas(key) {
if (typeof key === "string") {
return this.atlases.get(key);
} else {
return this.atlases.values().next().value;
}
} | javascript | function getAtlas(key) {
if (typeof key === "string") {
return this.atlases.get(key);
} else {
return this.atlases.values().next().value;
}
} | [
"function",
"getAtlas",
"(",
"key",
")",
"{",
"if",
"(",
"typeof",
"key",
"===",
"\"string\"",
")",
"{",
"return",
"this",
".",
"atlases",
".",
"get",
"(",
"key",
")",
";",
"}",
"else",
"{",
"return",
"this",
".",
"atlases",
".",
"values",
"(",
")",
".",
"next",
"(",
")",
".",
"value",
";",
"}",
"}"
] | return the default or specified atlas dictionnary
@name getAtlas
@memberOf me.Renderer.Texture
@function
@param {String} [name] atlas name in case of multipack textures
@return {Object} | [
"return",
"the",
"default",
"or",
"specified",
"atlas",
"dictionnary"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L21037-L21043 |
7,331 | melonjs/melonJS | dist/melonjs.js | fillArc | function fillArc(x, y, radius, start, end, antiClockwise) {
this.strokeArc(x, y, radius, start, end, antiClockwise || false, true);
} | javascript | function fillArc(x, y, radius, start, end, antiClockwise) {
this.strokeArc(x, y, radius, start, end, antiClockwise || false, true);
} | [
"function",
"fillArc",
"(",
"x",
",",
"y",
",",
"radius",
",",
"start",
",",
"end",
",",
"antiClockwise",
")",
"{",
"this",
".",
"strokeArc",
"(",
"x",
",",
"y",
",",
"radius",
",",
"start",
",",
"end",
",",
"antiClockwise",
"||",
"false",
",",
"true",
")",
";",
"}"
] | Fill an arc at the specified coordinates with given radius, start and end points
@name fillArc
@memberOf me.CanvasRenderer.prototype
@function
@param {Number} x arc center point x-axis
@param {Number} y arc center point y-axis
@param {Number} radius
@param {Number} start start angle in radians
@param {Number} end end angle in radians
@param {Boolean} [antiClockwise=false] draw arc anti-clockwise | [
"Fill",
"an",
"arc",
"at",
"the",
"specified",
"coordinates",
"with",
"given",
"radius",
"start",
"and",
"end",
"points"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L21584-L21586 |
7,332 | melonjs/melonJS | dist/melonjs.js | fillLine | function fillLine(startX, startY, endX, endY) {
this.strokeLine(startX, startY, endX, endY);
} | javascript | function fillLine(startX, startY, endX, endY) {
this.strokeLine(startX, startY, endX, endY);
} | [
"function",
"fillLine",
"(",
"startX",
",",
"startY",
",",
"endX",
",",
"endY",
")",
"{",
"this",
".",
"strokeLine",
"(",
"startX",
",",
"startY",
",",
"endX",
",",
"endY",
")",
";",
"}"
] | Fill a line of the given two points
@name fillLine
@memberOf me.CanvasRenderer.prototype
@function
@param {Number} startX the start x coordinate
@param {Number} startY the start y coordinate
@param {Number} endX the end x coordinate
@param {Number} endY the end y coordinate | [
"Fill",
"a",
"line",
"of",
"the",
"given",
"two",
"points"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L21675-L21677 |
7,333 | melonjs/melonJS | dist/melonjs.js | strokeRect | function strokeRect(x, y, width, height) {
if (this.backBufferContext2D.globalAlpha < 1 / 255) {
// Fast path: don't draw fully transparent
return;
}
this.backBufferContext2D.strokeRect(x, y, width, height);
} | javascript | function strokeRect(x, y, width, height) {
if (this.backBufferContext2D.globalAlpha < 1 / 255) {
// Fast path: don't draw fully transparent
return;
}
this.backBufferContext2D.strokeRect(x, y, width, height);
} | [
"function",
"strokeRect",
"(",
"x",
",",
"y",
",",
"width",
",",
"height",
")",
"{",
"if",
"(",
"this",
".",
"backBufferContext2D",
".",
"globalAlpha",
"<",
"1",
"/",
"255",
")",
"{",
"// Fast path: don't draw fully transparent",
"return",
";",
"}",
"this",
".",
"backBufferContext2D",
".",
"strokeRect",
"(",
"x",
",",
"y",
",",
"width",
",",
"height",
")",
";",
"}"
] | Stroke a rectangle at the specified coordinates
@name strokeRect
@memberOf me.CanvasRenderer.prototype
@function
@param {Number} x
@param {Number} y
@param {Number} width
@param {Number} height | [
"Stroke",
"a",
"rectangle",
"at",
"the",
"specified",
"coordinates"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L21731-L21738 |
7,334 | melonjs/melonJS | dist/melonjs.js | createPattern | function createPattern(image, repeat) {
if (!me.Math.isPowerOfTwo(image.width) || !me.Math.isPowerOfTwo(image.height)) {
var src = typeof image.src !== "undefined" ? image.src : image;
throw new Error("[WebGL Renderer] " + src + " is not a POT texture " + "(" + image.width + "x" + image.height + ")");
}
var texture = new this.Texture(this.Texture.prototype.createAtlas.apply(this.Texture.prototype, [image.width, image.height, "pattern", repeat]), image); // FIXME: Remove old cache entry and texture when changing the repeat mode
this.compositor.uploadTexture(texture);
return texture;
} | javascript | function createPattern(image, repeat) {
if (!me.Math.isPowerOfTwo(image.width) || !me.Math.isPowerOfTwo(image.height)) {
var src = typeof image.src !== "undefined" ? image.src : image;
throw new Error("[WebGL Renderer] " + src + " is not a POT texture " + "(" + image.width + "x" + image.height + ")");
}
var texture = new this.Texture(this.Texture.prototype.createAtlas.apply(this.Texture.prototype, [image.width, image.height, "pattern", repeat]), image); // FIXME: Remove old cache entry and texture when changing the repeat mode
this.compositor.uploadTexture(texture);
return texture;
} | [
"function",
"createPattern",
"(",
"image",
",",
"repeat",
")",
"{",
"if",
"(",
"!",
"me",
".",
"Math",
".",
"isPowerOfTwo",
"(",
"image",
".",
"width",
")",
"||",
"!",
"me",
".",
"Math",
".",
"isPowerOfTwo",
"(",
"image",
".",
"height",
")",
")",
"{",
"var",
"src",
"=",
"typeof",
"image",
".",
"src",
"!==",
"\"undefined\"",
"?",
"image",
".",
"src",
":",
"image",
";",
"throw",
"new",
"Error",
"(",
"\"[WebGL Renderer] \"",
"+",
"src",
"+",
"\" is not a POT texture \"",
"+",
"\"(\"",
"+",
"image",
".",
"width",
"+",
"\"x\"",
"+",
"image",
".",
"height",
"+",
"\")\"",
")",
";",
"}",
"var",
"texture",
"=",
"new",
"this",
".",
"Texture",
"(",
"this",
".",
"Texture",
".",
"prototype",
".",
"createAtlas",
".",
"apply",
"(",
"this",
".",
"Texture",
".",
"prototype",
",",
"[",
"image",
".",
"width",
",",
"image",
".",
"height",
",",
"\"pattern\"",
",",
"repeat",
"]",
")",
",",
"image",
")",
";",
"// FIXME: Remove old cache entry and texture when changing the repeat mode",
"this",
".",
"compositor",
".",
"uploadTexture",
"(",
"texture",
")",
";",
"return",
"texture",
";",
"}"
] | Create a pattern with the specified repetition
@name createPattern
@memberOf me.WebGLRenderer.prototype
@function
@param {image} image Source image
@param {String} repeat Define how the pattern should be repeated
@return {me.video.renderer.Texture}
@see me.ImageLayer#repeat
@example
var tileable = renderer.createPattern(image, "repeat");
var horizontal = renderer.createPattern(image, "repeat-x");
var vertical = renderer.createPattern(image, "repeat-y");
var basic = renderer.createPattern(image, "no-repeat"); | [
"Create",
"a",
"pattern",
"with",
"the",
"specified",
"repetition"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L22201-L22211 |
7,335 | melonjs/melonJS | dist/melonjs.js | getContextGL | function getContextGL(canvas, transparent) {
if (typeof canvas === "undefined" || canvas === null) {
throw new Error("You must pass a canvas element in order to create " + "a GL context");
}
if (typeof transparent !== "boolean") {
transparent = true;
}
var attr = {
alpha: transparent,
antialias: this.settings.antiAlias,
depth: false,
stencil: true,
premultipliedAlpha: transparent,
failIfMajorPerformanceCaveat: this.settings.failIfMajorPerformanceCaveat
};
var gl = canvas.getContext("webgl", attr) || canvas.getContext("experimental-webgl", attr);
if (!gl) {
throw new Error("A WebGL context could not be created.");
}
return gl;
} | javascript | function getContextGL(canvas, transparent) {
if (typeof canvas === "undefined" || canvas === null) {
throw new Error("You must pass a canvas element in order to create " + "a GL context");
}
if (typeof transparent !== "boolean") {
transparent = true;
}
var attr = {
alpha: transparent,
antialias: this.settings.antiAlias,
depth: false,
stencil: true,
premultipliedAlpha: transparent,
failIfMajorPerformanceCaveat: this.settings.failIfMajorPerformanceCaveat
};
var gl = canvas.getContext("webgl", attr) || canvas.getContext("experimental-webgl", attr);
if (!gl) {
throw new Error("A WebGL context could not be created.");
}
return gl;
} | [
"function",
"getContextGL",
"(",
"canvas",
",",
"transparent",
")",
"{",
"if",
"(",
"typeof",
"canvas",
"===",
"\"undefined\"",
"||",
"canvas",
"===",
"null",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"You must pass a canvas element in order to create \"",
"+",
"\"a GL context\"",
")",
";",
"}",
"if",
"(",
"typeof",
"transparent",
"!==",
"\"boolean\"",
")",
"{",
"transparent",
"=",
"true",
";",
"}",
"var",
"attr",
"=",
"{",
"alpha",
":",
"transparent",
",",
"antialias",
":",
"this",
".",
"settings",
".",
"antiAlias",
",",
"depth",
":",
"false",
",",
"stencil",
":",
"true",
",",
"premultipliedAlpha",
":",
"transparent",
",",
"failIfMajorPerformanceCaveat",
":",
"this",
".",
"settings",
".",
"failIfMajorPerformanceCaveat",
"}",
";",
"var",
"gl",
"=",
"canvas",
".",
"getContext",
"(",
"\"webgl\"",
",",
"attr",
")",
"||",
"canvas",
".",
"getContext",
"(",
"\"experimental-webgl\"",
",",
"attr",
")",
";",
"if",
"(",
"!",
"gl",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"A WebGL context could not be created.\"",
")",
";",
"}",
"return",
"gl",
";",
"}"
] | Returns the WebGL Context object of the given Canvas
@name getContextGL
@memberOf me.WebGLRenderer.prototype
@function
@param {Canvas} canvas
@param {Boolean} [transparent=true] use false to disable transparency
@return {WebGLRenderingContext} | [
"Returns",
"the",
"WebGL",
"Context",
"object",
"of",
"the",
"given",
"Canvas"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L22367-L22391 |
7,336 | melonjs/melonJS | dist/melonjs.js | setBlendMode | function setBlendMode(mode, gl) {
gl = gl || this.gl;
gl.enable(gl.BLEND);
switch (mode) {
case "multiply":
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
this.currentBlendMode = mode;
break;
default:
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
this.currentBlendMode = "normal";
break;
}
} | javascript | function setBlendMode(mode, gl) {
gl = gl || this.gl;
gl.enable(gl.BLEND);
switch (mode) {
case "multiply":
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
this.currentBlendMode = mode;
break;
default:
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
this.currentBlendMode = "normal";
break;
}
} | [
"function",
"setBlendMode",
"(",
"mode",
",",
"gl",
")",
"{",
"gl",
"=",
"gl",
"||",
"this",
".",
"gl",
";",
"gl",
".",
"enable",
"(",
"gl",
".",
"BLEND",
")",
";",
"switch",
"(",
"mode",
")",
"{",
"case",
"\"multiply\"",
":",
"gl",
".",
"blendFunc",
"(",
"gl",
".",
"SRC_ALPHA",
",",
"gl",
".",
"ONE_MINUS_SRC_ALPHA",
")",
";",
"this",
".",
"currentBlendMode",
"=",
"mode",
";",
"break",
";",
"default",
":",
"gl",
".",
"blendFunc",
"(",
"gl",
".",
"ONE",
",",
"gl",
".",
"ONE_MINUS_SRC_ALPHA",
")",
";",
"this",
".",
"currentBlendMode",
"=",
"\"normal\"",
";",
"break",
";",
"}",
"}"
] | set a blend mode for the given context
@name setBlendMode
@memberOf me.WebGLRenderer.prototype
@function
@param {String} [mode="normal"] blend mode : "normal", "multiply"
@param {WebGLRenderingContext} [gl] | [
"set",
"a",
"blend",
"mode",
"for",
"the",
"given",
"context"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L22413-L22428 |
7,337 | melonjs/melonJS | dist/melonjs.js | scaleCanvas | function scaleCanvas(scaleX, scaleY) {
var w = this.canvas.width * scaleX;
var h = this.canvas.height * scaleY; // adjust CSS style for High-DPI devices
if (me.device.devicePixelRatio > 1) {
this.canvas.style.width = w / me.device.devicePixelRatio + "px";
this.canvas.style.height = h / me.device.devicePixelRatio + "px";
} else {
this.canvas.style.width = w + "px";
this.canvas.style.height = h + "px";
}
this.compositor.setProjection(this.canvas.width, this.canvas.height);
} | javascript | function scaleCanvas(scaleX, scaleY) {
var w = this.canvas.width * scaleX;
var h = this.canvas.height * scaleY; // adjust CSS style for High-DPI devices
if (me.device.devicePixelRatio > 1) {
this.canvas.style.width = w / me.device.devicePixelRatio + "px";
this.canvas.style.height = h / me.device.devicePixelRatio + "px";
} else {
this.canvas.style.width = w + "px";
this.canvas.style.height = h + "px";
}
this.compositor.setProjection(this.canvas.width, this.canvas.height);
} | [
"function",
"scaleCanvas",
"(",
"scaleX",
",",
"scaleY",
")",
"{",
"var",
"w",
"=",
"this",
".",
"canvas",
".",
"width",
"*",
"scaleX",
";",
"var",
"h",
"=",
"this",
".",
"canvas",
".",
"height",
"*",
"scaleY",
";",
"// adjust CSS style for High-DPI devices",
"if",
"(",
"me",
".",
"device",
".",
"devicePixelRatio",
">",
"1",
")",
"{",
"this",
".",
"canvas",
".",
"style",
".",
"width",
"=",
"w",
"/",
"me",
".",
"device",
".",
"devicePixelRatio",
"+",
"\"px\"",
";",
"this",
".",
"canvas",
".",
"style",
".",
"height",
"=",
"h",
"/",
"me",
".",
"device",
".",
"devicePixelRatio",
"+",
"\"px\"",
";",
"}",
"else",
"{",
"this",
".",
"canvas",
".",
"style",
".",
"width",
"=",
"w",
"+",
"\"px\"",
";",
"this",
".",
"canvas",
".",
"style",
".",
"height",
"=",
"h",
"+",
"\"px\"",
";",
"}",
"this",
".",
"compositor",
".",
"setProjection",
"(",
"this",
".",
"canvas",
".",
"width",
",",
"this",
".",
"canvas",
".",
"height",
")",
";",
"}"
] | scales the canvas & GL Context
@name scaleCanvas
@memberOf me.WebGLRenderer.prototype
@function | [
"scales",
"the",
"canvas",
"&",
"GL",
"Context"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L22451-L22464 |
7,338 | melonjs/melonJS | dist/melonjs.js | save | function save() {
this._colorStack.push(this.currentColor.clone());
this._matrixStack.push(this.currentTransform.clone());
if (this.gl.isEnabled(this.gl.SCISSOR_TEST)) {
// FIXME avoid slice and object realloc
this._scissorStack.push(this.currentScissor.slice());
}
} | javascript | function save() {
this._colorStack.push(this.currentColor.clone());
this._matrixStack.push(this.currentTransform.clone());
if (this.gl.isEnabled(this.gl.SCISSOR_TEST)) {
// FIXME avoid slice and object realloc
this._scissorStack.push(this.currentScissor.slice());
}
} | [
"function",
"save",
"(",
")",
"{",
"this",
".",
"_colorStack",
".",
"push",
"(",
"this",
".",
"currentColor",
".",
"clone",
"(",
")",
")",
";",
"this",
".",
"_matrixStack",
".",
"push",
"(",
"this",
".",
"currentTransform",
".",
"clone",
"(",
")",
")",
";",
"if",
"(",
"this",
".",
"gl",
".",
"isEnabled",
"(",
"this",
".",
"gl",
".",
"SCISSOR_TEST",
")",
")",
"{",
"// FIXME avoid slice and object realloc",
"this",
".",
"_scissorStack",
".",
"push",
"(",
"this",
".",
"currentScissor",
".",
"slice",
"(",
")",
")",
";",
"}",
"}"
] | saves the canvas context
@name save
@memberOf me.WebGLRenderer.prototype
@function | [
"saves",
"the",
"canvas",
"context"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L22506-L22515 |
7,339 | melonjs/melonJS | dist/melonjs.js | strokePolygon | function strokePolygon(poly, fill) {
if (fill === true) {
this.fillPolygon(poly);
} else {
var len = poly.points.length,
points = this._glPoints,
i; // Grow internal points buffer if necessary
for (i = points.length; i < len; i++) {
points.push(new me.Vector2d());
} // calculate and draw all segments
for (i = 0; i < len; i++) {
points[i].x = poly.pos.x + poly.points[i].x;
points[i].y = poly.pos.y + poly.points[i].y;
}
this.compositor.drawLine(points, len);
}
} | javascript | function strokePolygon(poly, fill) {
if (fill === true) {
this.fillPolygon(poly);
} else {
var len = poly.points.length,
points = this._glPoints,
i; // Grow internal points buffer if necessary
for (i = points.length; i < len; i++) {
points.push(new me.Vector2d());
} // calculate and draw all segments
for (i = 0; i < len; i++) {
points[i].x = poly.pos.x + poly.points[i].x;
points[i].y = poly.pos.y + poly.points[i].y;
}
this.compositor.drawLine(points, len);
}
} | [
"function",
"strokePolygon",
"(",
"poly",
",",
"fill",
")",
"{",
"if",
"(",
"fill",
"===",
"true",
")",
"{",
"this",
".",
"fillPolygon",
"(",
"poly",
")",
";",
"}",
"else",
"{",
"var",
"len",
"=",
"poly",
".",
"points",
".",
"length",
",",
"points",
"=",
"this",
".",
"_glPoints",
",",
"i",
";",
"// Grow internal points buffer if necessary",
"for",
"(",
"i",
"=",
"points",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"points",
".",
"push",
"(",
"new",
"me",
".",
"Vector2d",
"(",
")",
")",
";",
"}",
"// calculate and draw all segments",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"points",
"[",
"i",
"]",
".",
"x",
"=",
"poly",
".",
"pos",
".",
"x",
"+",
"poly",
".",
"points",
"[",
"i",
"]",
".",
"x",
";",
"points",
"[",
"i",
"]",
".",
"y",
"=",
"poly",
".",
"pos",
".",
"y",
"+",
"poly",
".",
"points",
"[",
"i",
"]",
".",
"y",
";",
"}",
"this",
".",
"compositor",
".",
"drawLine",
"(",
"points",
",",
"len",
")",
";",
"}",
"}"
] | Stroke a me.Polygon on the screen with a specified color
@name strokePolygon
@memberOf me.WebGLRenderer.prototype
@function
@param {me.Polygon} poly the shape to draw | [
"Stroke",
"a",
"me",
".",
"Polygon",
"on",
"the",
"screen",
"with",
"a",
"specified",
"color"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L22728-L22748 |
7,340 | melonjs/melonJS | dist/melonjs.js | fillPolygon | function fillPolygon(poly) {
var points = poly.points;
var glPoints = this._glPoints;
var indices = poly.getIndices();
var x = poly.pos.x,
y = poly.pos.y; // Grow internal points buffer if necessary
for (i = glPoints.length; i < indices.length; i++) {
glPoints.push(new me.Vector2d());
} // calculate all vertices
for (var i = 0; i < indices.length; i++) {
glPoints[i].set(x + points[indices[i]].x, y + points[indices[i]].y);
} // draw all triangle
this.compositor.drawTriangle(glPoints, indices.length);
} | javascript | function fillPolygon(poly) {
var points = poly.points;
var glPoints = this._glPoints;
var indices = poly.getIndices();
var x = poly.pos.x,
y = poly.pos.y; // Grow internal points buffer if necessary
for (i = glPoints.length; i < indices.length; i++) {
glPoints.push(new me.Vector2d());
} // calculate all vertices
for (var i = 0; i < indices.length; i++) {
glPoints[i].set(x + points[indices[i]].x, y + points[indices[i]].y);
} // draw all triangle
this.compositor.drawTriangle(glPoints, indices.length);
} | [
"function",
"fillPolygon",
"(",
"poly",
")",
"{",
"var",
"points",
"=",
"poly",
".",
"points",
";",
"var",
"glPoints",
"=",
"this",
".",
"_glPoints",
";",
"var",
"indices",
"=",
"poly",
".",
"getIndices",
"(",
")",
";",
"var",
"x",
"=",
"poly",
".",
"pos",
".",
"x",
",",
"y",
"=",
"poly",
".",
"pos",
".",
"y",
";",
"// Grow internal points buffer if necessary",
"for",
"(",
"i",
"=",
"glPoints",
".",
"length",
";",
"i",
"<",
"indices",
".",
"length",
";",
"i",
"++",
")",
"{",
"glPoints",
".",
"push",
"(",
"new",
"me",
".",
"Vector2d",
"(",
")",
")",
";",
"}",
"// calculate all vertices",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"indices",
".",
"length",
";",
"i",
"++",
")",
"{",
"glPoints",
"[",
"i",
"]",
".",
"set",
"(",
"x",
"+",
"points",
"[",
"indices",
"[",
"i",
"]",
"]",
".",
"x",
",",
"y",
"+",
"points",
"[",
"indices",
"[",
"i",
"]",
"]",
".",
"y",
")",
";",
"}",
"// draw all triangle",
"this",
".",
"compositor",
".",
"drawTriangle",
"(",
"glPoints",
",",
"indices",
".",
"length",
")",
";",
"}"
] | Fill a me.Polygon on the screen
@name fillPolygon
@memberOf me.WebGLRenderer.prototype
@function
@param {me.Polygon} poly the shape to draw | [
"Fill",
"a",
"me",
".",
"Polygon",
"on",
"the",
"screen"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L22757-L22775 |
7,341 | melonjs/melonJS | dist/melonjs.js | translate | function translate(x, y) {
if (this.settings.subPixel === false) {
this.currentTransform.translate(~~x, ~~y);
} else {
this.currentTransform.translate(x, y);
}
} | javascript | function translate(x, y) {
if (this.settings.subPixel === false) {
this.currentTransform.translate(~~x, ~~y);
} else {
this.currentTransform.translate(x, y);
}
} | [
"function",
"translate",
"(",
"x",
",",
"y",
")",
"{",
"if",
"(",
"this",
".",
"settings",
".",
"subPixel",
"===",
"false",
")",
"{",
"this",
".",
"currentTransform",
".",
"translate",
"(",
"~",
"~",
"x",
",",
"~",
"~",
"y",
")",
";",
"}",
"else",
"{",
"this",
".",
"currentTransform",
".",
"translate",
"(",
"x",
",",
"y",
")",
";",
"}",
"}"
] | Translates the uniform matrix by the given coordinates
@name translate
@memberOf me.WebGLRenderer.prototype
@function
@param {Number} x
@param {Number} y | [
"Translates",
"the",
"uniform",
"matrix",
"by",
"the",
"given",
"coordinates"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L22862-L22868 |
7,342 | melonjs/melonJS | dist/melonjs.js | setProjection | function setProjection(w, h) {
this.flush();
this.gl.viewport(0, 0, w, h);
this.uMatrix.setTransform(2 / w, 0, 0, 0, -2 / h, 0, -1, 1, 1);
} | javascript | function setProjection(w, h) {
this.flush();
this.gl.viewport(0, 0, w, h);
this.uMatrix.setTransform(2 / w, 0, 0, 0, -2 / h, 0, -1, 1, 1);
} | [
"function",
"setProjection",
"(",
"w",
",",
"h",
")",
"{",
"this",
".",
"flush",
"(",
")",
";",
"this",
".",
"gl",
".",
"viewport",
"(",
"0",
",",
"0",
",",
"w",
",",
"h",
")",
";",
"this",
".",
"uMatrix",
".",
"setTransform",
"(",
"2",
"/",
"w",
",",
"0",
",",
"0",
",",
"0",
",",
"-",
"2",
"/",
"h",
",",
"0",
",",
"-",
"1",
",",
"1",
",",
"1",
")",
";",
"}"
] | Sets the projection matrix with the given size
@name setProjection
@memberOf me.WebGLRenderer.Compositor
@function
@param {Number} w WebGL Canvas width
@param {Number} h WebGL Canvas height | [
"Sets",
"the",
"projection",
"matrix",
"with",
"the",
"given",
"size"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L23099-L23103 |
7,343 | melonjs/melonJS | dist/melonjs.js | compileProgram | function compileProgram(gl, vertex, fragment) {
var vertShader = compileShader(gl, gl.VERTEX_SHADER, vertex);
var fragShader = compileShader(gl, gl.FRAGMENT_SHADER, fragment);
var program = gl.createProgram();
gl.attachShader(program, vertShader);
gl.attachShader(program, fragShader);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
throw new Error("Error initializing Shader " + this + "\n" + "gl.VALIDATE_STATUS: " + gl.getProgramParameter(program, gl.VALIDATE_STATUS) + "\n" + "gl.getError()" + gl.getError() + "\n" + "gl.getProgramInfoLog()" + gl.getProgramInfoLog(program));
}
gl.useProgram(program); // clean-up
gl.deleteShader(vertShader);
gl.deleteShader(fragShader);
return program;
} | javascript | function compileProgram(gl, vertex, fragment) {
var vertShader = compileShader(gl, gl.VERTEX_SHADER, vertex);
var fragShader = compileShader(gl, gl.FRAGMENT_SHADER, fragment);
var program = gl.createProgram();
gl.attachShader(program, vertShader);
gl.attachShader(program, fragShader);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
throw new Error("Error initializing Shader " + this + "\n" + "gl.VALIDATE_STATUS: " + gl.getProgramParameter(program, gl.VALIDATE_STATUS) + "\n" + "gl.getError()" + gl.getError() + "\n" + "gl.getProgramInfoLog()" + gl.getProgramInfoLog(program));
}
gl.useProgram(program); // clean-up
gl.deleteShader(vertShader);
gl.deleteShader(fragShader);
return program;
} | [
"function",
"compileProgram",
"(",
"gl",
",",
"vertex",
",",
"fragment",
")",
"{",
"var",
"vertShader",
"=",
"compileShader",
"(",
"gl",
",",
"gl",
".",
"VERTEX_SHADER",
",",
"vertex",
")",
";",
"var",
"fragShader",
"=",
"compileShader",
"(",
"gl",
",",
"gl",
".",
"FRAGMENT_SHADER",
",",
"fragment",
")",
";",
"var",
"program",
"=",
"gl",
".",
"createProgram",
"(",
")",
";",
"gl",
".",
"attachShader",
"(",
"program",
",",
"vertShader",
")",
";",
"gl",
".",
"attachShader",
"(",
"program",
",",
"fragShader",
")",
";",
"gl",
".",
"linkProgram",
"(",
"program",
")",
";",
"if",
"(",
"!",
"gl",
".",
"getProgramParameter",
"(",
"program",
",",
"gl",
".",
"LINK_STATUS",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Error initializing Shader \"",
"+",
"this",
"+",
"\"\\n\"",
"+",
"\"gl.VALIDATE_STATUS: \"",
"+",
"gl",
".",
"getProgramParameter",
"(",
"program",
",",
"gl",
".",
"VALIDATE_STATUS",
")",
"+",
"\"\\n\"",
"+",
"\"gl.getError()\"",
"+",
"gl",
".",
"getError",
"(",
")",
"+",
"\"\\n\"",
"+",
"\"gl.getProgramInfoLog()\"",
"+",
"gl",
".",
"getProgramInfoLog",
"(",
"program",
")",
")",
";",
"}",
"gl",
".",
"useProgram",
"(",
"program",
")",
";",
"// clean-up",
"gl",
".",
"deleteShader",
"(",
"vertShader",
")",
";",
"gl",
".",
"deleteShader",
"(",
"fragShader",
")",
";",
"return",
"program",
";",
"}"
] | Compile GLSL into a shader object
@private | [
"Compile",
"GLSL",
"into",
"a",
"shader",
"object"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L23510-L23527 |
7,344 | melonjs/melonJS | dist/melonjs.js | minify | function minify(src) {
// remove comments
src = src.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, "$1"); // Remove leading and trailing whitespace from lines
src = src.replace(/(\\n\s+)|(\s+\\n)/g, ""); // Remove line breaks
src = src.replace(/(\\r|\\n)+/g, ""); // Remove unnecessary whitespace
src = src.replace(/\s*([;,[\](){}\\\/\-+*|^&!=<>?~%])\s*/g, "$1");
return src;
} | javascript | function minify(src) {
// remove comments
src = src.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, "$1"); // Remove leading and trailing whitespace from lines
src = src.replace(/(\\n\s+)|(\s+\\n)/g, ""); // Remove line breaks
src = src.replace(/(\\r|\\n)+/g, ""); // Remove unnecessary whitespace
src = src.replace(/\s*([;,[\](){}\\\/\-+*|^&!=<>?~%])\s*/g, "$1");
return src;
} | [
"function",
"minify",
"(",
"src",
")",
"{",
"// remove comments",
"src",
"=",
"src",
".",
"replace",
"(",
"/",
"\\/\\*[\\s\\S]*?\\*\\/|([^\\\\:]|^)\\/\\/.*$",
"/",
"gm",
",",
"\"$1\"",
")",
";",
"// Remove leading and trailing whitespace from lines",
"src",
"=",
"src",
".",
"replace",
"(",
"/",
"(\\\\n\\s+)|(\\s+\\\\n)",
"/",
"g",
",",
"\"\"",
")",
";",
"// Remove line breaks",
"src",
"=",
"src",
".",
"replace",
"(",
"/",
"(\\\\r|\\\\n)+",
"/",
"g",
",",
"\"\"",
")",
";",
"// Remove unnecessary whitespace",
"src",
"=",
"src",
".",
"replace",
"(",
"/",
"\\s*([;,[\\](){}\\\\\\/\\-+*|^&!=<>?~%])\\s*",
"/",
"g",
",",
"\"$1\"",
")",
";",
"return",
"src",
";",
"}"
] | clean the given source from space, comments, etc...
@private | [
"clean",
"the",
"given",
"source",
"from",
"space",
"comments",
"etc",
"..."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L23569-L23579 |
7,345 | melonjs/melonJS | dist/melonjs.js | setEvent | function setEvent(event, pageX, pageY, clientX, clientY, pointerId) {
var width = 1;
var height = 1; // the original event object
this.event = event;
this.pageX = pageX || 0;
this.pageY = pageY || 0;
this.clientX = clientX || 0;
this.clientY = clientY || 0; // translate to local coordinates
me.input.globalToLocal(this.pageX, this.pageY, this.pos); // true if not originally a pointer event
this.isNormalized = !me.device.PointerEvent || me.device.PointerEvent && !(event instanceof window.PointerEvent);
if (event.type === "wheel") {
this.deltaMode = 1;
this.deltaX = event.deltaX;
this.deltaY = -1 / 40 * event.wheelDelta;
event.wheelDeltaX && (this.deltaX = -1 / 40 * event.wheelDeltaX);
} // could be 0, so test if defined
this.pointerId = typeof pointerId !== "undefined" ? pointerId : 1;
this.isPrimary = typeof event.isPrimary !== "undefined" ? event.isPrimary : true; // in case of touch events, button is not defined
this.button = event.button || 0;
this.type = event.type;
this.gameScreenX = this.pos.x;
this.gameScreenY = this.pos.y; // get the current screen to world offset
if (typeof me.game.viewport !== "undefined") {
me.game.viewport.localToWorld(this.gameScreenX, this.gameScreenY, viewportOffset);
}
/* Initialize the two coordinate space properties. */
this.gameWorldX = viewportOffset.x;
this.gameWorldY = viewportOffset.y; // get the pointer size
if (this.isNormalized === false) {
// native PointerEvent
width = event.width || 1;
height = event.height || 1;
} else if (typeof event.radiusX === "number") {
// TouchEvent
width = event.radiusX * 2 || 1;
height = event.radiusY * 2 || 1;
} // resize the pointer object accordingly
this.resize(width, height);
} | javascript | function setEvent(event, pageX, pageY, clientX, clientY, pointerId) {
var width = 1;
var height = 1; // the original event object
this.event = event;
this.pageX = pageX || 0;
this.pageY = pageY || 0;
this.clientX = clientX || 0;
this.clientY = clientY || 0; // translate to local coordinates
me.input.globalToLocal(this.pageX, this.pageY, this.pos); // true if not originally a pointer event
this.isNormalized = !me.device.PointerEvent || me.device.PointerEvent && !(event instanceof window.PointerEvent);
if (event.type === "wheel") {
this.deltaMode = 1;
this.deltaX = event.deltaX;
this.deltaY = -1 / 40 * event.wheelDelta;
event.wheelDeltaX && (this.deltaX = -1 / 40 * event.wheelDeltaX);
} // could be 0, so test if defined
this.pointerId = typeof pointerId !== "undefined" ? pointerId : 1;
this.isPrimary = typeof event.isPrimary !== "undefined" ? event.isPrimary : true; // in case of touch events, button is not defined
this.button = event.button || 0;
this.type = event.type;
this.gameScreenX = this.pos.x;
this.gameScreenY = this.pos.y; // get the current screen to world offset
if (typeof me.game.viewport !== "undefined") {
me.game.viewport.localToWorld(this.gameScreenX, this.gameScreenY, viewportOffset);
}
/* Initialize the two coordinate space properties. */
this.gameWorldX = viewportOffset.x;
this.gameWorldY = viewportOffset.y; // get the pointer size
if (this.isNormalized === false) {
// native PointerEvent
width = event.width || 1;
height = event.height || 1;
} else if (typeof event.radiusX === "number") {
// TouchEvent
width = event.radiusX * 2 || 1;
height = event.radiusY * 2 || 1;
} // resize the pointer object accordingly
this.resize(width, height);
} | [
"function",
"setEvent",
"(",
"event",
",",
"pageX",
",",
"pageY",
",",
"clientX",
",",
"clientY",
",",
"pointerId",
")",
"{",
"var",
"width",
"=",
"1",
";",
"var",
"height",
"=",
"1",
";",
"// the original event object",
"this",
".",
"event",
"=",
"event",
";",
"this",
".",
"pageX",
"=",
"pageX",
"||",
"0",
";",
"this",
".",
"pageY",
"=",
"pageY",
"||",
"0",
";",
"this",
".",
"clientX",
"=",
"clientX",
"||",
"0",
";",
"this",
".",
"clientY",
"=",
"clientY",
"||",
"0",
";",
"// translate to local coordinates",
"me",
".",
"input",
".",
"globalToLocal",
"(",
"this",
".",
"pageX",
",",
"this",
".",
"pageY",
",",
"this",
".",
"pos",
")",
";",
"// true if not originally a pointer event",
"this",
".",
"isNormalized",
"=",
"!",
"me",
".",
"device",
".",
"PointerEvent",
"||",
"me",
".",
"device",
".",
"PointerEvent",
"&&",
"!",
"(",
"event",
"instanceof",
"window",
".",
"PointerEvent",
")",
";",
"if",
"(",
"event",
".",
"type",
"===",
"\"wheel\"",
")",
"{",
"this",
".",
"deltaMode",
"=",
"1",
";",
"this",
".",
"deltaX",
"=",
"event",
".",
"deltaX",
";",
"this",
".",
"deltaY",
"=",
"-",
"1",
"/",
"40",
"*",
"event",
".",
"wheelDelta",
";",
"event",
".",
"wheelDeltaX",
"&&",
"(",
"this",
".",
"deltaX",
"=",
"-",
"1",
"/",
"40",
"*",
"event",
".",
"wheelDeltaX",
")",
";",
"}",
"// could be 0, so test if defined",
"this",
".",
"pointerId",
"=",
"typeof",
"pointerId",
"!==",
"\"undefined\"",
"?",
"pointerId",
":",
"1",
";",
"this",
".",
"isPrimary",
"=",
"typeof",
"event",
".",
"isPrimary",
"!==",
"\"undefined\"",
"?",
"event",
".",
"isPrimary",
":",
"true",
";",
"// in case of touch events, button is not defined",
"this",
".",
"button",
"=",
"event",
".",
"button",
"||",
"0",
";",
"this",
".",
"type",
"=",
"event",
".",
"type",
";",
"this",
".",
"gameScreenX",
"=",
"this",
".",
"pos",
".",
"x",
";",
"this",
".",
"gameScreenY",
"=",
"this",
".",
"pos",
".",
"y",
";",
"// get the current screen to world offset",
"if",
"(",
"typeof",
"me",
".",
"game",
".",
"viewport",
"!==",
"\"undefined\"",
")",
"{",
"me",
".",
"game",
".",
"viewport",
".",
"localToWorld",
"(",
"this",
".",
"gameScreenX",
",",
"this",
".",
"gameScreenY",
",",
"viewportOffset",
")",
";",
"}",
"/* Initialize the two coordinate space properties. */",
"this",
".",
"gameWorldX",
"=",
"viewportOffset",
".",
"x",
";",
"this",
".",
"gameWorldY",
"=",
"viewportOffset",
".",
"y",
";",
"// get the pointer size",
"if",
"(",
"this",
".",
"isNormalized",
"===",
"false",
")",
"{",
"// native PointerEvent",
"width",
"=",
"event",
".",
"width",
"||",
"1",
";",
"height",
"=",
"event",
".",
"height",
"||",
"1",
";",
"}",
"else",
"if",
"(",
"typeof",
"event",
".",
"radiusX",
"===",
"\"number\"",
")",
"{",
"// TouchEvent",
"width",
"=",
"event",
".",
"radiusX",
"*",
"2",
"||",
"1",
";",
"height",
"=",
"event",
".",
"radiusY",
"*",
"2",
"||",
"1",
";",
"}",
"// resize the pointer object accordingly",
"this",
".",
"resize",
"(",
"width",
",",
"height",
")",
";",
"}"
] | initialize the Pointer object using the given Event Object
@name me.Pointer#set
@private
@function
@param {Event} event the original Event object
@param {Number} pageX the horizontal coordinate at which the event occurred, relative to the left edge of the entire document
@param {Number} pageY the vertical coordinate at which the event occurred, relative to the left edge of the entire document
@param {Number} clientX the horizontal coordinate within the application's client area at which the event occurred
@param {Number} clientX the vertical coordinate within the application's client area at which the event occurred
@param {Number} pointedId the Pointer, Touch or Mouse event Id | [
"initialize",
"the",
"Pointer",
"object",
"using",
"the",
"given",
"Event",
"Object"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L24587-L24638 |
7,346 | melonjs/melonJS | dist/melonjs.js | normalizeEvent | function normalizeEvent(event) {
var pointer; // PointerEvent or standard Mouse event
if (me.device.TouchEvent && event.changedTouches) {
// iOS/Android Touch event
for (var i = 0, l = event.changedTouches.length; i < l; i++) {
var touchEvent = event.changedTouches[i];
pointer = T_POINTERS.pop();
pointer.setEvent(event, touchEvent.pageX, touchEvent.pageY, touchEvent.clientX, touchEvent.clientY, touchEvent.identifier);
normalizedEvents.push(pointer);
}
} else {
// Mouse or PointerEvent
pointer = T_POINTERS.pop();
pointer.setEvent(event, event.pageX, event.pageY, event.clientX, event.clientY, event.pointerId);
normalizedEvents.push(pointer);
} // if event.isPrimary is defined and false, return
if (event.isPrimary === false) {
return normalizedEvents;
} // else use the first entry to simulate mouse event
normalizedEvents[0].isPrimary = true;
Object.assign(api.pointer, normalizedEvents[0]);
return normalizedEvents;
} | javascript | function normalizeEvent(event) {
var pointer; // PointerEvent or standard Mouse event
if (me.device.TouchEvent && event.changedTouches) {
// iOS/Android Touch event
for (var i = 0, l = event.changedTouches.length; i < l; i++) {
var touchEvent = event.changedTouches[i];
pointer = T_POINTERS.pop();
pointer.setEvent(event, touchEvent.pageX, touchEvent.pageY, touchEvent.clientX, touchEvent.clientY, touchEvent.identifier);
normalizedEvents.push(pointer);
}
} else {
// Mouse or PointerEvent
pointer = T_POINTERS.pop();
pointer.setEvent(event, event.pageX, event.pageY, event.clientX, event.clientY, event.pointerId);
normalizedEvents.push(pointer);
} // if event.isPrimary is defined and false, return
if (event.isPrimary === false) {
return normalizedEvents;
} // else use the first entry to simulate mouse event
normalizedEvents[0].isPrimary = true;
Object.assign(api.pointer, normalizedEvents[0]);
return normalizedEvents;
} | [
"function",
"normalizeEvent",
"(",
"event",
")",
"{",
"var",
"pointer",
";",
"// PointerEvent or standard Mouse event",
"if",
"(",
"me",
".",
"device",
".",
"TouchEvent",
"&&",
"event",
".",
"changedTouches",
")",
"{",
"// iOS/Android Touch event",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"event",
".",
"changedTouches",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"var",
"touchEvent",
"=",
"event",
".",
"changedTouches",
"[",
"i",
"]",
";",
"pointer",
"=",
"T_POINTERS",
".",
"pop",
"(",
")",
";",
"pointer",
".",
"setEvent",
"(",
"event",
",",
"touchEvent",
".",
"pageX",
",",
"touchEvent",
".",
"pageY",
",",
"touchEvent",
".",
"clientX",
",",
"touchEvent",
".",
"clientY",
",",
"touchEvent",
".",
"identifier",
")",
";",
"normalizedEvents",
".",
"push",
"(",
"pointer",
")",
";",
"}",
"}",
"else",
"{",
"// Mouse or PointerEvent",
"pointer",
"=",
"T_POINTERS",
".",
"pop",
"(",
")",
";",
"pointer",
".",
"setEvent",
"(",
"event",
",",
"event",
".",
"pageX",
",",
"event",
".",
"pageY",
",",
"event",
".",
"clientX",
",",
"event",
".",
"clientY",
",",
"event",
".",
"pointerId",
")",
";",
"normalizedEvents",
".",
"push",
"(",
"pointer",
")",
";",
"}",
"// if event.isPrimary is defined and false, return",
"if",
"(",
"event",
".",
"isPrimary",
"===",
"false",
")",
"{",
"return",
"normalizedEvents",
";",
"}",
"// else use the first entry to simulate mouse event",
"normalizedEvents",
"[",
"0",
"]",
".",
"isPrimary",
"=",
"true",
";",
"Object",
".",
"assign",
"(",
"api",
".",
"pointer",
",",
"normalizedEvents",
"[",
"0",
"]",
")",
";",
"return",
"normalizedEvents",
";",
"}"
] | translate event coordinates
@ignore | [
"translate",
"event",
"coordinates"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L24992-L25019 |
7,347 | melonjs/melonJS | dist/melonjs.js | wiredXbox360NormalizeFn | function wiredXbox360NormalizeFn(value, axis, button) {
if (button === api.GAMEPAD.BUTTONS.L2 || button === api.GAMEPAD.BUTTONS.R2) {
return (value + 1) / 2;
}
return value;
} | javascript | function wiredXbox360NormalizeFn(value, axis, button) {
if (button === api.GAMEPAD.BUTTONS.L2 || button === api.GAMEPAD.BUTTONS.R2) {
return (value + 1) / 2;
}
return value;
} | [
"function",
"wiredXbox360NormalizeFn",
"(",
"value",
",",
"axis",
",",
"button",
")",
"{",
"if",
"(",
"button",
"===",
"api",
".",
"GAMEPAD",
".",
"BUTTONS",
".",
"L2",
"||",
"button",
"===",
"api",
".",
"GAMEPAD",
".",
"BUTTONS",
".",
"R2",
")",
"{",
"return",
"(",
"value",
"+",
"1",
")",
"/",
"2",
";",
"}",
"return",
"value",
";",
"}"
] | Normalize axis values for wired Xbox 360
@ignore | [
"Normalize",
"axis",
"values",
"for",
"wired",
"Xbox",
"360"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L25369-L25375 |
7,348 | melonjs/melonJS | dist/melonjs.js | ouyaNormalizeFn | function ouyaNormalizeFn(value, axis, button) {
if (value > 0) {
if (button === api.GAMEPAD.BUTTONS.L2) {
// L2 is wonky; seems like the deadzone is around 20000
// (That's over 15% of the total range!)
value = Math.max(0, value - 20000) / 111070;
} else {
// Normalize [1..65536] => [0.0..0.5]
value = (value - 1) / 131070;
}
} else {
// Normalize [-65536..-1] => [0.5..1.0]
value = (65536 + value) / 131070 + 0.5;
}
return value;
} | javascript | function ouyaNormalizeFn(value, axis, button) {
if (value > 0) {
if (button === api.GAMEPAD.BUTTONS.L2) {
// L2 is wonky; seems like the deadzone is around 20000
// (That's over 15% of the total range!)
value = Math.max(0, value - 20000) / 111070;
} else {
// Normalize [1..65536] => [0.0..0.5]
value = (value - 1) / 131070;
}
} else {
// Normalize [-65536..-1] => [0.5..1.0]
value = (65536 + value) / 131070 + 0.5;
}
return value;
} | [
"function",
"ouyaNormalizeFn",
"(",
"value",
",",
"axis",
",",
"button",
")",
"{",
"if",
"(",
"value",
">",
"0",
")",
"{",
"if",
"(",
"button",
"===",
"api",
".",
"GAMEPAD",
".",
"BUTTONS",
".",
"L2",
")",
"{",
"// L2 is wonky; seems like the deadzone is around 20000",
"// (That's over 15% of the total range!)",
"value",
"=",
"Math",
".",
"max",
"(",
"0",
",",
"value",
"-",
"20000",
")",
"/",
"111070",
";",
"}",
"else",
"{",
"// Normalize [1..65536] => [0.0..0.5]",
"value",
"=",
"(",
"value",
"-",
"1",
")",
"/",
"131070",
";",
"}",
"}",
"else",
"{",
"// Normalize [-65536..-1] => [0.5..1.0]",
"value",
"=",
"(",
"65536",
"+",
"value",
")",
"/",
"131070",
"+",
"0.5",
";",
"}",
"return",
"value",
";",
"}"
] | Normalize axis values for OUYA
@ignore | [
"Normalize",
"axis",
"values",
"for",
"OUYA"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L25382-L25398 |
7,349 | melonjs/melonJS | dist/melonjs.js | lighten | function lighten(scale) {
scale = me.Math.clamp(scale, 0, 1);
this.glArray[0] = me.Math.clamp(this.glArray[0] + (1 - this.glArray[0]) * scale, 0, 1);
this.glArray[1] = me.Math.clamp(this.glArray[1] + (1 - this.glArray[1]) * scale, 0, 1);
this.glArray[2] = me.Math.clamp(this.glArray[2] + (1 - this.glArray[2]) * scale, 0, 1);
return this;
} | javascript | function lighten(scale) {
scale = me.Math.clamp(scale, 0, 1);
this.glArray[0] = me.Math.clamp(this.glArray[0] + (1 - this.glArray[0]) * scale, 0, 1);
this.glArray[1] = me.Math.clamp(this.glArray[1] + (1 - this.glArray[1]) * scale, 0, 1);
this.glArray[2] = me.Math.clamp(this.glArray[2] + (1 - this.glArray[2]) * scale, 0, 1);
return this;
} | [
"function",
"lighten",
"(",
"scale",
")",
"{",
"scale",
"=",
"me",
".",
"Math",
".",
"clamp",
"(",
"scale",
",",
"0",
",",
"1",
")",
";",
"this",
".",
"glArray",
"[",
"0",
"]",
"=",
"me",
".",
"Math",
".",
"clamp",
"(",
"this",
".",
"glArray",
"[",
"0",
"]",
"+",
"(",
"1",
"-",
"this",
".",
"glArray",
"[",
"0",
"]",
")",
"*",
"scale",
",",
"0",
",",
"1",
")",
";",
"this",
".",
"glArray",
"[",
"1",
"]",
"=",
"me",
".",
"Math",
".",
"clamp",
"(",
"this",
".",
"glArray",
"[",
"1",
"]",
"+",
"(",
"1",
"-",
"this",
".",
"glArray",
"[",
"1",
"]",
")",
"*",
"scale",
",",
"0",
",",
"1",
")",
";",
"this",
".",
"glArray",
"[",
"2",
"]",
"=",
"me",
".",
"Math",
".",
"clamp",
"(",
"this",
".",
"glArray",
"[",
"2",
"]",
"+",
"(",
"1",
"-",
"this",
".",
"glArray",
"[",
"2",
"]",
")",
"*",
"scale",
",",
"0",
",",
"1",
")",
";",
"return",
"this",
";",
"}"
] | Lighten this color value by 0..1
@name lighten
@memberOf me.Color
@function
@param {Number} scale
@return {me.Color} Reference to this object for method chaining | [
"Lighten",
"this",
"color",
"value",
"by",
"0",
"..",
"1"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L26332-L26338 |
7,350 | melonjs/melonJS | dist/melonjs.js | add | function add(props) {
Object.keys(props).forEach(function (key) {
if (isReserved(key)) {
return;
}
(function (prop) {
Object.defineProperty(api, prop, {
configurable: true,
enumerable: true,
/**
* @ignore
*/
get: function get() {
return data[prop];
},
/**
* @ignore
*/
set: function set(value) {
data[prop] = value;
if (me.device.localStorage === true) {
localStorage.setItem("me.save." + prop, JSON.stringify(value));
}
}
});
})(key); // Set default value for key
if (!(key in data)) {
api[key] = props[key];
}
}); // Save keys
if (me.device.localStorage === true) {
localStorage.setItem("me.save", JSON.stringify(Object.keys(data)));
}
} | javascript | function add(props) {
Object.keys(props).forEach(function (key) {
if (isReserved(key)) {
return;
}
(function (prop) {
Object.defineProperty(api, prop, {
configurable: true,
enumerable: true,
/**
* @ignore
*/
get: function get() {
return data[prop];
},
/**
* @ignore
*/
set: function set(value) {
data[prop] = value;
if (me.device.localStorage === true) {
localStorage.setItem("me.save." + prop, JSON.stringify(value));
}
}
});
})(key); // Set default value for key
if (!(key in data)) {
api[key] = props[key];
}
}); // Save keys
if (me.device.localStorage === true) {
localStorage.setItem("me.save", JSON.stringify(Object.keys(data)));
}
} | [
"function",
"add",
"(",
"props",
")",
"{",
"Object",
".",
"keys",
"(",
"props",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"isReserved",
"(",
"key",
")",
")",
"{",
"return",
";",
"}",
"(",
"function",
"(",
"prop",
")",
"{",
"Object",
".",
"defineProperty",
"(",
"api",
",",
"prop",
",",
"{",
"configurable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"/**\n * @ignore\n */",
"get",
":",
"function",
"get",
"(",
")",
"{",
"return",
"data",
"[",
"prop",
"]",
";",
"}",
",",
"/**\n * @ignore\n */",
"set",
":",
"function",
"set",
"(",
"value",
")",
"{",
"data",
"[",
"prop",
"]",
"=",
"value",
";",
"if",
"(",
"me",
".",
"device",
".",
"localStorage",
"===",
"true",
")",
"{",
"localStorage",
".",
"setItem",
"(",
"\"me.save.\"",
"+",
"prop",
",",
"JSON",
".",
"stringify",
"(",
"value",
")",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
")",
"(",
"key",
")",
";",
"// Set default value for key",
"if",
"(",
"!",
"(",
"key",
"in",
"data",
")",
")",
"{",
"api",
"[",
"key",
"]",
"=",
"props",
"[",
"key",
"]",
";",
"}",
"}",
")",
";",
"// Save keys",
"if",
"(",
"me",
".",
"device",
".",
"localStorage",
"===",
"true",
")",
"{",
"localStorage",
".",
"setItem",
"(",
"\"me.save\"",
",",
"JSON",
".",
"stringify",
"(",
"Object",
".",
"keys",
"(",
"data",
")",
")",
")",
";",
"}",
"}"
] | Add new keys to localStorage and set them to the given default values if they do not exist
@name add
@memberOf me.save
@function
@param {Object} props key and corresponding values
@example
// Initialize "score" and "lives" with default values
me.save.add({ score : 0, lives : 3 }); | [
"Add",
"new",
"keys",
"to",
"localStorage",
"and",
"set",
"them",
"to",
"the",
"given",
"default",
"values",
"if",
"they",
"do",
"not",
"exist"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L26668-L26708 |
7,351 | melonjs/melonJS | dist/melonjs.js | remove | function remove(key) {
if (!isReserved(key)) {
if (typeof data[key] !== "undefined") {
delete data[key];
if (me.device.localStorage === true) {
localStorage.removeItem("me.save." + key);
localStorage.setItem("me.save", JSON.stringify(Object.keys(data)));
}
}
}
} | javascript | function remove(key) {
if (!isReserved(key)) {
if (typeof data[key] !== "undefined") {
delete data[key];
if (me.device.localStorage === true) {
localStorage.removeItem("me.save." + key);
localStorage.setItem("me.save", JSON.stringify(Object.keys(data)));
}
}
}
} | [
"function",
"remove",
"(",
"key",
")",
"{",
"if",
"(",
"!",
"isReserved",
"(",
"key",
")",
")",
"{",
"if",
"(",
"typeof",
"data",
"[",
"key",
"]",
"!==",
"\"undefined\"",
")",
"{",
"delete",
"data",
"[",
"key",
"]",
";",
"if",
"(",
"me",
".",
"device",
".",
"localStorage",
"===",
"true",
")",
"{",
"localStorage",
".",
"removeItem",
"(",
"\"me.save.\"",
"+",
"key",
")",
";",
"localStorage",
".",
"setItem",
"(",
"\"me.save\"",
",",
"JSON",
".",
"stringify",
"(",
"Object",
".",
"keys",
"(",
"data",
")",
")",
")",
";",
"}",
"}",
"}",
"}"
] | Remove a key from localStorage
@name remove
@memberOf me.save
@function
@param {String} key key to be removed
@example
// Remove the "score" key from localStorage
me.save.remove("score"); | [
"Remove",
"a",
"key",
"from",
"localStorage"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L26720-L26731 |
7,352 | melonjs/melonJS | dist/melonjs.js | setTMXValue | function setTMXValue(name, type, value) {
var match;
if (typeof value !== "string") {
// Value is already normalized (e.g. with JSON maps)
return value;
}
switch (type) {
case "int":
case "float":
value = Number(value);
break;
case "bool":
value = value === "true";
break;
default:
// try to parse it anyway
if (!value || me.utils.string.isBoolean(value)) {
// if value not defined or boolean
value = value ? value === "true" : true;
} else if (me.utils.string.isNumeric(value)) {
// check if numeric
value = Number(value);
} else if (value.search(/^json:/i) === 0) {
// try to parse it
match = value.split(/^json:/i)[1];
try {
value = JSON.parse(match);
} catch (e) {
throw new Error("Unable to parse JSON: " + match);
}
} else if (value.search(/^eval:/i) === 0) {
// try to evaluate it
match = value.split(/^eval:/i)[1];
try {
// eslint-disable-next-line
value = eval(match);
} catch (e) {
throw new Error("Unable to evaluate: " + match);
}
} else if ((match = value.match(/^#([\da-fA-F])([\da-fA-F]{3})$/)) || (match = value.match(/^#([\da-fA-F]{2})([\da-fA-F]{6})$/))) {
value = "#" + match[2] + match[1];
} // normalize values
if (name.search(/^(ratio|anchorPoint)$/) === 0) {
// convert number to vector
if (typeof value === "number") {
value = {
"x": value,
"y": value
};
}
}
} // return the interpreted value
return value;
} | javascript | function setTMXValue(name, type, value) {
var match;
if (typeof value !== "string") {
// Value is already normalized (e.g. with JSON maps)
return value;
}
switch (type) {
case "int":
case "float":
value = Number(value);
break;
case "bool":
value = value === "true";
break;
default:
// try to parse it anyway
if (!value || me.utils.string.isBoolean(value)) {
// if value not defined or boolean
value = value ? value === "true" : true;
} else if (me.utils.string.isNumeric(value)) {
// check if numeric
value = Number(value);
} else if (value.search(/^json:/i) === 0) {
// try to parse it
match = value.split(/^json:/i)[1];
try {
value = JSON.parse(match);
} catch (e) {
throw new Error("Unable to parse JSON: " + match);
}
} else if (value.search(/^eval:/i) === 0) {
// try to evaluate it
match = value.split(/^eval:/i)[1];
try {
// eslint-disable-next-line
value = eval(match);
} catch (e) {
throw new Error("Unable to evaluate: " + match);
}
} else if ((match = value.match(/^#([\da-fA-F])([\da-fA-F]{3})$/)) || (match = value.match(/^#([\da-fA-F]{2})([\da-fA-F]{6})$/))) {
value = "#" + match[2] + match[1];
} // normalize values
if (name.search(/^(ratio|anchorPoint)$/) === 0) {
// convert number to vector
if (typeof value === "number") {
value = {
"x": value,
"y": value
};
}
}
} // return the interpreted value
return value;
} | [
"function",
"setTMXValue",
"(",
"name",
",",
"type",
",",
"value",
")",
"{",
"var",
"match",
";",
"if",
"(",
"typeof",
"value",
"!==",
"\"string\"",
")",
"{",
"// Value is already normalized (e.g. with JSON maps)",
"return",
"value",
";",
"}",
"switch",
"(",
"type",
")",
"{",
"case",
"\"int\"",
":",
"case",
"\"float\"",
":",
"value",
"=",
"Number",
"(",
"value",
")",
";",
"break",
";",
"case",
"\"bool\"",
":",
"value",
"=",
"value",
"===",
"\"true\"",
";",
"break",
";",
"default",
":",
"// try to parse it anyway",
"if",
"(",
"!",
"value",
"||",
"me",
".",
"utils",
".",
"string",
".",
"isBoolean",
"(",
"value",
")",
")",
"{",
"// if value not defined or boolean",
"value",
"=",
"value",
"?",
"value",
"===",
"\"true\"",
":",
"true",
";",
"}",
"else",
"if",
"(",
"me",
".",
"utils",
".",
"string",
".",
"isNumeric",
"(",
"value",
")",
")",
"{",
"// check if numeric",
"value",
"=",
"Number",
"(",
"value",
")",
";",
"}",
"else",
"if",
"(",
"value",
".",
"search",
"(",
"/",
"^json:",
"/",
"i",
")",
"===",
"0",
")",
"{",
"// try to parse it",
"match",
"=",
"value",
".",
"split",
"(",
"/",
"^json:",
"/",
"i",
")",
"[",
"1",
"]",
";",
"try",
"{",
"value",
"=",
"JSON",
".",
"parse",
"(",
"match",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Unable to parse JSON: \"",
"+",
"match",
")",
";",
"}",
"}",
"else",
"if",
"(",
"value",
".",
"search",
"(",
"/",
"^eval:",
"/",
"i",
")",
"===",
"0",
")",
"{",
"// try to evaluate it",
"match",
"=",
"value",
".",
"split",
"(",
"/",
"^eval:",
"/",
"i",
")",
"[",
"1",
"]",
";",
"try",
"{",
"// eslint-disable-next-line",
"value",
"=",
"eval",
"(",
"match",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Unable to evaluate: \"",
"+",
"match",
")",
";",
"}",
"}",
"else",
"if",
"(",
"(",
"match",
"=",
"value",
".",
"match",
"(",
"/",
"^#([\\da-fA-F])([\\da-fA-F]{3})$",
"/",
")",
")",
"||",
"(",
"match",
"=",
"value",
".",
"match",
"(",
"/",
"^#([\\da-fA-F]{2})([\\da-fA-F]{6})$",
"/",
")",
")",
")",
"{",
"value",
"=",
"\"#\"",
"+",
"match",
"[",
"2",
"]",
"+",
"match",
"[",
"1",
"]",
";",
"}",
"// normalize values",
"if",
"(",
"name",
".",
"search",
"(",
"/",
"^(ratio|anchorPoint)$",
"/",
")",
"===",
"0",
")",
"{",
"// convert number to vector",
"if",
"(",
"typeof",
"value",
"===",
"\"number\"",
")",
"{",
"value",
"=",
"{",
"\"x\"",
":",
"value",
",",
"\"y\"",
":",
"value",
"}",
";",
"}",
"}",
"}",
"// return the interpreted value",
"return",
"value",
";",
"}"
] | set and interpret a TMX property value
@ignore | [
"set",
"and",
"interpret",
"a",
"TMX",
"property",
"value"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L26755-L26819 |
7,353 | melonjs/melonJS | dist/melonjs.js | parseTMXShapes | function parseTMXShapes() {
var i = 0;
var shapes = []; // add an ellipse shape
if (this.isEllipse === true) {
// ellipse coordinates are the center position, so set default to the corresonding radius
shapes.push(new me.Ellipse(this.width / 2, this.height / 2, this.width, this.height).rotate(this.rotation));
} // add a polygon
else if (this.isPolygon === true) {
shapes.push(new me.Polygon(0, 0, this.points).rotate(this.rotation));
} // add a polyline
else if (this.isPolyLine === true) {
var p = this.points;
var p1, p2;
var segments = p.length - 1;
for (i = 0; i < segments; i++) {
// clone the value before, as [i + 1]
// is reused later by the next segment
p1 = new me.Vector2d(p[i].x, p[i].y);
p2 = new me.Vector2d(p[i + 1].x, p[i + 1].y);
if (this.rotation !== 0) {
p1 = p1.rotate(this.rotation);
p2 = p2.rotate(this.rotation);
}
shapes.push(new me.Line(0, 0, [p1, p2]));
}
} // it's a rectangle, returns a polygon object anyway
else {
shapes.push(new me.Polygon(0, 0, [new me.Vector2d(), new me.Vector2d(this.width, 0), new me.Vector2d(this.width, this.height), new me.Vector2d(0, this.height)]).rotate(this.rotation));
} // Apply isometric projection
if (this.orientation === "isometric") {
for (i = 0; i < shapes.length; i++) {
shapes[i].toIso();
}
}
return shapes;
} | javascript | function parseTMXShapes() {
var i = 0;
var shapes = []; // add an ellipse shape
if (this.isEllipse === true) {
// ellipse coordinates are the center position, so set default to the corresonding radius
shapes.push(new me.Ellipse(this.width / 2, this.height / 2, this.width, this.height).rotate(this.rotation));
} // add a polygon
else if (this.isPolygon === true) {
shapes.push(new me.Polygon(0, 0, this.points).rotate(this.rotation));
} // add a polyline
else if (this.isPolyLine === true) {
var p = this.points;
var p1, p2;
var segments = p.length - 1;
for (i = 0; i < segments; i++) {
// clone the value before, as [i + 1]
// is reused later by the next segment
p1 = new me.Vector2d(p[i].x, p[i].y);
p2 = new me.Vector2d(p[i + 1].x, p[i + 1].y);
if (this.rotation !== 0) {
p1 = p1.rotate(this.rotation);
p2 = p2.rotate(this.rotation);
}
shapes.push(new me.Line(0, 0, [p1, p2]));
}
} // it's a rectangle, returns a polygon object anyway
else {
shapes.push(new me.Polygon(0, 0, [new me.Vector2d(), new me.Vector2d(this.width, 0), new me.Vector2d(this.width, this.height), new me.Vector2d(0, this.height)]).rotate(this.rotation));
} // Apply isometric projection
if (this.orientation === "isometric") {
for (i = 0; i < shapes.length; i++) {
shapes[i].toIso();
}
}
return shapes;
} | [
"function",
"parseTMXShapes",
"(",
")",
"{",
"var",
"i",
"=",
"0",
";",
"var",
"shapes",
"=",
"[",
"]",
";",
"// add an ellipse shape",
"if",
"(",
"this",
".",
"isEllipse",
"===",
"true",
")",
"{",
"// ellipse coordinates are the center position, so set default to the corresonding radius",
"shapes",
".",
"push",
"(",
"new",
"me",
".",
"Ellipse",
"(",
"this",
".",
"width",
"/",
"2",
",",
"this",
".",
"height",
"/",
"2",
",",
"this",
".",
"width",
",",
"this",
".",
"height",
")",
".",
"rotate",
"(",
"this",
".",
"rotation",
")",
")",
";",
"}",
"// add a polygon",
"else",
"if",
"(",
"this",
".",
"isPolygon",
"===",
"true",
")",
"{",
"shapes",
".",
"push",
"(",
"new",
"me",
".",
"Polygon",
"(",
"0",
",",
"0",
",",
"this",
".",
"points",
")",
".",
"rotate",
"(",
"this",
".",
"rotation",
")",
")",
";",
"}",
"// add a polyline",
"else",
"if",
"(",
"this",
".",
"isPolyLine",
"===",
"true",
")",
"{",
"var",
"p",
"=",
"this",
".",
"points",
";",
"var",
"p1",
",",
"p2",
";",
"var",
"segments",
"=",
"p",
".",
"length",
"-",
"1",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"segments",
";",
"i",
"++",
")",
"{",
"// clone the value before, as [i + 1]",
"// is reused later by the next segment",
"p1",
"=",
"new",
"me",
".",
"Vector2d",
"(",
"p",
"[",
"i",
"]",
".",
"x",
",",
"p",
"[",
"i",
"]",
".",
"y",
")",
";",
"p2",
"=",
"new",
"me",
".",
"Vector2d",
"(",
"p",
"[",
"i",
"+",
"1",
"]",
".",
"x",
",",
"p",
"[",
"i",
"+",
"1",
"]",
".",
"y",
")",
";",
"if",
"(",
"this",
".",
"rotation",
"!==",
"0",
")",
"{",
"p1",
"=",
"p1",
".",
"rotate",
"(",
"this",
".",
"rotation",
")",
";",
"p2",
"=",
"p2",
".",
"rotate",
"(",
"this",
".",
"rotation",
")",
";",
"}",
"shapes",
".",
"push",
"(",
"new",
"me",
".",
"Line",
"(",
"0",
",",
"0",
",",
"[",
"p1",
",",
"p2",
"]",
")",
")",
";",
"}",
"}",
"// it's a rectangle, returns a polygon object anyway",
"else",
"{",
"shapes",
".",
"push",
"(",
"new",
"me",
".",
"Polygon",
"(",
"0",
",",
"0",
",",
"[",
"new",
"me",
".",
"Vector2d",
"(",
")",
",",
"new",
"me",
".",
"Vector2d",
"(",
"this",
".",
"width",
",",
"0",
")",
",",
"new",
"me",
".",
"Vector2d",
"(",
"this",
".",
"width",
",",
"this",
".",
"height",
")",
",",
"new",
"me",
".",
"Vector2d",
"(",
"0",
",",
"this",
".",
"height",
")",
"]",
")",
".",
"rotate",
"(",
"this",
".",
"rotation",
")",
")",
";",
"}",
"// Apply isometric projection",
"if",
"(",
"this",
".",
"orientation",
"===",
"\"isometric\"",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"shapes",
".",
"length",
";",
"i",
"++",
")",
"{",
"shapes",
"[",
"i",
"]",
".",
"toIso",
"(",
")",
";",
"}",
"}",
"return",
"shapes",
";",
"}"
] | parses the TMX shape definition and returns a corresponding array of me.Shape object
@name parseTMXShapes
@memberOf me.TMXObject
@private
@function
@return {me.Polygon[]|me.Line[]|me.Ellipse[]} an array of shape objects | [
"parses",
"the",
"TMX",
"shape",
"definition",
"and",
"returns",
"a",
"corresponding",
"array",
"of",
"me",
".",
"Shape",
"object"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L27477-L27519 |
7,354 | melonjs/melonJS | dist/melonjs.js | createTransform | function createTransform() {
if (this.currentTransform === null) {
this.currentTransform = new me.Matrix2d();
} else {
// reset the matrix
this.currentTransform.identity();
}
if (this.flippedAD) {
// Use shearing to swap the X/Y axis
this.currentTransform.setTransform(0, 1, 0, 1, 0, 0, 0, 0, 1);
this.currentTransform.translate(0, this.height - this.width);
}
if (this.flippedX) {
this.currentTransform.translate(this.flippedAD ? 0 : this.width, this.flippedAD ? this.height : 0);
this.currentTransform.scaleX(-1);
}
if (this.flippedY) {
this.currentTransform.translate(this.flippedAD ? this.width : 0, this.flippedAD ? 0 : this.height);
this.currentTransform.scaleY(-1);
}
} | javascript | function createTransform() {
if (this.currentTransform === null) {
this.currentTransform = new me.Matrix2d();
} else {
// reset the matrix
this.currentTransform.identity();
}
if (this.flippedAD) {
// Use shearing to swap the X/Y axis
this.currentTransform.setTransform(0, 1, 0, 1, 0, 0, 0, 0, 1);
this.currentTransform.translate(0, this.height - this.width);
}
if (this.flippedX) {
this.currentTransform.translate(this.flippedAD ? 0 : this.width, this.flippedAD ? this.height : 0);
this.currentTransform.scaleX(-1);
}
if (this.flippedY) {
this.currentTransform.translate(this.flippedAD ? this.width : 0, this.flippedAD ? 0 : this.height);
this.currentTransform.scaleY(-1);
}
} | [
"function",
"createTransform",
"(",
")",
"{",
"if",
"(",
"this",
".",
"currentTransform",
"===",
"null",
")",
"{",
"this",
".",
"currentTransform",
"=",
"new",
"me",
".",
"Matrix2d",
"(",
")",
";",
"}",
"else",
"{",
"// reset the matrix",
"this",
".",
"currentTransform",
".",
"identity",
"(",
")",
";",
"}",
"if",
"(",
"this",
".",
"flippedAD",
")",
"{",
"// Use shearing to swap the X/Y axis",
"this",
".",
"currentTransform",
".",
"setTransform",
"(",
"0",
",",
"1",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"1",
")",
";",
"this",
".",
"currentTransform",
".",
"translate",
"(",
"0",
",",
"this",
".",
"height",
"-",
"this",
".",
"width",
")",
";",
"}",
"if",
"(",
"this",
".",
"flippedX",
")",
"{",
"this",
".",
"currentTransform",
".",
"translate",
"(",
"this",
".",
"flippedAD",
"?",
"0",
":",
"this",
".",
"width",
",",
"this",
".",
"flippedAD",
"?",
"this",
".",
"height",
":",
"0",
")",
";",
"this",
".",
"currentTransform",
".",
"scaleX",
"(",
"-",
"1",
")",
";",
"}",
"if",
"(",
"this",
".",
"flippedY",
")",
"{",
"this",
".",
"currentTransform",
".",
"translate",
"(",
"this",
".",
"flippedAD",
"?",
"this",
".",
"width",
":",
"0",
",",
"this",
".",
"flippedAD",
"?",
"0",
":",
"this",
".",
"height",
")",
";",
"this",
".",
"currentTransform",
".",
"scaleY",
"(",
"-",
"1",
")",
";",
"}",
"}"
] | create a transformation matrix for this tile
@ignore | [
"create",
"a",
"transformation",
"matrix",
"for",
"this",
"tile"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L27637-L27660 |
7,355 | melonjs/melonJS | dist/melonjs.js | getRenderable | function getRenderable(settings) {
var renderable;
var tileset = this.tileset;
if (tileset.animations.has(this.tileId)) {
var frames = [];
var frameId = [];
tileset.animations.get(this.tileId).frames.forEach(function (frame) {
frameId.push(frame.tileid);
frames.push({
name: "" + frame.tileid,
delay: frame.duration
});
});
renderable = tileset.texture.createAnimationFromName(frameId, settings);
renderable.addAnimation(this.tileId - tileset.firstgid, frames);
renderable.setCurrentAnimation(this.tileId - tileset.firstgid);
} else {
if (tileset.isCollection === true) {
var image = tileset.getTileImage(this.tileId);
renderable = new me.Sprite(0, 0, Object.assign({
image: image
}) //, settings)
);
renderable.anchorPoint.set(0, 0);
renderable.scale(settings.width / this.width, settings.height / this.height);
if (typeof settings.rotation !== "undefined") {
renderable.anchorPoint.set(0.5, 0.5);
renderable.currentTransform.rotate(settings.rotation);
renderable.currentTransform.translate(settings.width / 2, settings.height / 2); // TODO : move the rotation related code from TMXTiledMap to here (under)
settings.rotation = undefined;
}
} else {
renderable = tileset.texture.createSpriteFromName(this.tileId - tileset.firstgid, settings);
}
} // any H/V flipping to apply?
if (this.flippedX) {
renderable.currentTransform.scaleX(-1);
}
if (this.flippedY) {
renderable.currentTransform.scaleY(-1);
}
return renderable;
} | javascript | function getRenderable(settings) {
var renderable;
var tileset = this.tileset;
if (tileset.animations.has(this.tileId)) {
var frames = [];
var frameId = [];
tileset.animations.get(this.tileId).frames.forEach(function (frame) {
frameId.push(frame.tileid);
frames.push({
name: "" + frame.tileid,
delay: frame.duration
});
});
renderable = tileset.texture.createAnimationFromName(frameId, settings);
renderable.addAnimation(this.tileId - tileset.firstgid, frames);
renderable.setCurrentAnimation(this.tileId - tileset.firstgid);
} else {
if (tileset.isCollection === true) {
var image = tileset.getTileImage(this.tileId);
renderable = new me.Sprite(0, 0, Object.assign({
image: image
}) //, settings)
);
renderable.anchorPoint.set(0, 0);
renderable.scale(settings.width / this.width, settings.height / this.height);
if (typeof settings.rotation !== "undefined") {
renderable.anchorPoint.set(0.5, 0.5);
renderable.currentTransform.rotate(settings.rotation);
renderable.currentTransform.translate(settings.width / 2, settings.height / 2); // TODO : move the rotation related code from TMXTiledMap to here (under)
settings.rotation = undefined;
}
} else {
renderable = tileset.texture.createSpriteFromName(this.tileId - tileset.firstgid, settings);
}
} // any H/V flipping to apply?
if (this.flippedX) {
renderable.currentTransform.scaleX(-1);
}
if (this.flippedY) {
renderable.currentTransform.scaleY(-1);
}
return renderable;
} | [
"function",
"getRenderable",
"(",
"settings",
")",
"{",
"var",
"renderable",
";",
"var",
"tileset",
"=",
"this",
".",
"tileset",
";",
"if",
"(",
"tileset",
".",
"animations",
".",
"has",
"(",
"this",
".",
"tileId",
")",
")",
"{",
"var",
"frames",
"=",
"[",
"]",
";",
"var",
"frameId",
"=",
"[",
"]",
";",
"tileset",
".",
"animations",
".",
"get",
"(",
"this",
".",
"tileId",
")",
".",
"frames",
".",
"forEach",
"(",
"function",
"(",
"frame",
")",
"{",
"frameId",
".",
"push",
"(",
"frame",
".",
"tileid",
")",
";",
"frames",
".",
"push",
"(",
"{",
"name",
":",
"\"\"",
"+",
"frame",
".",
"tileid",
",",
"delay",
":",
"frame",
".",
"duration",
"}",
")",
";",
"}",
")",
";",
"renderable",
"=",
"tileset",
".",
"texture",
".",
"createAnimationFromName",
"(",
"frameId",
",",
"settings",
")",
";",
"renderable",
".",
"addAnimation",
"(",
"this",
".",
"tileId",
"-",
"tileset",
".",
"firstgid",
",",
"frames",
")",
";",
"renderable",
".",
"setCurrentAnimation",
"(",
"this",
".",
"tileId",
"-",
"tileset",
".",
"firstgid",
")",
";",
"}",
"else",
"{",
"if",
"(",
"tileset",
".",
"isCollection",
"===",
"true",
")",
"{",
"var",
"image",
"=",
"tileset",
".",
"getTileImage",
"(",
"this",
".",
"tileId",
")",
";",
"renderable",
"=",
"new",
"me",
".",
"Sprite",
"(",
"0",
",",
"0",
",",
"Object",
".",
"assign",
"(",
"{",
"image",
":",
"image",
"}",
")",
"//, settings)",
")",
";",
"renderable",
".",
"anchorPoint",
".",
"set",
"(",
"0",
",",
"0",
")",
";",
"renderable",
".",
"scale",
"(",
"settings",
".",
"width",
"/",
"this",
".",
"width",
",",
"settings",
".",
"height",
"/",
"this",
".",
"height",
")",
";",
"if",
"(",
"typeof",
"settings",
".",
"rotation",
"!==",
"\"undefined\"",
")",
"{",
"renderable",
".",
"anchorPoint",
".",
"set",
"(",
"0.5",
",",
"0.5",
")",
";",
"renderable",
".",
"currentTransform",
".",
"rotate",
"(",
"settings",
".",
"rotation",
")",
";",
"renderable",
".",
"currentTransform",
".",
"translate",
"(",
"settings",
".",
"width",
"/",
"2",
",",
"settings",
".",
"height",
"/",
"2",
")",
";",
"// TODO : move the rotation related code from TMXTiledMap to here (under)",
"settings",
".",
"rotation",
"=",
"undefined",
";",
"}",
"}",
"else",
"{",
"renderable",
"=",
"tileset",
".",
"texture",
".",
"createSpriteFromName",
"(",
"this",
".",
"tileId",
"-",
"tileset",
".",
"firstgid",
",",
"settings",
")",
";",
"}",
"}",
"// any H/V flipping to apply?",
"if",
"(",
"this",
".",
"flippedX",
")",
"{",
"renderable",
".",
"currentTransform",
".",
"scaleX",
"(",
"-",
"1",
")",
";",
"}",
"if",
"(",
"this",
".",
"flippedY",
")",
"{",
"renderable",
".",
"currentTransform",
".",
"scaleY",
"(",
"-",
"1",
")",
";",
"}",
"return",
"renderable",
";",
"}"
] | return a renderable object for this Tile object
@name me.Tile#getRenderable
@public
@function
@param {Object} [settings] see {@link me.Sprite}
@return {me.Renderable} a me.Sprite object | [
"return",
"a",
"renderable",
"object",
"for",
"this",
"Tile",
"object"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L27670-L27719 |
7,356 | melonjs/melonJS | dist/melonjs.js | update | function update(dt) {
var duration = 0,
now = me.timer.getTime(),
result = false;
if (this._lastUpdate !== now) {
this._lastUpdate = now;
this.animations.forEach(function (anim) {
anim.dt += dt;
duration = anim.cur.duration;
while (anim.dt >= duration) {
anim.dt -= duration;
anim.idx = (anim.idx + 1) % anim.frames.length;
anim.cur = anim.frames[anim.idx];
duration = anim.cur.duration;
result = true;
}
});
}
return result;
} | javascript | function update(dt) {
var duration = 0,
now = me.timer.getTime(),
result = false;
if (this._lastUpdate !== now) {
this._lastUpdate = now;
this.animations.forEach(function (anim) {
anim.dt += dt;
duration = anim.cur.duration;
while (anim.dt >= duration) {
anim.dt -= duration;
anim.idx = (anim.idx + 1) % anim.frames.length;
anim.cur = anim.frames[anim.idx];
duration = anim.cur.duration;
result = true;
}
});
}
return result;
} | [
"function",
"update",
"(",
"dt",
")",
"{",
"var",
"duration",
"=",
"0",
",",
"now",
"=",
"me",
".",
"timer",
".",
"getTime",
"(",
")",
",",
"result",
"=",
"false",
";",
"if",
"(",
"this",
".",
"_lastUpdate",
"!==",
"now",
")",
"{",
"this",
".",
"_lastUpdate",
"=",
"now",
";",
"this",
".",
"animations",
".",
"forEach",
"(",
"function",
"(",
"anim",
")",
"{",
"anim",
".",
"dt",
"+=",
"dt",
";",
"duration",
"=",
"anim",
".",
"cur",
".",
"duration",
";",
"while",
"(",
"anim",
".",
"dt",
">=",
"duration",
")",
"{",
"anim",
".",
"dt",
"-=",
"duration",
";",
"anim",
".",
"idx",
"=",
"(",
"anim",
".",
"idx",
"+",
"1",
")",
"%",
"anim",
".",
"frames",
".",
"length",
";",
"anim",
".",
"cur",
"=",
"anim",
".",
"frames",
"[",
"anim",
".",
"idx",
"]",
";",
"duration",
"=",
"anim",
".",
"cur",
".",
"duration",
";",
"result",
"=",
"true",
";",
"}",
"}",
")",
";",
"}",
"return",
"result",
";",
"}"
] | update tile animations | [
"update",
"tile",
"animations"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L27947-L27969 |
7,357 | melonjs/melonJS | dist/melonjs.js | canRender | function canRender(component) {
return this.cols === component.cols && this.rows === component.rows && this.tilewidth === component.tilewidth && this.tileheight === component.tileheight;
} | javascript | function canRender(component) {
return this.cols === component.cols && this.rows === component.rows && this.tilewidth === component.tilewidth && this.tileheight === component.tileheight;
} | [
"function",
"canRender",
"(",
"component",
")",
"{",
"return",
"this",
".",
"cols",
"===",
"component",
".",
"cols",
"&&",
"this",
".",
"rows",
"===",
"component",
".",
"rows",
"&&",
"this",
".",
"tilewidth",
"===",
"component",
".",
"tilewidth",
"&&",
"this",
".",
"tileheight",
"===",
"component",
".",
"tileheight",
";",
"}"
] | return true if the renderer can render the specified layer
@name me.TMXRenderer#canRender
@public
@function
@param {me.TMXTileMap|me.TMXLayer} component TMX Map or Layer
@return {boolean} | [
"return",
"true",
"if",
"the",
"renderer",
"can",
"render",
"the",
"specified",
"layer"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L28134-L28136 |
7,358 | melonjs/melonJS | dist/melonjs.js | initArray | function initArray(layer) {
// initialize the array
layer.layerData = new Array(layer.cols);
for (var x = 0; x < layer.cols; x++) {
layer.layerData[x] = new Array(layer.rows);
for (var y = 0; y < layer.rows; y++) {
layer.layerData[x][y] = null;
}
}
} | javascript | function initArray(layer) {
// initialize the array
layer.layerData = new Array(layer.cols);
for (var x = 0; x < layer.cols; x++) {
layer.layerData[x] = new Array(layer.rows);
for (var y = 0; y < layer.rows; y++) {
layer.layerData[x][y] = null;
}
}
} | [
"function",
"initArray",
"(",
"layer",
")",
"{",
"// initialize the array",
"layer",
".",
"layerData",
"=",
"new",
"Array",
"(",
"layer",
".",
"cols",
")",
";",
"for",
"(",
"var",
"x",
"=",
"0",
";",
"x",
"<",
"layer",
".",
"cols",
";",
"x",
"++",
")",
"{",
"layer",
".",
"layerData",
"[",
"x",
"]",
"=",
"new",
"Array",
"(",
"layer",
".",
"rows",
")",
";",
"for",
"(",
"var",
"y",
"=",
"0",
";",
"y",
"<",
"layer",
".",
"rows",
";",
"y",
"++",
")",
"{",
"layer",
".",
"layerData",
"[",
"x",
"]",
"[",
"y",
"]",
"=",
"null",
";",
"}",
"}",
"}"
] | Create required arrays for the given layer object
@ignore | [
"Create",
"required",
"arrays",
"for",
"the",
"given",
"layer",
"object"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L28680-L28691 |
7,359 | melonjs/melonJS | dist/melonjs.js | setLayerData | function setLayerData(layer, data) {
var idx = 0; // initialize the array
initArray(layer); // set everything
for (var y = 0; y < layer.rows; y++) {
for (var x = 0; x < layer.cols; x++) {
// get the value of the gid
var gid = data[idx++]; // fill the array
if (gid !== 0) {
// add a new tile to the layer
layer.setTile(x, y, gid);
}
}
}
} | javascript | function setLayerData(layer, data) {
var idx = 0; // initialize the array
initArray(layer); // set everything
for (var y = 0; y < layer.rows; y++) {
for (var x = 0; x < layer.cols; x++) {
// get the value of the gid
var gid = data[idx++]; // fill the array
if (gid !== 0) {
// add a new tile to the layer
layer.setTile(x, y, gid);
}
}
}
} | [
"function",
"setLayerData",
"(",
"layer",
",",
"data",
")",
"{",
"var",
"idx",
"=",
"0",
";",
"// initialize the array",
"initArray",
"(",
"layer",
")",
";",
"// set everything",
"for",
"(",
"var",
"y",
"=",
"0",
";",
"y",
"<",
"layer",
".",
"rows",
";",
"y",
"++",
")",
"{",
"for",
"(",
"var",
"x",
"=",
"0",
";",
"x",
"<",
"layer",
".",
"cols",
";",
"x",
"++",
")",
"{",
"// get the value of the gid",
"var",
"gid",
"=",
"data",
"[",
"idx",
"++",
"]",
";",
"// fill the array",
"if",
"(",
"gid",
"!==",
"0",
")",
"{",
"// add a new tile to the layer",
"layer",
".",
"setTile",
"(",
"x",
",",
"y",
",",
"gid",
")",
";",
"}",
"}",
"}",
"}"
] | Set a tiled layer Data
@ignore | [
"Set",
"a",
"tiled",
"layer",
"Data"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L28698-L28714 |
7,360 | melonjs/melonJS | dist/melonjs.js | getTileId | function getTileId(x, y) {
var tile = this.getTile(x, y);
return tile ? tile.tileId : null;
} | javascript | function getTileId(x, y) {
var tile = this.getTile(x, y);
return tile ? tile.tileId : null;
} | [
"function",
"getTileId",
"(",
"x",
",",
"y",
")",
"{",
"var",
"tile",
"=",
"this",
".",
"getTile",
"(",
"x",
",",
"y",
")",
";",
"return",
"tile",
"?",
"tile",
".",
"tileId",
":",
"null",
";",
"}"
] | Return the TileId of the Tile at the specified position
@name getTileId
@memberOf me.TMXLayer
@public
@function
@param {Number} x X coordinate (in world/pixels coordinates)
@param {Number} y Y coordinate (in world/pixels coordinates)
@return {Number} TileId or null if there is no Tile at the given position | [
"Return",
"the",
"TileId",
"of",
"the",
"Tile",
"at",
"the",
"specified",
"position"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L28900-L28903 |
7,361 | melonjs/melonJS | dist/melonjs.js | setTile | function setTile(x, y, tileId) {
if (!this.tileset.contains(tileId)) {
// look for the corresponding tileset
this.tileset = this.tilesets.getTilesetByGid(tileId);
}
var tile = this.layerData[x][y] = new me.Tile(x, y, tileId, this.tileset); // draw the corresponding tile
if (this.preRender) {
this.renderer.drawTile(this.canvasRenderer, x, y, tile);
}
return tile;
} | javascript | function setTile(x, y, tileId) {
if (!this.tileset.contains(tileId)) {
// look for the corresponding tileset
this.tileset = this.tilesets.getTilesetByGid(tileId);
}
var tile = this.layerData[x][y] = new me.Tile(x, y, tileId, this.tileset); // draw the corresponding tile
if (this.preRender) {
this.renderer.drawTile(this.canvasRenderer, x, y, tile);
}
return tile;
} | [
"function",
"setTile",
"(",
"x",
",",
"y",
",",
"tileId",
")",
"{",
"if",
"(",
"!",
"this",
".",
"tileset",
".",
"contains",
"(",
"tileId",
")",
")",
"{",
"// look for the corresponding tileset",
"this",
".",
"tileset",
"=",
"this",
".",
"tilesets",
".",
"getTilesetByGid",
"(",
"tileId",
")",
";",
"}",
"var",
"tile",
"=",
"this",
".",
"layerData",
"[",
"x",
"]",
"[",
"y",
"]",
"=",
"new",
"me",
".",
"Tile",
"(",
"x",
",",
"y",
",",
"tileId",
",",
"this",
".",
"tileset",
")",
";",
"// draw the corresponding tile",
"if",
"(",
"this",
".",
"preRender",
")",
"{",
"this",
".",
"renderer",
".",
"drawTile",
"(",
"this",
".",
"canvasRenderer",
",",
"x",
",",
"y",
",",
"tile",
")",
";",
"}",
"return",
"tile",
";",
"}"
] | Create a new Tile at the specified position
@name setTile
@memberOf me.TMXLayer
@public
@function
@param {Number} x X coordinate (in map coordinates: row/column)
@param {Number} y Y coordinate (in map coordinates: row/column)
@param {Number} tileId tileId
@return {me.Tile} the corresponding newly created tile object | [
"Create",
"a",
"new",
"Tile",
"at",
"the",
"specified",
"position"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L28947-L28960 |
7,362 | melonjs/melonJS | dist/melonjs.js | getRenderer | function getRenderer(layer) {
// first ensure a renderer is associated to this map
if (typeof this.renderer === "undefined" || !this.renderer.canRender(this)) {
this.renderer = getNewDefaultRenderer(this);
} // return a renderer for the given layer (if any)
if (typeof layer !== "undefined" && !this.renderer.canRender(layer)) {
return getNewDefaultRenderer(layer);
} // else return this renderer
return this.renderer;
} | javascript | function getRenderer(layer) {
// first ensure a renderer is associated to this map
if (typeof this.renderer === "undefined" || !this.renderer.canRender(this)) {
this.renderer = getNewDefaultRenderer(this);
} // return a renderer for the given layer (if any)
if (typeof layer !== "undefined" && !this.renderer.canRender(layer)) {
return getNewDefaultRenderer(layer);
} // else return this renderer
return this.renderer;
} | [
"function",
"getRenderer",
"(",
"layer",
")",
"{",
"// first ensure a renderer is associated to this map",
"if",
"(",
"typeof",
"this",
".",
"renderer",
"===",
"\"undefined\"",
"||",
"!",
"this",
".",
"renderer",
".",
"canRender",
"(",
"this",
")",
")",
"{",
"this",
".",
"renderer",
"=",
"getNewDefaultRenderer",
"(",
"this",
")",
";",
"}",
"// return a renderer for the given layer (if any)",
"if",
"(",
"typeof",
"layer",
"!==",
"\"undefined\"",
"&&",
"!",
"this",
".",
"renderer",
".",
"canRender",
"(",
"layer",
")",
")",
"{",
"return",
"getNewDefaultRenderer",
"(",
"layer",
")",
";",
"}",
"// else return this renderer",
"return",
"this",
".",
"renderer",
";",
"}"
] | Return the map default renderer
@name getRenderer
@memberOf me.TMXTileMap
@public
@function
@param {me.TMXLayer} [layer] a layer object
@return {me.TMXRenderer} a TMX renderer | [
"Return",
"the",
"map",
"default",
"renderer"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L29263-L29276 |
7,363 | melonjs/melonJS | dist/melonjs.js | initEvents | function initEvents() {
var self = this;
/**
* @ignore
*/
this.mouseDown = function (e) {
this.translatePointerEvent(e, Event.DRAGSTART);
};
/**
* @ignore
*/
this.mouseUp = function (e) {
this.translatePointerEvent(e, Event.DRAGEND);
};
this.onPointerEvent("pointerdown", this, this.mouseDown.bind(this));
this.onPointerEvent("pointerup", this, this.mouseUp.bind(this));
this.onPointerEvent("pointercancel", this, this.mouseUp.bind(this));
Event.subscribe(Event.POINTERMOVE, this.dragMove.bind(this));
Event.subscribe(Event.DRAGSTART, function (e, draggable) {
if (draggable === self) {
self.dragStart(e);
}
});
Event.subscribe(Event.DRAGEND, function (e, draggable) {
if (draggable === self) {
self.dragEnd(e);
}
});
} | javascript | function initEvents() {
var self = this;
/**
* @ignore
*/
this.mouseDown = function (e) {
this.translatePointerEvent(e, Event.DRAGSTART);
};
/**
* @ignore
*/
this.mouseUp = function (e) {
this.translatePointerEvent(e, Event.DRAGEND);
};
this.onPointerEvent("pointerdown", this, this.mouseDown.bind(this));
this.onPointerEvent("pointerup", this, this.mouseUp.bind(this));
this.onPointerEvent("pointercancel", this, this.mouseUp.bind(this));
Event.subscribe(Event.POINTERMOVE, this.dragMove.bind(this));
Event.subscribe(Event.DRAGSTART, function (e, draggable) {
if (draggable === self) {
self.dragStart(e);
}
});
Event.subscribe(Event.DRAGEND, function (e, draggable) {
if (draggable === self) {
self.dragEnd(e);
}
});
} | [
"function",
"initEvents",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"/**\n * @ignore\n */",
"this",
".",
"mouseDown",
"=",
"function",
"(",
"e",
")",
"{",
"this",
".",
"translatePointerEvent",
"(",
"e",
",",
"Event",
".",
"DRAGSTART",
")",
";",
"}",
";",
"/**\n * @ignore\n */",
"this",
".",
"mouseUp",
"=",
"function",
"(",
"e",
")",
"{",
"this",
".",
"translatePointerEvent",
"(",
"e",
",",
"Event",
".",
"DRAGEND",
")",
";",
"}",
";",
"this",
".",
"onPointerEvent",
"(",
"\"pointerdown\"",
",",
"this",
",",
"this",
".",
"mouseDown",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"onPointerEvent",
"(",
"\"pointerup\"",
",",
"this",
",",
"this",
".",
"mouseUp",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"onPointerEvent",
"(",
"\"pointercancel\"",
",",
"this",
",",
"this",
".",
"mouseUp",
".",
"bind",
"(",
"this",
")",
")",
";",
"Event",
".",
"subscribe",
"(",
"Event",
".",
"POINTERMOVE",
",",
"this",
".",
"dragMove",
".",
"bind",
"(",
"this",
")",
")",
";",
"Event",
".",
"subscribe",
"(",
"Event",
".",
"DRAGSTART",
",",
"function",
"(",
"e",
",",
"draggable",
")",
"{",
"if",
"(",
"draggable",
"===",
"self",
")",
"{",
"self",
".",
"dragStart",
"(",
"e",
")",
";",
"}",
"}",
")",
";",
"Event",
".",
"subscribe",
"(",
"Event",
".",
"DRAGEND",
",",
"function",
"(",
"e",
",",
"draggable",
")",
"{",
"if",
"(",
"draggable",
"===",
"self",
")",
"{",
"self",
".",
"dragEnd",
"(",
"e",
")",
";",
"}",
"}",
")",
";",
"}"
] | Initializes the events the modules needs to listen to
It translates the pointer events to me.events
in order to make them pass through the system and to make
this module testable. Then we subscribe this module to the
transformed events.
@name initEvents
@memberOf me.DraggableEntity
@function | [
"Initializes",
"the",
"events",
"the",
"modules",
"needs",
"to",
"listen",
"to",
"It",
"translates",
"the",
"pointer",
"events",
"to",
"me",
".",
"events",
"in",
"order",
"to",
"make",
"them",
"pass",
"through",
"the",
"system",
"and",
"to",
"make",
"this",
"module",
"testable",
".",
"Then",
"we",
"subscribe",
"this",
"module",
"to",
"the",
"transformed",
"events",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L30825-L30857 |
7,364 | melonjs/melonJS | dist/melonjs.js | goTo | function goTo(level) {
this.gotolevel = level || this.nextlevel; // load a level
//console.log("going to : ", to);
if (this.fade && this.duration) {
if (!this.fading) {
this.fading = true;
me.game.viewport.fadeIn(this.fade, this.duration, this.onFadeComplete.bind(this));
}
} else {
me.levelDirector.loadLevel(this.gotolevel, this.getlevelSettings());
}
} | javascript | function goTo(level) {
this.gotolevel = level || this.nextlevel; // load a level
//console.log("going to : ", to);
if (this.fade && this.duration) {
if (!this.fading) {
this.fading = true;
me.game.viewport.fadeIn(this.fade, this.duration, this.onFadeComplete.bind(this));
}
} else {
me.levelDirector.loadLevel(this.gotolevel, this.getlevelSettings());
}
} | [
"function",
"goTo",
"(",
"level",
")",
"{",
"this",
".",
"gotolevel",
"=",
"level",
"||",
"this",
".",
"nextlevel",
";",
"// load a level",
"//console.log(\"going to : \", to);",
"if",
"(",
"this",
".",
"fade",
"&&",
"this",
".",
"duration",
")",
"{",
"if",
"(",
"!",
"this",
".",
"fading",
")",
"{",
"this",
".",
"fading",
"=",
"true",
";",
"me",
".",
"game",
".",
"viewport",
".",
"fadeIn",
"(",
"this",
".",
"fade",
",",
"this",
".",
"duration",
",",
"this",
".",
"onFadeComplete",
".",
"bind",
"(",
"this",
")",
")",
";",
"}",
"}",
"else",
"{",
"me",
".",
"levelDirector",
".",
"loadLevel",
"(",
"this",
".",
"gotolevel",
",",
"this",
".",
"getlevelSettings",
"(",
")",
")",
";",
"}",
"}"
] | go to the specified level
@name goTo
@memberOf me.LevelEntity
@function
@param {String} [level=this.nextlevel] name of the level to load
@protected | [
"go",
"to",
"the",
"specified",
"level"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L31141-L31153 |
7,365 | melonjs/melonJS | src/renderable/sprite.js | function (duration, callback) {
this._flicker.duration = duration;
if (this._flicker.duration <= 0) {
this._flicker.isFlickering = false;
this._flicker.callback = null;
}
else if (!this._flicker.isFlickering) {
this._flicker.callback = callback;
this._flicker.isFlickering = true;
}
return this;
} | javascript | function (duration, callback) {
this._flicker.duration = duration;
if (this._flicker.duration <= 0) {
this._flicker.isFlickering = false;
this._flicker.callback = null;
}
else if (!this._flicker.isFlickering) {
this._flicker.callback = callback;
this._flicker.isFlickering = true;
}
return this;
} | [
"function",
"(",
"duration",
",",
"callback",
")",
"{",
"this",
".",
"_flicker",
".",
"duration",
"=",
"duration",
";",
"if",
"(",
"this",
".",
"_flicker",
".",
"duration",
"<=",
"0",
")",
"{",
"this",
".",
"_flicker",
".",
"isFlickering",
"=",
"false",
";",
"this",
".",
"_flicker",
".",
"callback",
"=",
"null",
";",
"}",
"else",
"if",
"(",
"!",
"this",
".",
"_flicker",
".",
"isFlickering",
")",
"{",
"this",
".",
"_flicker",
".",
"callback",
"=",
"callback",
";",
"this",
".",
"_flicker",
".",
"isFlickering",
"=",
"true",
";",
"}",
"return",
"this",
";",
"}"
] | make the object flicker
@name flicker
@memberOf me.Sprite.prototype
@function
@param {Number} duration expressed in milliseconds
@param {Function} callback Function to call when flickering ends
@return {me.Sprite} Reference to this object for method chaining
@example
// make the object flicker for 1 second
// and then remove it
this.flicker(1000, function () {
me.game.world.removeChild(this);
}); | [
"make",
"the",
"object",
"flicker"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/renderable/sprite.js#L222-L233 |
|
7,366 | melonjs/melonJS | examples/UI/js/entities/buttons.js | function (/* event */) {
this.setRegion(this.unclicked_region);
// account for the different sprite size
this.pos.y -= this.unclicked_region.height - this.height;
this.height = this.unclicked_region.height;
// don't propagate the event
return false;
} | javascript | function (/* event */) {
this.setRegion(this.unclicked_region);
// account for the different sprite size
this.pos.y -= this.unclicked_region.height - this.height;
this.height = this.unclicked_region.height;
// don't propagate the event
return false;
} | [
"function",
"(",
"/* event */",
")",
"{",
"this",
".",
"setRegion",
"(",
"this",
".",
"unclicked_region",
")",
";",
"// account for the different sprite size",
"this",
".",
"pos",
".",
"y",
"-=",
"this",
".",
"unclicked_region",
".",
"height",
"-",
"this",
".",
"height",
";",
"this",
".",
"height",
"=",
"this",
".",
"unclicked_region",
".",
"height",
";",
"// don't propagate the event",
"return",
"false",
";",
"}"
] | function called when the pointer button is released | [
"function",
"called",
"when",
"the",
"pointer",
"button",
"is",
"released"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/examples/UI/js/entities/buttons.js#L70-L77 |
|
7,367 | melonjs/melonJS | examples/UI/js/entities/buttons.js | function (selected) {
if (selected) {
this.setRegion(this.on_icon_region);
this.isSelected = true;
} else {
this.setRegion(this.off_icon_region);
this.isSelected = false;
}
} | javascript | function (selected) {
if (selected) {
this.setRegion(this.on_icon_region);
this.isSelected = true;
} else {
this.setRegion(this.off_icon_region);
this.isSelected = false;
}
} | [
"function",
"(",
"selected",
")",
"{",
"if",
"(",
"selected",
")",
"{",
"this",
".",
"setRegion",
"(",
"this",
".",
"on_icon_region",
")",
";",
"this",
".",
"isSelected",
"=",
"true",
";",
"}",
"else",
"{",
"this",
".",
"setRegion",
"(",
"this",
".",
"off_icon_region",
")",
";",
"this",
".",
"isSelected",
"=",
"false",
";",
"}",
"}"
] | change the checkbox state | [
"change",
"the",
"checkbox",
"state"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/examples/UI/js/entities/buttons.js#L149-L157 |
|
7,368 | melonjs/melonJS | src/video/webgl/webgl_renderer.js | function (col, opaque) {
this.save();
this.resetTransform();
this.currentColor.copy(col);
if (opaque) {
this.compositor.clear();
}
else {
this.fillRect(0, 0, this.canvas.width, this.canvas.height);
}
this.restore();
} | javascript | function (col, opaque) {
this.save();
this.resetTransform();
this.currentColor.copy(col);
if (opaque) {
this.compositor.clear();
}
else {
this.fillRect(0, 0, this.canvas.width, this.canvas.height);
}
this.restore();
} | [
"function",
"(",
"col",
",",
"opaque",
")",
"{",
"this",
".",
"save",
"(",
")",
";",
"this",
".",
"resetTransform",
"(",
")",
";",
"this",
".",
"currentColor",
".",
"copy",
"(",
"col",
")",
";",
"if",
"(",
"opaque",
")",
"{",
"this",
".",
"compositor",
".",
"clear",
"(",
")",
";",
"}",
"else",
"{",
"this",
".",
"fillRect",
"(",
"0",
",",
"0",
",",
"this",
".",
"canvas",
".",
"width",
",",
"this",
".",
"canvas",
".",
"height",
")",
";",
"}",
"this",
".",
"restore",
"(",
")",
";",
"}"
] | Clears the gl context with the given color.
@name clearColor
@memberOf me.WebGLRenderer.prototype
@function
@param {me.Color|String} color CSS color.
@param {Boolean} [opaque=false] Allow transparency [default] or clear the surface completely [true] | [
"Clears",
"the",
"gl",
"context",
"with",
"the",
"given",
"color",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/webgl/webgl_renderer.js#L235-L246 |
|
7,369 | melonjs/melonJS | src/video/webgl/webgl_renderer.js | function (image, sx, sy, sw, sh, dx, dy, dw, dh) {
if (typeof sw === "undefined") {
sw = dw = image.width;
sh = dh = image.height;
dx = sx;
dy = sy;
sx = 0;
sy = 0;
}
else if (typeof dx === "undefined") {
dx = sx;
dy = sy;
dw = sw;
dh = sh;
sw = image.width;
sh = image.height;
sx = 0;
sy = 0;
}
if (this.settings.subPixel === false) {
// clamp to pixel grid
dx = ~~dx;
dy = ~~dy;
}
var key = sx + "," + sy + "," + sw + "," + sh;
this.compositor.addQuad(this.cache.get(image), key, dx, dy, dw, dh);
} | javascript | function (image, sx, sy, sw, sh, dx, dy, dw, dh) {
if (typeof sw === "undefined") {
sw = dw = image.width;
sh = dh = image.height;
dx = sx;
dy = sy;
sx = 0;
sy = 0;
}
else if (typeof dx === "undefined") {
dx = sx;
dy = sy;
dw = sw;
dh = sh;
sw = image.width;
sh = image.height;
sx = 0;
sy = 0;
}
if (this.settings.subPixel === false) {
// clamp to pixel grid
dx = ~~dx;
dy = ~~dy;
}
var key = sx + "," + sy + "," + sw + "," + sh;
this.compositor.addQuad(this.cache.get(image), key, dx, dy, dw, dh);
} | [
"function",
"(",
"image",
",",
"sx",
",",
"sy",
",",
"sw",
",",
"sh",
",",
"dx",
",",
"dy",
",",
"dw",
",",
"dh",
")",
"{",
"if",
"(",
"typeof",
"sw",
"===",
"\"undefined\"",
")",
"{",
"sw",
"=",
"dw",
"=",
"image",
".",
"width",
";",
"sh",
"=",
"dh",
"=",
"image",
".",
"height",
";",
"dx",
"=",
"sx",
";",
"dy",
"=",
"sy",
";",
"sx",
"=",
"0",
";",
"sy",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"typeof",
"dx",
"===",
"\"undefined\"",
")",
"{",
"dx",
"=",
"sx",
";",
"dy",
"=",
"sy",
";",
"dw",
"=",
"sw",
";",
"dh",
"=",
"sh",
";",
"sw",
"=",
"image",
".",
"width",
";",
"sh",
"=",
"image",
".",
"height",
";",
"sx",
"=",
"0",
";",
"sy",
"=",
"0",
";",
"}",
"if",
"(",
"this",
".",
"settings",
".",
"subPixel",
"===",
"false",
")",
"{",
"// clamp to pixel grid",
"dx",
"=",
"~",
"~",
"dx",
";",
"dy",
"=",
"~",
"~",
"dy",
";",
"}",
"var",
"key",
"=",
"sx",
"+",
"\",\"",
"+",
"sy",
"+",
"\",\"",
"+",
"sw",
"+",
"\",\"",
"+",
"sh",
";",
"this",
".",
"compositor",
".",
"addQuad",
"(",
"this",
".",
"cache",
".",
"get",
"(",
"image",
")",
",",
"key",
",",
"dx",
",",
"dy",
",",
"dw",
",",
"dh",
")",
";",
"}"
] | Draw an image to the gl context
@name drawImage
@memberOf me.WebGLRenderer.prototype
@function
@param {Image} image An element to draw into the context. The specification permits any canvas image source (CanvasImageSource), specifically, a CSSImageValue, an HTMLImageElement, an SVGImageElement, an HTMLVideoElement, an HTMLCanvasElement, an ImageBitmap, or an OffscreenCanvas.
@param {Number} sx The X coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
@param {Number} sy The Y coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
@param {Number} sw The width of the sub-rectangle of the source image to draw into the destination context. If not specified, the entire rectangle from the coordinates specified by sx and sy to the bottom-right corner of the image is used.
@param {Number} sh The height of the sub-rectangle of the source image to draw into the destination context.
@param {Number} dx The X coordinate in the destination canvas at which to place the top-left corner of the source image.
@param {Number} dy The Y coordinate in the destination canvas at which to place the top-left corner of the source image.
@param {Number} dWidth The width to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in width when drawn.
@param {Number} dHeight The height to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in height when drawn.
@example
// Position the image on the canvas:
renderer.drawImage(image, dx, dy);
// Position the image on the canvas, and specify width and height of the image:
renderer.drawImage(image, dx, dy, dWidth, dHeight);
// Clip the image and position the clipped part on the canvas:
renderer.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight); | [
"Draw",
"an",
"image",
"to",
"the",
"gl",
"context"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/webgl/webgl_renderer.js#L320-L348 |
|
7,370 | melonjs/melonJS | src/video/webgl/webgl_renderer.js | function (x, y, width, height) {
var points = this._glPoints;
points[0].x = x;
points[0].y = y;
points[1].x = x + width;
points[1].y = y;
points[2].x = x + width;
points[2].y = y + height;
points[3].x = x;
points[3].y = y + height;
this.compositor.drawLine(points, 4);
} | javascript | function (x, y, width, height) {
var points = this._glPoints;
points[0].x = x;
points[0].y = y;
points[1].x = x + width;
points[1].y = y;
points[2].x = x + width;
points[2].y = y + height;
points[3].x = x;
points[3].y = y + height;
this.compositor.drawLine(points, 4);
} | [
"function",
"(",
"x",
",",
"y",
",",
"width",
",",
"height",
")",
"{",
"var",
"points",
"=",
"this",
".",
"_glPoints",
";",
"points",
"[",
"0",
"]",
".",
"x",
"=",
"x",
";",
"points",
"[",
"0",
"]",
".",
"y",
"=",
"y",
";",
"points",
"[",
"1",
"]",
".",
"x",
"=",
"x",
"+",
"width",
";",
"points",
"[",
"1",
"]",
".",
"y",
"=",
"y",
";",
"points",
"[",
"2",
"]",
".",
"x",
"=",
"x",
"+",
"width",
";",
"points",
"[",
"2",
"]",
".",
"y",
"=",
"y",
"+",
"height",
";",
"points",
"[",
"3",
"]",
".",
"x",
"=",
"x",
";",
"points",
"[",
"3",
"]",
".",
"y",
"=",
"y",
"+",
"height",
";",
"this",
".",
"compositor",
".",
"drawLine",
"(",
"points",
",",
"4",
")",
";",
"}"
] | Draw a stroke rectangle at the specified coordinates
@name strokeRect
@memberOf me.WebGLRenderer.prototype
@function
@param {Number} x
@param {Number} y
@param {Number} width
@param {Number} height | [
"Draw",
"a",
"stroke",
"rectangle",
"at",
"the",
"specified",
"coordinates"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/webgl/webgl_renderer.js#L848-L859 |
|
7,371 | melonjs/melonJS | plugins/debug/debugPanel.js | function () {
if (!this.visible) {
// add the debug panel to the game world
me.game.world.addChild(this, Infinity);
// register a mouse event for the checkboxes
me.input.registerPointerEvent("pointerdown", this, this.onClick.bind(this));
// mark it as visible
this.visible = true;
// force repaint
me.game.repaint();
}
} | javascript | function () {
if (!this.visible) {
// add the debug panel to the game world
me.game.world.addChild(this, Infinity);
// register a mouse event for the checkboxes
me.input.registerPointerEvent("pointerdown", this, this.onClick.bind(this));
// mark it as visible
this.visible = true;
// force repaint
me.game.repaint();
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"visible",
")",
"{",
"// add the debug panel to the game world",
"me",
".",
"game",
".",
"world",
".",
"addChild",
"(",
"this",
",",
"Infinity",
")",
";",
"// register a mouse event for the checkboxes",
"me",
".",
"input",
".",
"registerPointerEvent",
"(",
"\"pointerdown\"",
",",
"this",
",",
"this",
".",
"onClick",
".",
"bind",
"(",
"this",
")",
")",
";",
"// mark it as visible",
"this",
".",
"visible",
"=",
"true",
";",
"// force repaint",
"me",
".",
"game",
".",
"repaint",
"(",
")",
";",
"}",
"}"
] | show the debug panel
@ignore | [
"show",
"the",
"debug",
"panel"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/plugins/debug/debugPanel.js#L614-L625 |
|
7,372 | melonjs/melonJS | plugins/debug/debugPanel.js | function () {
if (this.visible) {
// release the mouse event for the checkboxes
me.input.releasePointerEvent("pointerdown", this);
// remove the debug panel from the game world
me.game.world.removeChild(this, true);
// mark it as invisible
this.visible = false;
// force repaint
me.game.repaint();
}
} | javascript | function () {
if (this.visible) {
// release the mouse event for the checkboxes
me.input.releasePointerEvent("pointerdown", this);
// remove the debug panel from the game world
me.game.world.removeChild(this, true);
// mark it as invisible
this.visible = false;
// force repaint
me.game.repaint();
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"visible",
")",
"{",
"// release the mouse event for the checkboxes",
"me",
".",
"input",
".",
"releasePointerEvent",
"(",
"\"pointerdown\"",
",",
"this",
")",
";",
"// remove the debug panel from the game world",
"me",
".",
"game",
".",
"world",
".",
"removeChild",
"(",
"this",
",",
"true",
")",
";",
"// mark it as invisible",
"this",
".",
"visible",
"=",
"false",
";",
"// force repaint",
"me",
".",
"game",
".",
"repaint",
"(",
")",
";",
"}",
"}"
] | hide the debug panel
@ignore | [
"hide",
"the",
"debug",
"panel"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/plugins/debug/debugPanel.js#L631-L642 |
|
7,373 | melonjs/melonJS | src/state/stage.js | function () {
var self = this;
// add all defined cameras
this.settings.cameras.forEach(function(camera) {
self.cameras.set(camera.name, camera);
});
// empty or no default camera
if (this.cameras.has("default") === false) {
if (typeof default_camera === "undefined") {
var width = me.video.renderer.getWidth();
var height = me.video.renderer.getHeight();
// new default camera instance
default_camera = new me.Camera2d(0, 0, width, height);
}
this.cameras.set("default", default_camera);
}
// reset the game manager
me.game.reset();
// call the onReset Function
this.onResetEvent.apply(this, arguments);
} | javascript | function () {
var self = this;
// add all defined cameras
this.settings.cameras.forEach(function(camera) {
self.cameras.set(camera.name, camera);
});
// empty or no default camera
if (this.cameras.has("default") === false) {
if (typeof default_camera === "undefined") {
var width = me.video.renderer.getWidth();
var height = me.video.renderer.getHeight();
// new default camera instance
default_camera = new me.Camera2d(0, 0, width, height);
}
this.cameras.set("default", default_camera);
}
// reset the game manager
me.game.reset();
// call the onReset Function
this.onResetEvent.apply(this, arguments);
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"// add all defined cameras",
"this",
".",
"settings",
".",
"cameras",
".",
"forEach",
"(",
"function",
"(",
"camera",
")",
"{",
"self",
".",
"cameras",
".",
"set",
"(",
"camera",
".",
"name",
",",
"camera",
")",
";",
"}",
")",
";",
"// empty or no default camera",
"if",
"(",
"this",
".",
"cameras",
".",
"has",
"(",
"\"default\"",
")",
"===",
"false",
")",
"{",
"if",
"(",
"typeof",
"default_camera",
"===",
"\"undefined\"",
")",
"{",
"var",
"width",
"=",
"me",
".",
"video",
".",
"renderer",
".",
"getWidth",
"(",
")",
";",
"var",
"height",
"=",
"me",
".",
"video",
".",
"renderer",
".",
"getHeight",
"(",
")",
";",
"// new default camera instance",
"default_camera",
"=",
"new",
"me",
".",
"Camera2d",
"(",
"0",
",",
"0",
",",
"width",
",",
"height",
")",
";",
"}",
"this",
".",
"cameras",
".",
"set",
"(",
"\"default\"",
",",
"default_camera",
")",
";",
"}",
"// reset the game manager",
"me",
".",
"game",
".",
"reset",
"(",
")",
";",
"// call the onReset Function",
"this",
".",
"onResetEvent",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}"
] | Object reset function
@ignore | [
"Object",
"reset",
"function"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/state/stage.js#L53-L77 |
|
7,374 | melonjs/melonJS | src/renderable/renderable.js | function (m) {
var bounds = this.getBounds();
this.currentTransform.multiply(m);
bounds.setPoints(bounds.transform(m).points);
bounds.pos.setV(this.pos);
return this;
} | javascript | function (m) {
var bounds = this.getBounds();
this.currentTransform.multiply(m);
bounds.setPoints(bounds.transform(m).points);
bounds.pos.setV(this.pos);
return this;
} | [
"function",
"(",
"m",
")",
"{",
"var",
"bounds",
"=",
"this",
".",
"getBounds",
"(",
")",
";",
"this",
".",
"currentTransform",
".",
"multiply",
"(",
"m",
")",
";",
"bounds",
".",
"setPoints",
"(",
"bounds",
".",
"transform",
"(",
"m",
")",
".",
"points",
")",
";",
"bounds",
".",
"pos",
".",
"setV",
"(",
"this",
".",
"pos",
")",
";",
"return",
"this",
";",
"}"
] | multiply the renderable currentTransform with the given matrix
@name transform
@memberOf me.Renderable.prototype
@see me.Renderable#currentTransform
@function
@param {me.Matrix2d} matrix the transformation matrix
@return {me.Renderable} Reference to this object for method chaining | [
"multiply",
"the",
"renderable",
"currentTransform",
"with",
"the",
"given",
"matrix"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/renderable/renderable.js#L416-L422 |
|
7,375 | melonjs/melonJS | src/renderable/renderable.js | function (target) {
var a = this.getBounds();
var ax, ay;
if (target instanceof me.Renderable) {
var b = target.getBounds();
ax = b.centerX - a.centerX;
ay = b.centerY - a.centerY;
} else { // vector object
ax = target.x - a.centerX;
ay = target.y - a.centerY;
}
return Math.atan2(ay, ax);
} | javascript | function (target) {
var a = this.getBounds();
var ax, ay;
if (target instanceof me.Renderable) {
var b = target.getBounds();
ax = b.centerX - a.centerX;
ay = b.centerY - a.centerY;
} else { // vector object
ax = target.x - a.centerX;
ay = target.y - a.centerY;
}
return Math.atan2(ay, ax);
} | [
"function",
"(",
"target",
")",
"{",
"var",
"a",
"=",
"this",
".",
"getBounds",
"(",
")",
";",
"var",
"ax",
",",
"ay",
";",
"if",
"(",
"target",
"instanceof",
"me",
".",
"Renderable",
")",
"{",
"var",
"b",
"=",
"target",
".",
"getBounds",
"(",
")",
";",
"ax",
"=",
"b",
".",
"centerX",
"-",
"a",
".",
"centerX",
";",
"ay",
"=",
"b",
".",
"centerY",
"-",
"a",
".",
"centerY",
";",
"}",
"else",
"{",
"// vector object",
"ax",
"=",
"target",
".",
"x",
"-",
"a",
".",
"centerX",
";",
"ay",
"=",
"target",
".",
"y",
"-",
"a",
".",
"centerY",
";",
"}",
"return",
"Math",
".",
"atan2",
"(",
"ay",
",",
"ax",
")",
";",
"}"
] | return the angle to the specified target
@name angleTo
@memberOf me.Renderable
@function
@param {me.Renderable|me.Vector2d|me.Vector3d} target
@return {Number} angle in radians | [
"return",
"the",
"angle",
"to",
"the",
"specified",
"target"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/renderable/renderable.js#L432-L446 |
|
7,376 | melonjs/melonJS | src/renderable/renderable.js | function (target) {
var a = this.getBounds();
var dx, dy;
if (target instanceof me.Renderable) {
var b = target.getBounds();
dx = a.centerX - b.centerX;
dy = a.centerY - b.centerY;
} else { // vector object
dx = a.centerX - target.x;
dy = a.centerY - target.y;
}
return Math.sqrt(dx * dx + dy * dy);
} | javascript | function (target) {
var a = this.getBounds();
var dx, dy;
if (target instanceof me.Renderable) {
var b = target.getBounds();
dx = a.centerX - b.centerX;
dy = a.centerY - b.centerY;
} else { // vector object
dx = a.centerX - target.x;
dy = a.centerY - target.y;
}
return Math.sqrt(dx * dx + dy * dy);
} | [
"function",
"(",
"target",
")",
"{",
"var",
"a",
"=",
"this",
".",
"getBounds",
"(",
")",
";",
"var",
"dx",
",",
"dy",
";",
"if",
"(",
"target",
"instanceof",
"me",
".",
"Renderable",
")",
"{",
"var",
"b",
"=",
"target",
".",
"getBounds",
"(",
")",
";",
"dx",
"=",
"a",
".",
"centerX",
"-",
"b",
".",
"centerX",
";",
"dy",
"=",
"a",
".",
"centerY",
"-",
"b",
".",
"centerY",
";",
"}",
"else",
"{",
"// vector object",
"dx",
"=",
"a",
".",
"centerX",
"-",
"target",
".",
"x",
";",
"dy",
"=",
"a",
".",
"centerY",
"-",
"target",
".",
"y",
";",
"}",
"return",
"Math",
".",
"sqrt",
"(",
"dx",
"*",
"dx",
"+",
"dy",
"*",
"dy",
")",
";",
"}"
] | return the distance to the specified target
@name distanceTo
@memberOf me.Renderable
@function
@param {me.Renderable|me.Vector2d|me.Vector3d} target
@return {Number} distance | [
"return",
"the",
"distance",
"to",
"the",
"specified",
"target"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/renderable/renderable.js#L456-L470 |
|
7,377 | melonjs/melonJS | src/renderable/renderable.js | function (target) {
var position;
if (target instanceof me.Renderable) {
position = target.pos;
} else {
position = target;
}
var angle = this.angleTo(position);
this.rotate(angle);
return this;
} | javascript | function (target) {
var position;
if (target instanceof me.Renderable) {
position = target.pos;
} else {
position = target;
}
var angle = this.angleTo(position);
this.rotate(angle);
return this;
} | [
"function",
"(",
"target",
")",
"{",
"var",
"position",
";",
"if",
"(",
"target",
"instanceof",
"me",
".",
"Renderable",
")",
"{",
"position",
"=",
"target",
".",
"pos",
";",
"}",
"else",
"{",
"position",
"=",
"target",
";",
"}",
"var",
"angle",
"=",
"this",
".",
"angleTo",
"(",
"position",
")",
";",
"this",
".",
"rotate",
"(",
"angle",
")",
";",
"return",
"this",
";",
"}"
] | Rotate this renderable towards the given target.
@name lookAt
@memberOf me.Renderable.prototype
@function
@param {me.Renderable|me.Vector2d|me.Vector3d} target the renderable or position to look at
@return {me.Renderable} Reference to this object for method chaining | [
"Rotate",
"this",
"renderable",
"towards",
"the",
"given",
"target",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/renderable/renderable.js#L480-L494 |
|
7,378 | melonjs/melonJS | src/math/matrix2.js | function (b) {
b = b.val;
var a = this.val,
a0 = a[0],
a1 = a[1],
a3 = a[3],
a4 = a[4],
b0 = b[0],
b1 = b[1],
b3 = b[3],
b4 = b[4],
b6 = b[6],
b7 = b[7];
a[0] = a0 * b0 + a3 * b1;
a[1] = a1 * b0 + a4 * b1;
a[3] = a0 * b3 + a3 * b4;
a[4] = a1 * b3 + a4 * b4;
a[6] += a0 * b6 + a3 * b7;
a[7] += a1 * b6 + a4 * b7;
return this;
} | javascript | function (b) {
b = b.val;
var a = this.val,
a0 = a[0],
a1 = a[1],
a3 = a[3],
a4 = a[4],
b0 = b[0],
b1 = b[1],
b3 = b[3],
b4 = b[4],
b6 = b[6],
b7 = b[7];
a[0] = a0 * b0 + a3 * b1;
a[1] = a1 * b0 + a4 * b1;
a[3] = a0 * b3 + a3 * b4;
a[4] = a1 * b3 + a4 * b4;
a[6] += a0 * b6 + a3 * b7;
a[7] += a1 * b6 + a4 * b7;
return this;
} | [
"function",
"(",
"b",
")",
"{",
"b",
"=",
"b",
".",
"val",
";",
"var",
"a",
"=",
"this",
".",
"val",
",",
"a0",
"=",
"a",
"[",
"0",
"]",
",",
"a1",
"=",
"a",
"[",
"1",
"]",
",",
"a3",
"=",
"a",
"[",
"3",
"]",
",",
"a4",
"=",
"a",
"[",
"4",
"]",
",",
"b0",
"=",
"b",
"[",
"0",
"]",
",",
"b1",
"=",
"b",
"[",
"1",
"]",
",",
"b3",
"=",
"b",
"[",
"3",
"]",
",",
"b4",
"=",
"b",
"[",
"4",
"]",
",",
"b6",
"=",
"b",
"[",
"6",
"]",
",",
"b7",
"=",
"b",
"[",
"7",
"]",
";",
"a",
"[",
"0",
"]",
"=",
"a0",
"*",
"b0",
"+",
"a3",
"*",
"b1",
";",
"a",
"[",
"1",
"]",
"=",
"a1",
"*",
"b0",
"+",
"a4",
"*",
"b1",
";",
"a",
"[",
"3",
"]",
"=",
"a0",
"*",
"b3",
"+",
"a3",
"*",
"b4",
";",
"a",
"[",
"4",
"]",
"=",
"a1",
"*",
"b3",
"+",
"a4",
"*",
"b4",
";",
"a",
"[",
"6",
"]",
"+=",
"a0",
"*",
"b6",
"+",
"a3",
"*",
"b7",
";",
"a",
"[",
"7",
"]",
"+=",
"a1",
"*",
"b6",
"+",
"a4",
"*",
"b7",
";",
"return",
"this",
";",
"}"
] | multiply both matrix
@name multiply
@memberOf me.Matrix2d
@function
@param {me.Matrix2d} b Other matrix
@return {me.Matrix2d} Reference to this object for method chaining | [
"multiply",
"both",
"matrix"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/math/matrix2.js#L115-L137 |
|
7,379 | melonjs/melonJS | src/math/matrix2.js | function () {
var val = this.val;
var a = val[ 0 ], b = val[ 1 ], c = val[ 2 ],
d = val[ 3 ], e = val[ 4 ], f = val[ 5 ],
g = val[ 6 ], h = val[ 7 ], i = val[ 8 ];
var ta = i * e - f * h,
td = f * g - i * d,
tg = h * d - e * g;
var n = a * ta + b * td + c * tg;
val[ 0 ] = ta / n;
val[ 1 ] = ( c * h - i * b ) / n;
val[ 2 ] = ( f * b - c * e ) / n;
val[ 3 ] = td / n;
val[ 4 ] = ( i * a - c * g ) / n;
val[ 5 ] = ( c * d - f * a ) / n;
val[ 6 ] = tg / n;
val[ 7 ] = ( b * g - h * a ) / n;
val[ 8 ] = ( e * a - b * d ) / n;
return this;
} | javascript | function () {
var val = this.val;
var a = val[ 0 ], b = val[ 1 ], c = val[ 2 ],
d = val[ 3 ], e = val[ 4 ], f = val[ 5 ],
g = val[ 6 ], h = val[ 7 ], i = val[ 8 ];
var ta = i * e - f * h,
td = f * g - i * d,
tg = h * d - e * g;
var n = a * ta + b * td + c * tg;
val[ 0 ] = ta / n;
val[ 1 ] = ( c * h - i * b ) / n;
val[ 2 ] = ( f * b - c * e ) / n;
val[ 3 ] = td / n;
val[ 4 ] = ( i * a - c * g ) / n;
val[ 5 ] = ( c * d - f * a ) / n;
val[ 6 ] = tg / n;
val[ 7 ] = ( b * g - h * a ) / n;
val[ 8 ] = ( e * a - b * d ) / n;
return this;
} | [
"function",
"(",
")",
"{",
"var",
"val",
"=",
"this",
".",
"val",
";",
"var",
"a",
"=",
"val",
"[",
"0",
"]",
",",
"b",
"=",
"val",
"[",
"1",
"]",
",",
"c",
"=",
"val",
"[",
"2",
"]",
",",
"d",
"=",
"val",
"[",
"3",
"]",
",",
"e",
"=",
"val",
"[",
"4",
"]",
",",
"f",
"=",
"val",
"[",
"5",
"]",
",",
"g",
"=",
"val",
"[",
"6",
"]",
",",
"h",
"=",
"val",
"[",
"7",
"]",
",",
"i",
"=",
"val",
"[",
"8",
"]",
";",
"var",
"ta",
"=",
"i",
"*",
"e",
"-",
"f",
"*",
"h",
",",
"td",
"=",
"f",
"*",
"g",
"-",
"i",
"*",
"d",
",",
"tg",
"=",
"h",
"*",
"d",
"-",
"e",
"*",
"g",
";",
"var",
"n",
"=",
"a",
"*",
"ta",
"+",
"b",
"*",
"td",
"+",
"c",
"*",
"tg",
";",
"val",
"[",
"0",
"]",
"=",
"ta",
"/",
"n",
";",
"val",
"[",
"1",
"]",
"=",
"(",
"c",
"*",
"h",
"-",
"i",
"*",
"b",
")",
"/",
"n",
";",
"val",
"[",
"2",
"]",
"=",
"(",
"f",
"*",
"b",
"-",
"c",
"*",
"e",
")",
"/",
"n",
";",
"val",
"[",
"3",
"]",
"=",
"td",
"/",
"n",
";",
"val",
"[",
"4",
"]",
"=",
"(",
"i",
"*",
"a",
"-",
"c",
"*",
"g",
")",
"/",
"n",
";",
"val",
"[",
"5",
"]",
"=",
"(",
"c",
"*",
"d",
"-",
"f",
"*",
"a",
")",
"/",
"n",
";",
"val",
"[",
"6",
"]",
"=",
"tg",
"/",
"n",
";",
"val",
"[",
"7",
"]",
"=",
"(",
"b",
"*",
"g",
"-",
"h",
"*",
"a",
")",
"/",
"n",
";",
"val",
"[",
"8",
"]",
"=",
"(",
"e",
"*",
"a",
"-",
"b",
"*",
"d",
")",
"/",
"n",
";",
"return",
"this",
";",
"}"
] | invert this matrix, causing it to apply the opposite transformation.
@name invert
@memberOf me.Matrix2d
@function
@return {me.Matrix2d} Reference to this object for method chaining | [
"invert",
"this",
"matrix",
"causing",
"it",
"to",
"apply",
"the",
"opposite",
"transformation",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/math/matrix2.js#L169-L195 |
|
7,380 | melonjs/melonJS | src/math/matrix2.js | function (v) {
var a = this.val,
x = v.x,
y = v.y;
v.x = x * a[0] + y * a[3] + a[6];
v.y = x * a[1] + y * a[4] + a[7];
return v;
} | javascript | function (v) {
var a = this.val,
x = v.x,
y = v.y;
v.x = x * a[0] + y * a[3] + a[6];
v.y = x * a[1] + y * a[4] + a[7];
return v;
} | [
"function",
"(",
"v",
")",
"{",
"var",
"a",
"=",
"this",
".",
"val",
",",
"x",
"=",
"v",
".",
"x",
",",
"y",
"=",
"v",
".",
"y",
";",
"v",
".",
"x",
"=",
"x",
"*",
"a",
"[",
"0",
"]",
"+",
"y",
"*",
"a",
"[",
"3",
"]",
"+",
"a",
"[",
"6",
"]",
";",
"v",
".",
"y",
"=",
"x",
"*",
"a",
"[",
"1",
"]",
"+",
"y",
"*",
"a",
"[",
"4",
"]",
"+",
"a",
"[",
"7",
"]",
";",
"return",
"v",
";",
"}"
] | Transforms the given vector according to this matrix.
@name multiplyVector
@memberOf me.Matrix2d
@function
@param {me.Vector2d} vector the vector object to be transformed
@return {me.Vector2d} result vector object. Useful for chaining method calls. | [
"Transforms",
"the",
"given",
"vector",
"according",
"to",
"this",
"matrix",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/math/matrix2.js#L205-L214 |
|
7,381 | melonjs/melonJS | src/math/matrix2.js | function (x, y) {
var a = this.val,
_x = x,
_y = typeof(y) === "undefined" ? _x : y;
a[0] *= _x;
a[1] *= _x;
a[3] *= _y;
a[4] *= _y;
return this;
} | javascript | function (x, y) {
var a = this.val,
_x = x,
_y = typeof(y) === "undefined" ? _x : y;
a[0] *= _x;
a[1] *= _x;
a[3] *= _y;
a[4] *= _y;
return this;
} | [
"function",
"(",
"x",
",",
"y",
")",
"{",
"var",
"a",
"=",
"this",
".",
"val",
",",
"_x",
"=",
"x",
",",
"_y",
"=",
"typeof",
"(",
"y",
")",
"===",
"\"undefined\"",
"?",
"_x",
":",
"y",
";",
"a",
"[",
"0",
"]",
"*=",
"_x",
";",
"a",
"[",
"1",
"]",
"*=",
"_x",
";",
"a",
"[",
"3",
"]",
"*=",
"_y",
";",
"a",
"[",
"4",
"]",
"*=",
"_y",
";",
"return",
"this",
";",
"}"
] | scale the matrix
@name scale
@memberOf me.Matrix2d
@function
@param {Number} x a number representing the abscissa of the scaling vector.
@param {Number} [y=x] a number representing the ordinate of the scaling vector.
@return {me.Matrix2d} Reference to this object for method chaining | [
"scale",
"the",
"matrix"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/math/matrix2.js#L246-L257 |
|
7,382 | melonjs/melonJS | src/math/matrix2.js | function (x, y) {
var a = this.val;
a[6] += a[0] * x + a[3] * y;
a[7] += a[1] * x + a[4] * y;
return this;
} | javascript | function (x, y) {
var a = this.val;
a[6] += a[0] * x + a[3] * y;
a[7] += a[1] * x + a[4] * y;
return this;
} | [
"function",
"(",
"x",
",",
"y",
")",
"{",
"var",
"a",
"=",
"this",
".",
"val",
";",
"a",
"[",
"6",
"]",
"+=",
"a",
"[",
"0",
"]",
"*",
"x",
"+",
"a",
"[",
"3",
"]",
"*",
"y",
";",
"a",
"[",
"7",
"]",
"+=",
"a",
"[",
"1",
"]",
"*",
"x",
"+",
"a",
"[",
"4",
"]",
"*",
"y",
";",
"return",
"this",
";",
"}"
] | translate the matrix position on the horizontal and vertical axis
@name translate
@memberOf me.Matrix2d
@function
@param {Number} x the x coordindates to translate the matrix by
@param {Number} y the y coordindates to translate the matrix by
@return {me.Matrix2d} Reference to this object for method chaining | [
"translate",
"the",
"matrix",
"position",
"on",
"the",
"horizontal",
"and",
"vertical",
"axis"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/math/matrix2.js#L335-L342 |
|
7,383 | melonjs/melonJS | src/video/renderer.js | function (width, height) {
if (width !== this.backBufferCanvas.width || height !== this.backBufferCanvas.height) {
this.canvas.width = this.backBufferCanvas.width = width;
this.canvas.height = this.backBufferCanvas.height = height;
this.currentScissor[0] = 0;
this.currentScissor[1] = 0;
this.currentScissor[2] = width;
this.currentScissor[3] = height;
// publish the corresponding event
me.event.publish(me.event.CANVAS_ONRESIZE, [ width, height ]);
}
this.updateBounds();
} | javascript | function (width, height) {
if (width !== this.backBufferCanvas.width || height !== this.backBufferCanvas.height) {
this.canvas.width = this.backBufferCanvas.width = width;
this.canvas.height = this.backBufferCanvas.height = height;
this.currentScissor[0] = 0;
this.currentScissor[1] = 0;
this.currentScissor[2] = width;
this.currentScissor[3] = height;
// publish the corresponding event
me.event.publish(me.event.CANVAS_ONRESIZE, [ width, height ]);
}
this.updateBounds();
} | [
"function",
"(",
"width",
",",
"height",
")",
"{",
"if",
"(",
"width",
"!==",
"this",
".",
"backBufferCanvas",
".",
"width",
"||",
"height",
"!==",
"this",
".",
"backBufferCanvas",
".",
"height",
")",
"{",
"this",
".",
"canvas",
".",
"width",
"=",
"this",
".",
"backBufferCanvas",
".",
"width",
"=",
"width",
";",
"this",
".",
"canvas",
".",
"height",
"=",
"this",
".",
"backBufferCanvas",
".",
"height",
"=",
"height",
";",
"this",
".",
"currentScissor",
"[",
"0",
"]",
"=",
"0",
";",
"this",
".",
"currentScissor",
"[",
"1",
"]",
"=",
"0",
";",
"this",
".",
"currentScissor",
"[",
"2",
"]",
"=",
"width",
";",
"this",
".",
"currentScissor",
"[",
"3",
"]",
"=",
"height",
";",
"// publish the corresponding event",
"me",
".",
"event",
".",
"publish",
"(",
"me",
".",
"event",
".",
"CANVAS_ONRESIZE",
",",
"[",
"width",
",",
"height",
"]",
")",
";",
"}",
"this",
".",
"updateBounds",
"(",
")",
";",
"}"
] | resizes the system canvas
@name resize
@memberOf me.Renderer.prototype
@function
@param {Number} width new width of the canvas
@param {Number} height new height of the canvas | [
"resizes",
"the",
"system",
"canvas"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/renderer.js#L288-L300 |
|
7,384 | melonjs/melonJS | src/camera/camera2d.js | function (x, y) {
var _x = this.pos.x;
var _y = this.pos.y;
this.pos.x = me.Math.clamp(
x,
this.bounds.pos.x,
this.bounds.width - this.width
);
this.pos.y = me.Math.clamp(
y,
this.bounds.pos.y,
this.bounds.height - this.height
);
//publish the VIEWPORT_ONCHANGE event if necessary
if (_x !== this.pos.x || _y !== this.pos.y) {
me.event.publish(me.event.VIEWPORT_ONCHANGE, [this.pos]);
}
} | javascript | function (x, y) {
var _x = this.pos.x;
var _y = this.pos.y;
this.pos.x = me.Math.clamp(
x,
this.bounds.pos.x,
this.bounds.width - this.width
);
this.pos.y = me.Math.clamp(
y,
this.bounds.pos.y,
this.bounds.height - this.height
);
//publish the VIEWPORT_ONCHANGE event if necessary
if (_x !== this.pos.x || _y !== this.pos.y) {
me.event.publish(me.event.VIEWPORT_ONCHANGE, [this.pos]);
}
} | [
"function",
"(",
"x",
",",
"y",
")",
"{",
"var",
"_x",
"=",
"this",
".",
"pos",
".",
"x",
";",
"var",
"_y",
"=",
"this",
".",
"pos",
".",
"y",
";",
"this",
".",
"pos",
".",
"x",
"=",
"me",
".",
"Math",
".",
"clamp",
"(",
"x",
",",
"this",
".",
"bounds",
".",
"pos",
".",
"x",
",",
"this",
".",
"bounds",
".",
"width",
"-",
"this",
".",
"width",
")",
";",
"this",
".",
"pos",
".",
"y",
"=",
"me",
".",
"Math",
".",
"clamp",
"(",
"y",
",",
"this",
".",
"bounds",
".",
"pos",
".",
"y",
",",
"this",
".",
"bounds",
".",
"height",
"-",
"this",
".",
"height",
")",
";",
"//publish the VIEWPORT_ONCHANGE event if necessary",
"if",
"(",
"_x",
"!==",
"this",
".",
"pos",
".",
"x",
"||",
"_y",
"!==",
"this",
".",
"pos",
".",
"y",
")",
"{",
"me",
".",
"event",
".",
"publish",
"(",
"me",
".",
"event",
".",
"VIEWPORT_ONCHANGE",
",",
"[",
"this",
".",
"pos",
"]",
")",
";",
"}",
"}"
] | move the camera upper-left position to the specified coordinates
@name moveTo
@memberOf me.Camera2d
@see me.Camera2d.focusOn
@function
@param {Number} x
@param {Number} y | [
"move",
"the",
"camera",
"upper",
"-",
"left",
"position",
"to",
"the",
"specified",
"coordinates"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/camera/camera2d.js#L338-L357 |
|
7,385 | melonjs/melonJS | src/camera/camera2d.js | function (target) {
var bounds = target.getBounds();
this.moveTo(
target.pos.x + bounds.pos.x + (bounds.width / 2),
target.pos.y + bounds.pos.y + (bounds.height / 2)
);
} | javascript | function (target) {
var bounds = target.getBounds();
this.moveTo(
target.pos.x + bounds.pos.x + (bounds.width / 2),
target.pos.y + bounds.pos.y + (bounds.height / 2)
);
} | [
"function",
"(",
"target",
")",
"{",
"var",
"bounds",
"=",
"target",
".",
"getBounds",
"(",
")",
";",
"this",
".",
"moveTo",
"(",
"target",
".",
"pos",
".",
"x",
"+",
"bounds",
".",
"pos",
".",
"x",
"+",
"(",
"bounds",
".",
"width",
"/",
"2",
")",
",",
"target",
".",
"pos",
".",
"y",
"+",
"bounds",
".",
"pos",
".",
"y",
"+",
"(",
"bounds",
".",
"height",
"/",
"2",
")",
")",
";",
"}"
] | set the camera position around the specified object
@name focusOn
@memberOf me.Camera2d
@function
@param {me.Renderable} | [
"set",
"the",
"camera",
"position",
"around",
"the",
"specified",
"object"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/camera/camera2d.js#L551-L557 |
|
7,386 | melonjs/melonJS | src/camera/camera2d.js | function (obj, floating) {
if (floating === true || obj.floating === true) {
// check against screen coordinates
return me.video.renderer.overlaps(obj.getBounds());
} else {
// check if within the current camera
return obj.getBounds().overlaps(this);
}
} | javascript | function (obj, floating) {
if (floating === true || obj.floating === true) {
// check against screen coordinates
return me.video.renderer.overlaps(obj.getBounds());
} else {
// check if within the current camera
return obj.getBounds().overlaps(this);
}
} | [
"function",
"(",
"obj",
",",
"floating",
")",
"{",
"if",
"(",
"floating",
"===",
"true",
"||",
"obj",
".",
"floating",
"===",
"true",
")",
"{",
"// check against screen coordinates",
"return",
"me",
".",
"video",
".",
"renderer",
".",
"overlaps",
"(",
"obj",
".",
"getBounds",
"(",
")",
")",
";",
"}",
"else",
"{",
"// check if within the current camera",
"return",
"obj",
".",
"getBounds",
"(",
")",
".",
"overlaps",
"(",
"this",
")",
";",
"}",
"}"
] | check if the specified renderable is in the camera
@name isVisible
@memberOf me.Camera2d
@function
@param {me.Renderable} object
@param {Boolean} [floating===object.floating] if visibility check should be done against screen coordinates
@return {Boolean} | [
"check",
"if",
"the",
"specified",
"renderable",
"is",
"in",
"the",
"camera"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/camera/camera2d.js#L568-L576 |
|
7,387 | melonjs/melonJS | examples/isometric_rpg/js/screens/play.js | function (event) {
var tile = this.refLayer.getTile(event.gameWorldX, event.gameWorldY);
if (tile && tile !== this.currentTile) {
// get the tile x/y world isometric coordinates
this.refLayer.getRenderer().tileToPixelCoords(tile.col, tile.row, this.diamondShape.pos);
// convert thhe diamon shape pos to floating coordinates
me.game.viewport.worldToLocal(
this.diamondShape.pos.x,
this.diamondShape.pos.y,
this.diamondShape.pos
);
// store the current tile
this.currentTile = tile;
};
} | javascript | function (event) {
var tile = this.refLayer.getTile(event.gameWorldX, event.gameWorldY);
if (tile && tile !== this.currentTile) {
// get the tile x/y world isometric coordinates
this.refLayer.getRenderer().tileToPixelCoords(tile.col, tile.row, this.diamondShape.pos);
// convert thhe diamon shape pos to floating coordinates
me.game.viewport.worldToLocal(
this.diamondShape.pos.x,
this.diamondShape.pos.y,
this.diamondShape.pos
);
// store the current tile
this.currentTile = tile;
};
} | [
"function",
"(",
"event",
")",
"{",
"var",
"tile",
"=",
"this",
".",
"refLayer",
".",
"getTile",
"(",
"event",
".",
"gameWorldX",
",",
"event",
".",
"gameWorldY",
")",
";",
"if",
"(",
"tile",
"&&",
"tile",
"!==",
"this",
".",
"currentTile",
")",
"{",
"// get the tile x/y world isometric coordinates",
"this",
".",
"refLayer",
".",
"getRenderer",
"(",
")",
".",
"tileToPixelCoords",
"(",
"tile",
".",
"col",
",",
"tile",
".",
"row",
",",
"this",
".",
"diamondShape",
".",
"pos",
")",
";",
"// convert thhe diamon shape pos to floating coordinates",
"me",
".",
"game",
".",
"viewport",
".",
"worldToLocal",
"(",
"this",
".",
"diamondShape",
".",
"pos",
".",
"x",
",",
"this",
".",
"diamondShape",
".",
"pos",
".",
"y",
",",
"this",
".",
"diamondShape",
".",
"pos",
")",
";",
"// store the current tile",
"this",
".",
"currentTile",
"=",
"tile",
";",
"}",
";",
"}"
] | pointer move event callback | [
"pointer",
"move",
"event",
"callback"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/examples/isometric_rpg/js/screens/play.js#L51-L65 |
|
7,388 | melonjs/melonJS | src/level/tiled/renderer/TMXIsometricRenderer.js | function (obj) {
var tileX = obj.x / this.hTilewidth;
var tileY = obj.y / this.tileheight;
var isoPos = me.pool.pull("me.Vector2d");
this.tileToPixelCoords(tileX, tileY, isoPos);
obj.x = isoPos.x;
obj.y = isoPos.y;
me.pool.push(isoPos);
} | javascript | function (obj) {
var tileX = obj.x / this.hTilewidth;
var tileY = obj.y / this.tileheight;
var isoPos = me.pool.pull("me.Vector2d");
this.tileToPixelCoords(tileX, tileY, isoPos);
obj.x = isoPos.x;
obj.y = isoPos.y;
me.pool.push(isoPos);
} | [
"function",
"(",
"obj",
")",
"{",
"var",
"tileX",
"=",
"obj",
".",
"x",
"/",
"this",
".",
"hTilewidth",
";",
"var",
"tileY",
"=",
"obj",
".",
"y",
"/",
"this",
".",
"tileheight",
";",
"var",
"isoPos",
"=",
"me",
".",
"pool",
".",
"pull",
"(",
"\"me.Vector2d\"",
")",
";",
"this",
".",
"tileToPixelCoords",
"(",
"tileX",
",",
"tileY",
",",
"isoPos",
")",
";",
"obj",
".",
"x",
"=",
"isoPos",
".",
"x",
";",
"obj",
".",
"y",
"=",
"isoPos",
".",
"y",
";",
"me",
".",
"pool",
".",
"push",
"(",
"isoPos",
")",
";",
"}"
] | fix the position of Objects to match
the way Tiled places them
@ignore | [
"fix",
"the",
"position",
"of",
"Objects",
"to",
"match",
"the",
"way",
"Tiled",
"places",
"them"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/level/tiled/renderer/TMXIsometricRenderer.js#L84-L95 |
|
7,389 | melonjs/melonJS | src/level/tiled/TMXLayer.js | function (x, y) {
if (this.containsPoint(x, y)) {
var renderer = this.renderer;
var tile = null;
var coord = renderer.pixelToTileCoords(x, y, me.pool.pull("me.Vector2d"));
if ((coord.x >= 0 && coord.x < renderer.cols) && ( coord.y >= 0 && coord.y < renderer.rows)) {
tile = this.layerData[~~coord.x][~~coord.y];
}
me.pool.push(coord);
}
return tile;
} | javascript | function (x, y) {
if (this.containsPoint(x, y)) {
var renderer = this.renderer;
var tile = null;
var coord = renderer.pixelToTileCoords(x, y, me.pool.pull("me.Vector2d"));
if ((coord.x >= 0 && coord.x < renderer.cols) && ( coord.y >= 0 && coord.y < renderer.rows)) {
tile = this.layerData[~~coord.x][~~coord.y];
}
me.pool.push(coord);
}
return tile;
} | [
"function",
"(",
"x",
",",
"y",
")",
"{",
"if",
"(",
"this",
".",
"containsPoint",
"(",
"x",
",",
"y",
")",
")",
"{",
"var",
"renderer",
"=",
"this",
".",
"renderer",
";",
"var",
"tile",
"=",
"null",
";",
"var",
"coord",
"=",
"renderer",
".",
"pixelToTileCoords",
"(",
"x",
",",
"y",
",",
"me",
".",
"pool",
".",
"pull",
"(",
"\"me.Vector2d\"",
")",
")",
";",
"if",
"(",
"(",
"coord",
".",
"x",
">=",
"0",
"&&",
"coord",
".",
"x",
"<",
"renderer",
".",
"cols",
")",
"&&",
"(",
"coord",
".",
"y",
">=",
"0",
"&&",
"coord",
".",
"y",
"<",
"renderer",
".",
"rows",
")",
")",
"{",
"tile",
"=",
"this",
".",
"layerData",
"[",
"~",
"~",
"coord",
".",
"x",
"]",
"[",
"~",
"~",
"coord",
".",
"y",
"]",
";",
"}",
"me",
".",
"pool",
".",
"push",
"(",
"coord",
")",
";",
"}",
"return",
"tile",
";",
"}"
] | Return the Tile object at the specified position
@name getTile
@memberOf me.TMXLayer
@public
@function
@param {Number} x X coordinate (in world/pixels coordinates)
@param {Number} y Y coordinate (in world/pixels coordinates)
@return {me.Tile} corresponding tile or null if outside of the map area
@example
// get the TMX Map Layer called "Front layer"
var layer = me.game.world.getChildByName("Front Layer")[0];
// get the tile object corresponding to the latest pointer position
var tile = layer.getTile(me.input.pointer.pos.x, me.input.pointer.pos.y); | [
"Return",
"the",
"Tile",
"object",
"at",
"the",
"specified",
"position"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/level/tiled/TMXLayer.js#L264-L275 |
|
7,390 | melonjs/melonJS | src/level/tiled/TMXLayer.js | function (x, y) {
// clearing tile
this.layerData[x][y] = null;
// erase the corresponding area in the canvas
if (this.preRender) {
this.canvasRenderer.clearRect(x * this.tilewidth, y * this.tileheight, this.tilewidth, this.tileheight);
}
} | javascript | function (x, y) {
// clearing tile
this.layerData[x][y] = null;
// erase the corresponding area in the canvas
if (this.preRender) {
this.canvasRenderer.clearRect(x * this.tilewidth, y * this.tileheight, this.tilewidth, this.tileheight);
}
} | [
"function",
"(",
"x",
",",
"y",
")",
"{",
"// clearing tile",
"this",
".",
"layerData",
"[",
"x",
"]",
"[",
"y",
"]",
"=",
"null",
";",
"// erase the corresponding area in the canvas",
"if",
"(",
"this",
".",
"preRender",
")",
"{",
"this",
".",
"canvasRenderer",
".",
"clearRect",
"(",
"x",
"*",
"this",
".",
"tilewidth",
",",
"y",
"*",
"this",
".",
"tileheight",
",",
"this",
".",
"tilewidth",
",",
"this",
".",
"tileheight",
")",
";",
"}",
"}"
] | clear the tile at the specified position
@name clearTile
@memberOf me.TMXLayer
@public
@function
@param {Number} x X coordinate (in map coordinates: row/column)
@param {Number} y Y coordinate (in map coordinates: row/column)
@example
me.game.world.getChildByType(me.TMXLayer).forEach(function(layer) {
// clear all tiles at the given x,y coordinates
layer.clearTile(x, y);
}); | [
"clear",
"the",
"tile",
"at",
"the",
"specified",
"position"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/level/tiled/TMXLayer.js#L315-L322 |
|
7,391 | melonjs/melonJS | src/level/tiled/TMXLayer.js | function (dt) {
if (this.isAnimated) {
var result = false;
for (var i = 0; i < this.animatedTilesets.length; i++) {
result = this.animatedTilesets[i].update(dt) || result;
}
return result;
}
return false;
} | javascript | function (dt) {
if (this.isAnimated) {
var result = false;
for (var i = 0; i < this.animatedTilesets.length; i++) {
result = this.animatedTilesets[i].update(dt) || result;
}
return result;
}
return false;
} | [
"function",
"(",
"dt",
")",
"{",
"if",
"(",
"this",
".",
"isAnimated",
")",
"{",
"var",
"result",
"=",
"false",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"animatedTilesets",
".",
"length",
";",
"i",
"++",
")",
"{",
"result",
"=",
"this",
".",
"animatedTilesets",
"[",
"i",
"]",
".",
"update",
"(",
"dt",
")",
"||",
"result",
";",
"}",
"return",
"result",
";",
"}",
"return",
"false",
";",
"}"
] | update animations in a tileset layer
@ignore | [
"update",
"animations",
"in",
"a",
"tileset",
"layer"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/level/tiled/TMXLayer.js#L328-L338 |
|
7,392 | melonjs/melonJS | src/level/tiled/TMXLayer.js | function (renderer, rect) {
// use the offscreen canvas
if (this.preRender) {
var width = Math.min(rect.width, this.width);
var height = Math.min(rect.height, this.height);
// draw using the cached canvas
renderer.drawImage(
this.canvasRenderer.getCanvas(),
rect.pos.x, rect.pos.y, // sx,sy
width, height, // sw,sh
rect.pos.x, rect.pos.y, // dx,dy
width, height // dw,dh
);
}
// dynamically render the layer
else {
// draw the layer
this.renderer.drawTileLayer(renderer, this, rect);
}
} | javascript | function (renderer, rect) {
// use the offscreen canvas
if (this.preRender) {
var width = Math.min(rect.width, this.width);
var height = Math.min(rect.height, this.height);
// draw using the cached canvas
renderer.drawImage(
this.canvasRenderer.getCanvas(),
rect.pos.x, rect.pos.y, // sx,sy
width, height, // sw,sh
rect.pos.x, rect.pos.y, // dx,dy
width, height // dw,dh
);
}
// dynamically render the layer
else {
// draw the layer
this.renderer.drawTileLayer(renderer, this, rect);
}
} | [
"function",
"(",
"renderer",
",",
"rect",
")",
"{",
"// use the offscreen canvas",
"if",
"(",
"this",
".",
"preRender",
")",
"{",
"var",
"width",
"=",
"Math",
".",
"min",
"(",
"rect",
".",
"width",
",",
"this",
".",
"width",
")",
";",
"var",
"height",
"=",
"Math",
".",
"min",
"(",
"rect",
".",
"height",
",",
"this",
".",
"height",
")",
";",
"// draw using the cached canvas",
"renderer",
".",
"drawImage",
"(",
"this",
".",
"canvasRenderer",
".",
"getCanvas",
"(",
")",
",",
"rect",
".",
"pos",
".",
"x",
",",
"rect",
".",
"pos",
".",
"y",
",",
"// sx,sy",
"width",
",",
"height",
",",
"// sw,sh",
"rect",
".",
"pos",
".",
"x",
",",
"rect",
".",
"pos",
".",
"y",
",",
"// dx,dy",
"width",
",",
"height",
"// dw,dh",
")",
";",
"}",
"// dynamically render the layer",
"else",
"{",
"// draw the layer",
"this",
".",
"renderer",
".",
"drawTileLayer",
"(",
"renderer",
",",
"this",
",",
"rect",
")",
";",
"}",
"}"
] | draw a tileset layer
@ignore | [
"draw",
"a",
"tileset",
"layer"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/level/tiled/TMXLayer.js#L344-L364 |
|
7,393 | melonjs/melonJS | src/shapes/ellipse.js | function () {
return new me.Ellipse(
this.pos.x,
this.pos.y,
this.radiusV.x * 2,
this.radiusV.y * 2
);
} | javascript | function () {
return new me.Ellipse(
this.pos.x,
this.pos.y,
this.radiusV.x * 2,
this.radiusV.y * 2
);
} | [
"function",
"(",
")",
"{",
"return",
"new",
"me",
".",
"Ellipse",
"(",
"this",
".",
"pos",
".",
"x",
",",
"this",
".",
"pos",
".",
"y",
",",
"this",
".",
"radiusV",
".",
"x",
"*",
"2",
",",
"this",
".",
"radiusV",
".",
"y",
"*",
"2",
")",
";",
"}"
] | clone this Ellipse
@name clone
@memberOf me.Ellipse.prototype
@function
@return {me.Ellipse} new Ellipse | [
"clone",
"this",
"Ellipse"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/shapes/ellipse.js#L265-L272 |
|
7,394 | melonjs/melonJS | examples/platformer/js/entities/controls.js | function (x, y) {
if (x - this.pos.x < this.width / 2) {
if (this.cursors.left === false) {
me.input.triggerKeyEvent(me.input.KEY.LEFT, true);
this.cursors.left = true;
this.joypad_offset.x = -((this.width / 2 - (x - this.pos.x)) % this.pad.width / 4);
}
// release the right key if it was pressed
if (this.cursors.right === true) {
me.input.triggerKeyEvent(me.input.KEY.RIGHT, false);
this.cursors.right = false;
}
}
if (x - this.pos.x > this.width / 2) {
if (this.cursors.right === false) {
me.input.triggerKeyEvent(me.input.KEY.RIGHT, true);
this.cursors.right = true;
this.joypad_offset.x = +(((x - this.pos.x) - this.width / 2) % this.pad.width / 4);
}
// release the left key is it was pressed
if (this.cursors.left === true) {
me.input.triggerKeyEvent(me.input.KEY.LEFT, false);
this.cursors.left = false;
}
}
} | javascript | function (x, y) {
if (x - this.pos.x < this.width / 2) {
if (this.cursors.left === false) {
me.input.triggerKeyEvent(me.input.KEY.LEFT, true);
this.cursors.left = true;
this.joypad_offset.x = -((this.width / 2 - (x - this.pos.x)) % this.pad.width / 4);
}
// release the right key if it was pressed
if (this.cursors.right === true) {
me.input.triggerKeyEvent(me.input.KEY.RIGHT, false);
this.cursors.right = false;
}
}
if (x - this.pos.x > this.width / 2) {
if (this.cursors.right === false) {
me.input.triggerKeyEvent(me.input.KEY.RIGHT, true);
this.cursors.right = true;
this.joypad_offset.x = +(((x - this.pos.x) - this.width / 2) % this.pad.width / 4);
}
// release the left key is it was pressed
if (this.cursors.left === true) {
me.input.triggerKeyEvent(me.input.KEY.LEFT, false);
this.cursors.left = false;
}
}
} | [
"function",
"(",
"x",
",",
"y",
")",
"{",
"if",
"(",
"x",
"-",
"this",
".",
"pos",
".",
"x",
"<",
"this",
".",
"width",
"/",
"2",
")",
"{",
"if",
"(",
"this",
".",
"cursors",
".",
"left",
"===",
"false",
")",
"{",
"me",
".",
"input",
".",
"triggerKeyEvent",
"(",
"me",
".",
"input",
".",
"KEY",
".",
"LEFT",
",",
"true",
")",
";",
"this",
".",
"cursors",
".",
"left",
"=",
"true",
";",
"this",
".",
"joypad_offset",
".",
"x",
"=",
"-",
"(",
"(",
"this",
".",
"width",
"/",
"2",
"-",
"(",
"x",
"-",
"this",
".",
"pos",
".",
"x",
")",
")",
"%",
"this",
".",
"pad",
".",
"width",
"/",
"4",
")",
";",
"}",
"// release the right key if it was pressed",
"if",
"(",
"this",
".",
"cursors",
".",
"right",
"===",
"true",
")",
"{",
"me",
".",
"input",
".",
"triggerKeyEvent",
"(",
"me",
".",
"input",
".",
"KEY",
".",
"RIGHT",
",",
"false",
")",
";",
"this",
".",
"cursors",
".",
"right",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"x",
"-",
"this",
".",
"pos",
".",
"x",
">",
"this",
".",
"width",
"/",
"2",
")",
"{",
"if",
"(",
"this",
".",
"cursors",
".",
"right",
"===",
"false",
")",
"{",
"me",
".",
"input",
".",
"triggerKeyEvent",
"(",
"me",
".",
"input",
".",
"KEY",
".",
"RIGHT",
",",
"true",
")",
";",
"this",
".",
"cursors",
".",
"right",
"=",
"true",
";",
"this",
".",
"joypad_offset",
".",
"x",
"=",
"+",
"(",
"(",
"(",
"x",
"-",
"this",
".",
"pos",
".",
"x",
")",
"-",
"this",
".",
"width",
"/",
"2",
")",
"%",
"this",
".",
"pad",
".",
"width",
"/",
"4",
")",
";",
"}",
"// release the left key is it was pressed",
"if",
"(",
"this",
".",
"cursors",
".",
"left",
"===",
"true",
")",
"{",
"me",
".",
"input",
".",
"triggerKeyEvent",
"(",
"me",
".",
"input",
".",
"KEY",
".",
"LEFT",
",",
"false",
")",
";",
"this",
".",
"cursors",
".",
"left",
"=",
"false",
";",
"}",
"}",
"}"
] | update the cursors value and trigger key event | [
"update",
"the",
"cursors",
"value",
"and",
"trigger",
"key",
"event"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/examples/platformer/js/entities/controls.js#L168-L193 |
|
7,395 | melonjs/melonJS | examples/platformer/js/entities/controls.js | function (event) {
this.setOpacity(0.25);
if (this.cursors.left === true) {
me.input.triggerKeyEvent(me.input.KEY.LEFT, false);
this.cursors.left = false;
}
if (this.cursors.right === true) {
me.input.triggerKeyEvent(me.input.KEY.RIGHT, false);
this.cursors.right = false;
}
this.joypad_offset.set(0, 0);
return false;
} | javascript | function (event) {
this.setOpacity(0.25);
if (this.cursors.left === true) {
me.input.triggerKeyEvent(me.input.KEY.LEFT, false);
this.cursors.left = false;
}
if (this.cursors.right === true) {
me.input.triggerKeyEvent(me.input.KEY.RIGHT, false);
this.cursors.right = false;
}
this.joypad_offset.set(0, 0);
return false;
} | [
"function",
"(",
"event",
")",
"{",
"this",
".",
"setOpacity",
"(",
"0.25",
")",
";",
"if",
"(",
"this",
".",
"cursors",
".",
"left",
"===",
"true",
")",
"{",
"me",
".",
"input",
".",
"triggerKeyEvent",
"(",
"me",
".",
"input",
".",
"KEY",
".",
"LEFT",
",",
"false",
")",
";",
"this",
".",
"cursors",
".",
"left",
"=",
"false",
";",
"}",
"if",
"(",
"this",
".",
"cursors",
".",
"right",
"===",
"true",
")",
"{",
"me",
".",
"input",
".",
"triggerKeyEvent",
"(",
"me",
".",
"input",
".",
"KEY",
".",
"RIGHT",
",",
"false",
")",
";",
"this",
".",
"cursors",
".",
"right",
"=",
"false",
";",
"}",
"this",
".",
"joypad_offset",
".",
"set",
"(",
"0",
",",
"0",
")",
";",
"return",
"false",
";",
"}"
] | function called when the object is release or cancelled | [
"function",
"called",
"when",
"the",
"object",
"is",
"release",
"or",
"cancelled"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/examples/platformer/js/entities/controls.js#L209-L221 |
|
7,396 | melonjs/melonJS | examples/platformer/js/entities/controls.js | function (renderer) {
// call the super constructor
this._super(me.GUI_Object, "draw", [ renderer ]);
this.pad.pos.setV(this.pos).add(this.relative).add(this.joypad_offset);
this.pad.draw(renderer);
} | javascript | function (renderer) {
// call the super constructor
this._super(me.GUI_Object, "draw", [ renderer ]);
this.pad.pos.setV(this.pos).add(this.relative).add(this.joypad_offset);
this.pad.draw(renderer);
} | [
"function",
"(",
"renderer",
")",
"{",
"// call the super constructor",
"this",
".",
"_super",
"(",
"me",
".",
"GUI_Object",
",",
"\"draw\"",
",",
"[",
"renderer",
"]",
")",
";",
"this",
".",
"pad",
".",
"pos",
".",
"setV",
"(",
"this",
".",
"pos",
")",
".",
"add",
"(",
"this",
".",
"relative",
")",
".",
"add",
"(",
"this",
".",
"joypad_offset",
")",
";",
"this",
".",
"pad",
".",
"draw",
"(",
"renderer",
")",
";",
"}"
] | extend the draw function | [
"extend",
"the",
"draw",
"function"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/examples/platformer/js/entities/controls.js#L226-L231 |
|
7,397 | melonjs/melonJS | examples/whack-a-mole/js/entities/entities.js | function() {
if (this.isOut === true) {
this.isOut = false;
// set touch animation
this.setCurrentAnimation("touch", this.hide.bind(this));
// make it flicker
this.flicker(750);
// play ow FX
me.audio.play("ow");
// add some points
game.data.score += 100;
if (game.data.hiscore < game.data.score) {
// i could save direclty to me.save
// but that allows me to only have one
// simple HUD Score Object
game.data.hiscore = game.data.score;
// save to local storage
me.save.hiscore = game.data.hiscore;
}
// stop propagating the event
return false;
}
} | javascript | function() {
if (this.isOut === true) {
this.isOut = false;
// set touch animation
this.setCurrentAnimation("touch", this.hide.bind(this));
// make it flicker
this.flicker(750);
// play ow FX
me.audio.play("ow");
// add some points
game.data.score += 100;
if (game.data.hiscore < game.data.score) {
// i could save direclty to me.save
// but that allows me to only have one
// simple HUD Score Object
game.data.hiscore = game.data.score;
// save to local storage
me.save.hiscore = game.data.hiscore;
}
// stop propagating the event
return false;
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"isOut",
"===",
"true",
")",
"{",
"this",
".",
"isOut",
"=",
"false",
";",
"// set touch animation",
"this",
".",
"setCurrentAnimation",
"(",
"\"touch\"",
",",
"this",
".",
"hide",
".",
"bind",
"(",
"this",
")",
")",
";",
"// make it flicker",
"this",
".",
"flicker",
"(",
"750",
")",
";",
"// play ow FX",
"me",
".",
"audio",
".",
"play",
"(",
"\"ow\"",
")",
";",
"// add some points",
"game",
".",
"data",
".",
"score",
"+=",
"100",
";",
"if",
"(",
"game",
".",
"data",
".",
"hiscore",
"<",
"game",
".",
"data",
".",
"score",
")",
"{",
"// i could save direclty to me.save",
"// but that allows me to only have one",
"// simple HUD Score Object",
"game",
".",
"data",
".",
"hiscore",
"=",
"game",
".",
"data",
".",
"score",
";",
"// save to local storage",
"me",
".",
"save",
".",
"hiscore",
"=",
"game",
".",
"data",
".",
"hiscore",
";",
"}",
"// stop propagating the event",
"return",
"false",
";",
"}",
"}"
] | callback for mouse click | [
"callback",
"for",
"mouse",
"click"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/examples/whack-a-mole/js/entities/entities.js#L46-L72 |
|
7,398 | melonjs/melonJS | examples/whack-a-mole/js/entities/entities.js | function() {
var finalpos = this.initialPos - 140;
this.displayTween = me.pool.pull("me.Tween", this.pos).to({y: finalpos }, 200);
this.displayTween.easing(me.Tween.Easing.Quadratic.Out);
this.displayTween.onComplete(this.onDisplayed.bind(this));
this.displayTween.start();
// the mole is visible
this.isVisible = true;
} | javascript | function() {
var finalpos = this.initialPos - 140;
this.displayTween = me.pool.pull("me.Tween", this.pos).to({y: finalpos }, 200);
this.displayTween.easing(me.Tween.Easing.Quadratic.Out);
this.displayTween.onComplete(this.onDisplayed.bind(this));
this.displayTween.start();
// the mole is visible
this.isVisible = true;
} | [
"function",
"(",
")",
"{",
"var",
"finalpos",
"=",
"this",
".",
"initialPos",
"-",
"140",
";",
"this",
".",
"displayTween",
"=",
"me",
".",
"pool",
".",
"pull",
"(",
"\"me.Tween\"",
",",
"this",
".",
"pos",
")",
".",
"to",
"(",
"{",
"y",
":",
"finalpos",
"}",
",",
"200",
")",
";",
"this",
".",
"displayTween",
".",
"easing",
"(",
"me",
".",
"Tween",
".",
"Easing",
".",
"Quadratic",
".",
"Out",
")",
";",
"this",
".",
"displayTween",
".",
"onComplete",
"(",
"this",
".",
"onDisplayed",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"displayTween",
".",
"start",
"(",
")",
";",
"// the mole is visible",
"this",
".",
"isVisible",
"=",
"true",
";",
"}"
] | display the mole
goes out of the hole | [
"display",
"the",
"mole",
"goes",
"out",
"of",
"the",
"hole"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/examples/whack-a-mole/js/entities/entities.js#L79-L87 |
|
7,399 | melonjs/melonJS | examples/whack-a-mole/js/entities/entities.js | function() {
var finalpos = this.initialPos;
this.displayTween = me.pool.pull("me.Tween", this.pos).to({y: finalpos }, 200);
this.displayTween.easing(me.Tween.Easing.Quadratic.In);
this.displayTween.onComplete(this.onHidden.bind(this));
this.displayTween.start();
} | javascript | function() {
var finalpos = this.initialPos;
this.displayTween = me.pool.pull("me.Tween", this.pos).to({y: finalpos }, 200);
this.displayTween.easing(me.Tween.Easing.Quadratic.In);
this.displayTween.onComplete(this.onHidden.bind(this));
this.displayTween.start();
} | [
"function",
"(",
")",
"{",
"var",
"finalpos",
"=",
"this",
".",
"initialPos",
";",
"this",
".",
"displayTween",
"=",
"me",
".",
"pool",
".",
"pull",
"(",
"\"me.Tween\"",
",",
"this",
".",
"pos",
")",
".",
"to",
"(",
"{",
"y",
":",
"finalpos",
"}",
",",
"200",
")",
";",
"this",
".",
"displayTween",
".",
"easing",
"(",
"me",
".",
"Tween",
".",
"Easing",
".",
"Quadratic",
".",
"In",
")",
";",
"this",
".",
"displayTween",
".",
"onComplete",
"(",
"this",
".",
"onHidden",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"displayTween",
".",
"start",
"(",
")",
";",
"}"
] | hide the mole
goes into the hole | [
"hide",
"the",
"mole",
"goes",
"into",
"the",
"hole"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/examples/whack-a-mole/js/entities/entities.js#L101-L107 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.