_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
52
373k
language
stringclasses
1 value
meta_information
dict
q22200
train
function(src, dest) { var contents, srcExists = fs.existsSync(src), destExists = fs.existsSync(dest), stats = srcExists && fs.statSync(src), isDirectory = srcExists && stats.isDirectory(); if (srcExists) { if (isDirectory) { if (!destExists) { ...
javascript
{ "resource": "" }
q22201
train
function () { var spaceCharCode = " ".charCodeAt(0); var glyph = this.glyphs[spaceCharCode]; if (!glyph) { glyph = new Glyph(); glyph.id = spaceCharCode; glyph.xadvance = this._getFirstGlyph().xadvance; this.glyphs[space...
javascript
{ "resource": "" }
q22202
train
function (response) { // the overlap vector var overlap = response.overlapV; // FIXME: Respond proportionally to object mass // Move out of the other object shape this.ancestor.pos.sub(overlap); // adjust velocity if (overlap.x !== 0...
javascript
{ "resource": "" }
q22203
train
function (vel) { var fx = this.friction.x * me.timer.tick, nx = vel.x + fx, x = vel.x - fx, fy = this.friction.y * me.timer.tick, ny = vel.y + fy, y = vel.y - fy; vel.x = ( (nx < 0) ? nx : ...
javascript
{ "resource": "" }
q22204
train
function (e) { if (this.dragging === false) { this.dragging = true; this.grabOffset.set(e.gameX, e.gameY); this.grabOffset.sub(this.pos); return false; } }
javascript
{ "resource": "" }
q22205
train
function (e) { if (this.dragging === true) { this.pos.set(e.gameX, e.gameY, this.pos.z); //TODO : z ? this.pos.sub(this.grabOffset); } }
javascript
{ "resource": "" }
q22206
train
function (r, g, b, alpha) { // Private initialization: copy Color value directly if (r instanceof me.Color) { this.glArray.set(r.glArray); return r; } this.r = r; this.g = g; this.b = b; this.alpha = alph...
javascript
{ "resource": "" }
q22207
train
function (color) { if (color instanceof me.Color) { this.glArray.set(color.glArray); return this; } return this.parseCSS(color); }
javascript
{ "resource": "" }
q22208
train
function (color) { this.glArray[0] = me.Math.clamp(this.glArray[0] + color.glArray[0], 0, 1); this.glArray[1] = me.Math.clamp(this.glArray[1] + color.glArray[1], 0, 1); this.glArray[2] = me.Math.clamp(this.glArray[2] + color.glArray[2], 0, 1); this.glArray[3] = (this.glAr...
javascript
{ "resource": "" }
q22209
train
function (scale) { scale = me.Math.clamp(scale, 0, 1); this.glArray[0] *= scale; this.glArray[1] *= scale; this.glArray[2] *= scale; return this; }
javascript
{ "resource": "" }
q22210
train
function (cssColor) { // TODO : Memoize this function by caching its input if (cssToRGB.has(cssColor)) { return this.setColor.apply(this, cssToRGB.get(cssColor)); } return this.parseRGB(cssColor); }
javascript
{ "resource": "" }
q22211
train
function (rgbColor) { // TODO : Memoize this function by caching its input var match = rgbaRx.exec(rgbColor); if (match) { return this.setColor(+match[1], +match[2], +match[3], +match[5]); } return this.parseHex(rgbColor); }
javascript
{ "resource": "" }
q22212
readLayer
train
function readLayer(map, data, z) { var layer = new me.TMXLayer(data, map.tilewidth, map.tileheight, map.orientation, map.tilesets, z); // set a renderer layer.setRenderer(map.getRenderer()); return layer; }
javascript
{ "resource": "" }
q22213
readImageLayer
train
function readImageLayer(map, data, z) { // Normalize properties me.TMXUtils.applyTMXProperties(data.properties, data); // create the layer var imageLayer = me.pool.pull("me.ImageLayer", // x/y is deprecated since 0.15 and replace by offsetx/y +data.offsetx || +da...
javascript
{ "resource": "" }
q22214
train
function (data) { if (this.initialized === true) { return; } // to automatically increment z index var zOrder = 0; var self = this; // Tileset information if (!this.tilesets) { // make sure we have a T...
javascript
{ "resource": "" }
q22215
train
function (container, flatten) { var _sort = container.autoSort; var _depth = container.autoDepth; // disable auto-sort and auto-depth container.autoSort = false; container.autoDepth = false; // add all layers instances this.getLayers(...
javascript
{ "resource": "" }
q22216
train
function (data) { var atlas = {}; var image = data.image; var spacing = data.spacing || 0; var margin = data.margin || 0; var width = image.width; var height = image.height; // calculate the sprite count (line, col) var sp...
javascript
{ "resource": "" }
q22217
train
function (name) { // Get the source texture region var region = this.getRegion(name); if (typeof(region) === "undefined") { // TODO: Require proper atlas regions instead of caching arbitrary region keys var keys = name.split(","), ...
javascript
{ "resource": "" }
q22218
train
function (name, settings) { // instantiate a new sprite object return me.pool.pull( "me.Sprite", 0, 0, Object.assign({ image: this, region : name }, settings || {}) ); }
javascript
{ "resource": "" }
q22219
_renderFrame
train
function _renderFrame(time) { var stage = _stages[_state].stage; // update all game objects me.game.update(time, stage); // render all game objects me.game.draw(stage); // schedule the next frame update if (_animFrameId !== -1) { ...
javascript
{ "resource": "" }
q22220
_switchState
train
function _switchState(state) { // clear previous interval if any _stopRunLoop(); // call the stage destroy method if (_stages[_state]) { // just notify the object _stages[_state].stage.destroy(); } if (_stages[stat...
javascript
{ "resource": "" }
q22221
train
function (renderer, rect) { var color = renderer.getColor(); var vpos = me.game.viewport.pos; renderer.setColor(this.color); renderer.fillRect( rect.left - vpos.x, rect.top - vpos.y, rect.width, rect.height ); render...
javascript
{ "resource": "" }
q22222
flattenPointsOn
train
function flattenPointsOn(points, normal, result) { var min = Number.MAX_VALUE; var max = -Number.MAX_VALUE; var len = points.length; for (var i = 0; i < len; i++) { // The magnitude of the projection of the point onto the normal var dot = points[i].dotProduct(norm...
javascript
{ "resource": "" }
q22223
checkLoadStatus
train
function checkLoadStatus(onload) { if (loadCount === resourceCount) { // wait 1/2s and execute callback (cheap workaround to ensure everything is loaded) if (onload || api.onload) { // make sure we clear the timer clearTimeout(timerId);...
javascript
{ "resource": "" }
q22224
preloadFontFace
train
function preloadFontFace(data, onload, onerror) { var font = new FontFace(data.name, data.src); // loading promise font.load().then(function() { // apply the font after the font has finished downloading document.fonts.add(font); documen...
javascript
{ "resource": "" }
q22225
preloadJSON
train
function preloadJSON(data, onload, onerror) { var xmlhttp = new XMLHttpRequest(); if (xmlhttp.overrideMimeType) { xmlhttp.overrideMimeType("application/json"); } xmlhttp.open("GET", data.src + api.nocache, true); xmlhttp.withCredentials = me....
javascript
{ "resource": "" }
q22226
train
function (x, y, points) { this.pos.set(x, y); if (!Array.isArray(points)) { return this; } // convert given points to me.Vector2d if required if (!(points[0] instanceof me.Vector2d)) { var _points = this.points = []; ...
javascript
{ "resource": "" }
q22227
train
function (x, y) { y = typeof (y) !== "undefined" ? y : x; var points = this.points; var len = points.length; for (var i = 0; i < len; i++) { points[i].scale(x, y); } this.recalc(); this.updateBounds(); retur...
javascript
{ "resource": "" }
q22228
train
function (body) { // update the entity bounds to match with the body bounds this.getBounds().resize(body.width, body.height); // update the bounds pos this.updateBoundsPos(this.pos.x, this.pos.y); }
javascript
{ "resource": "" }
q22229
train
function () { return (isFinite(this.pos.x) && isFinite(this.pos.y) && isFinite(this._width) && isFinite(this._height)); }
javascript
{ "resource": "" }
q22230
loadTMXLevel
train
function loadTMXLevel(levelId, container, flatten, setViewportBounds) { var level = levels[levelId]; // disable auto-sort for the given container var autoSort = container.autoSort; container.autoSort = false; var levelBounds = level.getBounds(); ...
javascript
{ "resource": "" }
q22231
train
function (x, y) { // translate the given coordinates, // rather than creating temp translated vectors x -= this.pos.x; // Cx y -= this.pos.y; // Cy var start = this.points[0]; // Ax/Ay var end = this.points[1]; // Bx/By //(Cy - Ay) * (...
javascript
{ "resource": "" }
q22232
train
function(context, font, stroke) { context.font = font.font; context.fillStyle = font.fillStyle.toRGBA(); if (stroke === true) { context.strokeStyle = font.strokeStyle.toRGBA(); context.lineWidth = font.lineWidth; } context.textAlign = font.textAlign; ...
javascript
{ "resource": "" }
q22233
train
function (renderer, text, x, y, stroke) { // "hacky patch" for backward compatibilty if (typeof this.ancestor === "undefined") { // update text cache this.setText(text); // update position if changed if (this.pos.x !== x || this.po...
javascript
{ "resource": "" }
q22234
train
function (event) { // Check if left mouse button is pressed if (event.button === 0 && this.isClickable) { this.updated = true; this.released = false; if (this.isHoldable) { if (this.holdTimeout !== null) { ...
javascript
{ "resource": "" }
q22235
train
function (event) { if (this.released === false) { this.released = true; me.timer.clearTimeout(this.holdTimeout); return this.onRelease.call(this, event); } }
javascript
{ "resource": "" }
q22236
train
function (count) { for (var i = 0; i < ~~count; i++) { // Add particle to the container var particle = me.pool.pull("me.Particle", this); this.container.addChild(particle); } }
javascript
{ "resource": "" }
q22237
apply_methods
train
function apply_methods(Class, methods, descriptor) { Object.keys(descriptor).forEach(function (method) { methods[method] = descriptor[method]; if (typeof(descriptor[method]) !== "function") { throw new TypeError( "extend: Method `" + me...
javascript
{ "resource": "" }
q22238
angle
train
function angle(v) { return Math.acos(me.Math.clamp(this.dotProduct(v) / (this.length() * v.length()), -1, 1)); }
javascript
{ "resource": "" }
q22239
floorSelf
train
function floorSelf() { return this._set(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z)); }
javascript
{ "resource": "" }
q22240
ceil
train
function ceil() { return new me.Vector3d(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z)); }
javascript
{ "resource": "" }
q22241
ceilSelf
train
function ceilSelf() { return this._set(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z)); }
javascript
{ "resource": "" }
q22242
setMuted
train
function setMuted(x, y, z) { this._x = x; this._y = y; this._z = z; return this; }
javascript
{ "resource": "" }
q22243
add
train
function add(v) { return this._set(this._x + v.x, this._y + v.y, this._z + (v.z || 0)); }
javascript
{ "resource": "" }
q22244
equals
train
function equals(v) { return this._x === v.x && this._y === v.y && this._z === (v.z || this._z); }
javascript
{ "resource": "" }
q22245
dotProduct
train
function dotProduct(v) { return this._x * v.x + this._y * v.y + this._z * (v.z || 1); }
javascript
{ "resource": "" }
q22246
setTransform
train
function setTransform() { var a = this.val; if (arguments.length === 9) { a[0] = arguments[0]; // a - m00 a[1] = arguments[1]; // b - m10 a[2] = arguments[2]; // c - m20 a[3] = arguments[3]; // d - m01 a[4] = arguments[4]; // e - m11 ...
javascript
{ "resource": "" }
q22247
multiplyVectorInverse
train
function multiplyVectorInverse(v) { var a = this.val, x = v.x, y = v.y; var invD = 1 / (a[0] * a[4] + a[3] * -a[1]); v.x = a[4] * invD * x + -a[3] * invD * y + (a[7] * a[3] - a[6] * a[4]) * invD; v.y = a[0] * invD * y + -a[1] * invD * x + (-a[7] * a[0] + a[6...
javascript
{ "resource": "" }
q22248
setShape
train
function setShape(x, y, w, h) { var hW = w / 2; var hH = h / 2; this.pos.set(x, y); this.radius = Math.max(hW, hH); this.ratio.set(hW / this.radius, hH / this.radius); this.radiusV.set(this.radius, this.radius).scaleV(this.ratio); var r = this.radius * this...
javascript
{ "resource": "" }
q22249
scale
train
function scale(x, y) { y = typeof y !== "undefined" ? y : x; return this.setShape(this.pos.x, this.pos.y, this.radiusV.x * 2 * x, this.radiusV.y * 2 * y); }
javascript
{ "resource": "" }
q22250
splitEarcut
train
function splitEarcut(start, triangles, dim, minX, minY, invSize) { // look for a valid diagonal that divides the polygon into two var a = start; do { var b = a.next.next; while (b !== a.prev) { if (a.i !== b.i && isValidDiagonal(a, b)) { // sp...
javascript
{ "resource": "" }
q22251
zOrder
train
function zOrder(x, y, minX, minY, invSize) { // coords are transformed into non-negative 15-bit integer range x = 32767 * (x - minX) * invSize; y = 32767 * (y - minY) * invSize; x = (x | (x << 8)) & 0x00FF00FF; x = (x | (x << 4)) & 0x0F0F0F0F; x = (x | (x << 2)) & 0x33333333; ...
javascript
{ "resource": "" }
q22252
pointInTriangle
train
function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) { return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0; }
javascript
{ "resource": "" }
q22253
area
train
function area(p, q, r) { return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y); }
javascript
{ "resource": "" }
q22254
splitPolygon
train
function splitPolygon(a, b) { var a2 = new Node(a.i, a.x, a.y), b2 = new Node(b.i, b.x, b.y), an = a.next, bp = b.prev; a.next = b; b.prev = a; a2.next = an; an.prev = a2; b2.next = a2; a2.prev = b2; bp.next = b2; b2.pre...
javascript
{ "resource": "" }
q22255
transform
train
function transform(m) { var points = this.points; var len = points.length; for (var i = 0; i < len; i++) { m.multiplyVector(points[i]); } this.recalc(); this.updateBounds(); return this; }
javascript
{ "resource": "" }
q22256
clone
train
function clone() { var copy = []; this.points.forEach(function (point) { copy.push(point.clone()); }); return new me.Polygon(this.pos.x, this.pos.y, copy); }
javascript
{ "resource": "" }
q22257
setShape
train
function setShape(x, y, w, h) { var points = w; // assume w is an array by default if (arguments.length === 4) { points = this.points; points[0].set(0, 0); // 0, 0 points[1].set(w, 0); // 1, 0 points[2].set(w, h); // 1, 1 points[3].set(0, h); ...
javascript
{ "resource": "" }
q22258
setPoints
train
function setPoints(points) { var x = Infinity, y = Infinity, right = -Infinity, bottom = -Infinity; points.forEach(function (point) { x = Math.min(x, point.x); y = Math.min(y, point.y); right = Math.max(right, point.x); ...
javascript
{ "resource": "" }
q22259
copy
train
function copy(rect) { return this.setShape(rect.pos.x, rect.pos.y, rect._width, rect._height); }
javascript
{ "resource": "" }
q22260
union
train
function union( /** {me.Rect} */ r) { var x1 = Math.min(this.left, r.left); var y1 = Math.min(this.top, r.top); this.resize(Math.max(this.right, r.right) - x1, Math.max(this.bottom, r.bottom) - y1); this.pos.set(x1, y1); return this; }
javascript
{ "resource": "" }
q22261
containsPoint
train
function containsPoint(x, y) { return x >= this.left && x <= this.right && y >= this.top && y <= this.bottom; }
javascript
{ "resource": "" }
q22262
equals
train
function equals(r) { return r.left === this.left && r.right === this.right && r.top === this.top && r.bottom === this.bottom; }
javascript
{ "resource": "" }
q22263
removeShape
train
function removeShape(shape) { me.utils.array.remove(this.shapes, shape); // update the body bounds to take in account the removed shape this.updateBounds(); // return the length of the shape list return this.shapes.length; }
javascript
{ "resource": "" }
q22264
computeVelocity
train
function computeVelocity(vel) { // apply fore if defined if (this.force.x) { vel.x += this.force.x * me.timer.tick; } if (this.force.y) { vel.y += this.force.y * me.timer.tick; } // apply friction if (this.friction.x || this.friction.y) { ...
javascript
{ "resource": "" }
q22265
QT_ARRAY_POP
train
function QT_ARRAY_POP(bounds, max_objects, max_levels, level) { if (QT_ARRAY.length > 0) { var _qt = QT_ARRAY.pop(); _qt.bounds = bounds; _qt.max_objects = max_objects || 4; _qt.max_levels = max_levels || 4; _qt.level = level || 0; return _qt; } else ...
javascript
{ "resource": "" }
q22266
scale
train
function scale(x, y) { var _x = x, _y = typeof y === "undefined" ? _x : y; // set the scaleFlag this.currentTransform.scale(_x, _y); // resize the bounding box this.getBounds().resize(this.width * _x, this.height * _y); return this; }
javascript
{ "resource": "" }
q22267
resize
train
function resize(w, h) { this._super(me.Renderable, "resize", [this.repeatX ? Infinity : w, this.repeatY ? Infinity : h]); }
javascript
{ "resource": "" }
q22268
onDeactivateEvent
train
function onDeactivateEvent() { // cancel all event subscriptions me.event.unsubscribe(this.vpChangeHdlr); me.event.unsubscribe(this.vpResizeHdlr); me.event.unsubscribe(this.vpLoadedHdlr); }
javascript
{ "resource": "" }
q22269
reverseAnimation
train
function reverseAnimation(name) { if (typeof name !== "undefined" && typeof this.anim[name] !== "undefined") { this.anim[name].frames.reverse(); } else { this.anim[this.current.name].frames.reverse(); } return this; }
javascript
{ "resource": "" }
q22270
setRegion
train
function setRegion(region) { if (this.source !== null) { // set the source texture for the given region this.image = this.source.getTexture(region); } // set the sprite offset within the texture this.current.offset.setV(region.offset); // set angle if defined ...
javascript
{ "resource": "" }
q22271
setAnimationFrame
train
function setAnimationFrame(idx) { this.current.idx = (idx || 0) % this.current.length; return this.setRegion(this.getAnimationFrameObjectByIndex(this.current.idx)); }
javascript
{ "resource": "" }
q22272
onAnchorUpdate
train
function onAnchorUpdate(newX, newY) { // since the callback is called before setting the new value // manually update the anchor point (required for updateBoundsPos) this.anchorPoint.setMuted(newX, newY); // then call updateBouds this.updateBoundsPos(this.pos.x, this.pos.y); ...
javascript
{ "resource": "" }
q22273
update
train
function update(dt) { // call the parent constructor var updated = this._super(me.Sprite, "update", [dt]); // check if the button was updated if (this.updated) { // clear the flag if (!this.released) { this.updated = false; } return ...
javascript
{ "resource": "" }
q22274
leave
train
function leave(event) { this.hover = false; this.release.call(this, event); return this.onOut.call(this, event); }
javascript
{ "resource": "" }
q22275
onActivateEvent
train
function onActivateEvent() { // register pointer events me.input.registerPointerEvent("pointerdown", this, this.clicked.bind(this)); me.input.registerPointerEvent("pointerup", this, this.release.bind(this)); me.input.registerPointerEvent("pointercancel", this, this.release.bind(this)...
javascript
{ "resource": "" }
q22276
onDeactivateEvent
train
function onDeactivateEvent() { // release pointer events me.input.releasePointerEvent("pointerdown", this); me.input.releasePointerEvent("pointerup", this); me.input.releasePointerEvent("pointercancel", this); me.input.releasePointerEvent("pointerenter", this); me.i...
javascript
{ "resource": "" }
q22277
getChildAt
train
function getChildAt(index) { if (index >= 0 && index < this.children.length) { return this.children[index]; } else { throw new Error("Index (" + index + ") Out Of Bounds for getChildAt()"); } }
javascript
{ "resource": "" }
q22278
getNextChild
train
function getNextChild(child) { var index = this.children.indexOf(child) - 1; if (index >= 0 && index < this.children.length) { return this.getChildAt(index); } return undefined; }
javascript
{ "resource": "" }
q22279
getChildByType
train
function getChildByType(_class) { var objList = []; for (var i = this.children.length - 1; i >= 0; i--) { var obj = this.children[i]; if (obj instanceof _class) { objList.push(obj); } if (obj instanceof me.Container) { objList = ...
javascript
{ "resource": "" }
q22280
updateChildBounds
train
function updateChildBounds() { this.childBounds.pos.set(Infinity, Infinity); this.childBounds.resize(-Infinity, -Infinity); var childBounds; for (var i = this.children.length, child; i--, child = this.children[i];) { if (child.isRenderable) { if (child instan...
javascript
{ "resource": "" }
q22281
isAttachedToRoot
train
function isAttachedToRoot() { if (this.root === true) { return true; } else { var ancestor = this.ancestor; while (ancestor) { if (ancestor.root === true) { return true; } ancestor = ancestor.ancestor; ...
javascript
{ "resource": "" }
q22282
removeChild
train
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
{ "resource": "" }
q22283
setChildsProperty
train
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
{ "resource": "" }
q22284
_sortZ
train
function _sortZ(a, b) { return b.pos && a.pos ? b.pos.z - a.pos.z : a.pos ? -Infinity : Infinity; }
javascript
{ "resource": "" }
q22285
setDeadzone
train
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); ...
javascript
{ "resource": "" }
q22286
resize
train
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, ...
javascript
{ "resource": "" }
q22287
move
train
function move(x, y) { this.moveTo(this.pos.x + x, this.pos.y + y); }
javascript
{ "resource": "" }
q22288
shake
train
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 onComplet...
javascript
{ "resource": "" }
q22289
drawFX
train
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); ...
javascript
{ "resource": "" }
q22290
draw
train
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 ...
javascript
{ "resource": "" }
q22291
distanceTo
train
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.heigh...
javascript
{ "resource": "" }
q22292
distanceToPoint
train
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 ...
javascript
{ "resource": "" }
q22293
angleTo
train
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 /...
javascript
{ "resource": "" }
q22294
angleToPoint
train
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
{ "resource": "" }
q22295
updateBoundsPos
train
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...
javascript
{ "resource": "" }
q22296
preloadTMX
train
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); } }...
javascript
{ "resource": "" }
q22297
setFont
train
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") { ...
javascript
{ "resource": "" }
q22298
setText
train
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
{ "resource": "" }
q22299
measureTextWidth
train
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 && lastG...
javascript
{ "resource": "" }