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,200 | APIDevTools/swagger-express-middleware | lib/mock/semantic-response.js | getResourceSchemas | function getResourceSchemas (path) {
let schemas = [];
["post", "put", "patch"].forEach((operation) => {
if (path[operation]) {
schemas.push(util.getRequestSchema(path, path[operation]));
}
});
return schemas;
} | javascript | function getResourceSchemas (path) {
let schemas = [];
["post", "put", "patch"].forEach((operation) => {
if (path[operation]) {
schemas.push(util.getRequestSchema(path, path[operation]));
}
});
return schemas;
} | [
"function",
"getResourceSchemas",
"(",
"path",
")",
"{",
"let",
"schemas",
"=",
"[",
"]",
";",
"[",
"\"post\"",
",",
"\"put\"",
",",
"\"patch\"",
"]",
".",
"forEach",
"(",
"(",
"operation",
")",
"=>",
"{",
"if",
"(",
"path",
"[",
"operation",
"]",
")",
"{",
"schemas",
".",
"push",
"(",
"util",
".",
"getRequestSchema",
"(",
"path",
",",
"path",
"[",
"operation",
"]",
")",
")",
";",
"}",
"}",
")",
";",
"return",
"schemas",
";",
"}"
] | Returns the JSON schemas for the given path's PUT, POST, and PATCH operations.
Usually these operations are not wrapped, so we can assume that they are the actual resource schema.
@param {object} path - A Path object, from the Swagger API.
@returns {object[]} - An array of JSON schema objects | [
"Returns",
"the",
"JSON",
"schemas",
"for",
"the",
"given",
"path",
"s",
"PUT",
"POST",
"and",
"PATCH",
"operations",
".",
"Usually",
"these",
"operations",
"are",
"not",
"wrapped",
"so",
"we",
"can",
"assume",
"that",
"they",
"are",
"the",
"actual",
"resource",
"schema",
"."
] | 7544c22045945565f6555419b678fe51ba664a1f | https://github.com/APIDevTools/swagger-express-middleware/blob/7544c22045945565f6555419b678fe51ba664a1f/lib/mock/semantic-response.js#L147-L157 |
7,201 | APIDevTools/swagger-express-middleware | lib/mock/semantic-response.js | schemasMatch | function schemasMatch (schemasToMatch, schemaToTest) {
let propertiesToTest = 0;
if (schemaToTest.properties) {
propertiesToTest = Object.keys(schemaToTest.properties).length;
}
return schemasToMatch.some((schemaToMatch) => {
let propertiesToMatch = 0;
if (schemaToMatch.properties) {
propertiesToMatch = Object.keys(schemaToMatch.properties).length;
}
// Make sure both schemas are the same type and have the same number of properties
if (schemaToTest.type === schemaToMatch.type && propertiesToTest === propertiesToMatch) {
// Compare each property in both schemas
return _.every(schemaToMatch.properties, (propertyToMatch, propName) => {
let propertyToTest = schemaToTest.properties[propName];
return propertyToTest && propertyToMatch.type === propertyToTest.type;
});
}
});
} | javascript | function schemasMatch (schemasToMatch, schemaToTest) {
let propertiesToTest = 0;
if (schemaToTest.properties) {
propertiesToTest = Object.keys(schemaToTest.properties).length;
}
return schemasToMatch.some((schemaToMatch) => {
let propertiesToMatch = 0;
if (schemaToMatch.properties) {
propertiesToMatch = Object.keys(schemaToMatch.properties).length;
}
// Make sure both schemas are the same type and have the same number of properties
if (schemaToTest.type === schemaToMatch.type && propertiesToTest === propertiesToMatch) {
// Compare each property in both schemas
return _.every(schemaToMatch.properties, (propertyToMatch, propName) => {
let propertyToTest = schemaToTest.properties[propName];
return propertyToTest && propertyToMatch.type === propertyToTest.type;
});
}
});
} | [
"function",
"schemasMatch",
"(",
"schemasToMatch",
",",
"schemaToTest",
")",
"{",
"let",
"propertiesToTest",
"=",
"0",
";",
"if",
"(",
"schemaToTest",
".",
"properties",
")",
"{",
"propertiesToTest",
"=",
"Object",
".",
"keys",
"(",
"schemaToTest",
".",
"properties",
")",
".",
"length",
";",
"}",
"return",
"schemasToMatch",
".",
"some",
"(",
"(",
"schemaToMatch",
")",
"=>",
"{",
"let",
"propertiesToMatch",
"=",
"0",
";",
"if",
"(",
"schemaToMatch",
".",
"properties",
")",
"{",
"propertiesToMatch",
"=",
"Object",
".",
"keys",
"(",
"schemaToMatch",
".",
"properties",
")",
".",
"length",
";",
"}",
"// Make sure both schemas are the same type and have the same number of properties",
"if",
"(",
"schemaToTest",
".",
"type",
"===",
"schemaToMatch",
".",
"type",
"&&",
"propertiesToTest",
"===",
"propertiesToMatch",
")",
"{",
"// Compare each property in both schemas",
"return",
"_",
".",
"every",
"(",
"schemaToMatch",
".",
"properties",
",",
"(",
"propertyToMatch",
",",
"propName",
")",
"=>",
"{",
"let",
"propertyToTest",
"=",
"schemaToTest",
".",
"properties",
"[",
"propName",
"]",
";",
"return",
"propertyToTest",
"&&",
"propertyToMatch",
".",
"type",
"===",
"propertyToTest",
".",
"type",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
] | Determines whether the given JSON schema matches any of the given JSON schemas.
@param {object[]} schemasToMatch - An array of JSON schema objects
@param {object} schemaToTest - The JSON schema object to test against the other schemas
@returns {boolean} - Returns true if the schema matches any of the other schemas | [
"Determines",
"whether",
"the",
"given",
"JSON",
"schema",
"matches",
"any",
"of",
"the",
"given",
"JSON",
"schemas",
"."
] | 7544c22045945565f6555419b678fe51ba664a1f | https://github.com/APIDevTools/swagger-express-middleware/blob/7544c22045945565f6555419b678fe51ba664a1f/lib/mock/semantic-response.js#L166-L187 |
7,202 | APIDevTools/swagger-express-middleware | lib/mock/edit-collection.js | mergeCollection | function mergeCollection (req, res, next, dataStore) {
let collection = req.path;
let resources = createResources(req);
// Set the "Location" HTTP header.
// If the operation allows saving multiple resources, then use the collection path.
// If the operation only saves a single resource, then use the resource's path.
res.swagger.location = _.isArray(req.body) ? collection : resources[0].toString();
// Save/Update the resources
util.debug("Saving data at %s", res.swagger.location);
dataStore.save(resources, sendResponse(req, res, next, dataStore));
} | javascript | function mergeCollection (req, res, next, dataStore) {
let collection = req.path;
let resources = createResources(req);
// Set the "Location" HTTP header.
// If the operation allows saving multiple resources, then use the collection path.
// If the operation only saves a single resource, then use the resource's path.
res.swagger.location = _.isArray(req.body) ? collection : resources[0].toString();
// Save/Update the resources
util.debug("Saving data at %s", res.swagger.location);
dataStore.save(resources, sendResponse(req, res, next, dataStore));
} | [
"function",
"mergeCollection",
"(",
"req",
",",
"res",
",",
"next",
",",
"dataStore",
")",
"{",
"let",
"collection",
"=",
"req",
".",
"path",
";",
"let",
"resources",
"=",
"createResources",
"(",
"req",
")",
";",
"// Set the \"Location\" HTTP header.",
"// If the operation allows saving multiple resources, then use the collection path.",
"// If the operation only saves a single resource, then use the resource's path.",
"res",
".",
"swagger",
".",
"location",
"=",
"_",
".",
"isArray",
"(",
"req",
".",
"body",
")",
"?",
"collection",
":",
"resources",
"[",
"0",
"]",
".",
"toString",
"(",
")",
";",
"// Save/Update the resources",
"util",
".",
"debug",
"(",
"\"Saving data at %s\"",
",",
"res",
".",
"swagger",
".",
"location",
")",
";",
"dataStore",
".",
"save",
"(",
"resources",
",",
"sendResponse",
"(",
"req",
",",
"res",
",",
"next",
",",
"dataStore",
")",
")",
";",
"}"
] | Adds one or more REST resources to the collection, or updates them if they already exist.
A unique URL is generated for each new resource, based on the schema definition in the Swagger API,
and this URL is used to determine whether a given resource is being created or updated.
For example, if you POST the data {id: 123, name: 'John Doe'} to /api/users,
then the "id" property will be used to construct the new REST URL: /api/users/123
Similarly, if you POST the data {name: 'John Doe', age: 42} to /api/users,
then the "name" property will be used to construct the new URL: /api/users/John%20Doe
If the data doesn't contain any properties that seem like unique IDs, then a unique ID is generated,
which means new resources will always be created, and never updated.
@param {Request} req
@param {Response} res
@param {function} next
@param {DataStore} dataStore | [
"Adds",
"one",
"or",
"more",
"REST",
"resources",
"to",
"the",
"collection",
"or",
"updates",
"them",
"if",
"they",
"already",
"exist",
".",
"A",
"unique",
"URL",
"is",
"generated",
"for",
"each",
"new",
"resource",
"based",
"on",
"the",
"schema",
"definition",
"in",
"the",
"Swagger",
"API",
"and",
"this",
"URL",
"is",
"used",
"to",
"determine",
"whether",
"a",
"given",
"resource",
"is",
"being",
"created",
"or",
"updated",
"."
] | 7544c22045945565f6555419b678fe51ba664a1f | https://github.com/APIDevTools/swagger-express-middleware/blob/7544c22045945565f6555419b678fe51ba664a1f/lib/mock/edit-collection.js#L34-L46 |
7,203 | APIDevTools/swagger-express-middleware | lib/mock/edit-collection.js | getResourceName | function getResourceName (data, schema) {
// Try to find the "name" property using several different methods
let propInfo =
getResourceNameByValue(data, schema) ||
getResourceNameByName(data, schema) ||
getResourceNameByRequired(data, schema) ||
getResourceNameByFile(data, schema);
if (propInfo) {
util.debug('The "%s" property (%j) appears to be the REST resource\'s name', propInfo.name, propInfo.value);
if (propInfo.value === undefined) {
propInfo.value = new JsonSchema(propInfo.schema).sample();
util.debug('Generated new value (%j) for the "%s" property', propInfo.value, propInfo.name);
}
return propInfo;
}
else {
util.debug("Unable to determine the unique name for the REST resource. Generating a unique value instead");
return {
name: "",
schema: { type: "string" },
value: _.uniqueId()
};
}
} | javascript | function getResourceName (data, schema) {
// Try to find the "name" property using several different methods
let propInfo =
getResourceNameByValue(data, schema) ||
getResourceNameByName(data, schema) ||
getResourceNameByRequired(data, schema) ||
getResourceNameByFile(data, schema);
if (propInfo) {
util.debug('The "%s" property (%j) appears to be the REST resource\'s name', propInfo.name, propInfo.value);
if (propInfo.value === undefined) {
propInfo.value = new JsonSchema(propInfo.schema).sample();
util.debug('Generated new value (%j) for the "%s" property', propInfo.value, propInfo.name);
}
return propInfo;
}
else {
util.debug("Unable to determine the unique name for the REST resource. Generating a unique value instead");
return {
name: "",
schema: { type: "string" },
value: _.uniqueId()
};
}
} | [
"function",
"getResourceName",
"(",
"data",
",",
"schema",
")",
"{",
"// Try to find the \"name\" property using several different methods",
"let",
"propInfo",
"=",
"getResourceNameByValue",
"(",
"data",
",",
"schema",
")",
"||",
"getResourceNameByName",
"(",
"data",
",",
"schema",
")",
"||",
"getResourceNameByRequired",
"(",
"data",
",",
"schema",
")",
"||",
"getResourceNameByFile",
"(",
"data",
",",
"schema",
")",
";",
"if",
"(",
"propInfo",
")",
"{",
"util",
".",
"debug",
"(",
"'The \"%s\" property (%j) appears to be the REST resource\\'s name'",
",",
"propInfo",
".",
"name",
",",
"propInfo",
".",
"value",
")",
";",
"if",
"(",
"propInfo",
".",
"value",
"===",
"undefined",
")",
"{",
"propInfo",
".",
"value",
"=",
"new",
"JsonSchema",
"(",
"propInfo",
".",
"schema",
")",
".",
"sample",
"(",
")",
";",
"util",
".",
"debug",
"(",
"'Generated new value (%j) for the \"%s\" property'",
",",
"propInfo",
".",
"value",
",",
"propInfo",
".",
"name",
")",
";",
"}",
"return",
"propInfo",
";",
"}",
"else",
"{",
"util",
".",
"debug",
"(",
"\"Unable to determine the unique name for the REST resource. Generating a unique value instead\"",
")",
";",
"return",
"{",
"name",
":",
"\"\"",
",",
"schema",
":",
"{",
"type",
":",
"\"string\"",
"}",
",",
"value",
":",
"_",
".",
"uniqueId",
"(",
")",
"}",
";",
"}",
"}"
] | Returns the property that is the REST resource's "unique" name.
@param {*} data - The parsed resource data.
@param {object} schema - The JSON schema for the data.
@returns {PropertyInfo} - The resource's name. | [
"Returns",
"the",
"property",
"that",
"is",
"the",
"REST",
"resource",
"s",
"unique",
"name",
"."
] | 7544c22045945565f6555419b678fe51ba664a1f | https://github.com/APIDevTools/swagger-express-middleware/blob/7544c22045945565f6555419b678fe51ba664a1f/lib/mock/edit-collection.js#L146-L172 |
7,204 | APIDevTools/swagger-express-middleware | lib/mock/edit-collection.js | getResourceNameByName | function getResourceNameByName (data, schema) {
/** @name PropertyInfo */
let propInfo = {
name: "",
schema: {
type: ""
},
value: undefined
};
// Get a list of all existing and possible properties of the resource
let propNames = _.union(_.keys(schema.properties), _.keys(data));
// Lowercase property names, for comparison
let lowercasePropNames = propNames.map((propName) => { return propName.toLowerCase(); });
// These properties are assumed to be unique IDs.
// If we find any of them in the schema, then use it as the REST resource's name.
let nameProperties = ["id", "key", "slug", "code", "number", "num", "nbr", "username", "name"];
let foundMatch = nameProperties.some((lowercasePropName) => {
let index = lowercasePropNames.indexOf(lowercasePropName);
if (index >= 0) {
// We found a property that appears to be the resource's name. Get its info.
propInfo.name = propNames[index];
propInfo.value = data ? data[propInfo.name] : undefined;
if (schema.properties[propInfo.name]) {
propInfo.schema = schema.properties[propInfo.name];
}
else if (_.isDate(data[propInfo.name])) {
propInfo.schema = {
type: "string",
format: "date-time"
};
}
else {
propInfo.schema.type = typeof (data[propInfo.name]);
}
// If the property is valid, then we're done
return isValidResourceName(propInfo);
}
});
return foundMatch ? propInfo : undefined;
} | javascript | function getResourceNameByName (data, schema) {
/** @name PropertyInfo */
let propInfo = {
name: "",
schema: {
type: ""
},
value: undefined
};
// Get a list of all existing and possible properties of the resource
let propNames = _.union(_.keys(schema.properties), _.keys(data));
// Lowercase property names, for comparison
let lowercasePropNames = propNames.map((propName) => { return propName.toLowerCase(); });
// These properties are assumed to be unique IDs.
// If we find any of them in the schema, then use it as the REST resource's name.
let nameProperties = ["id", "key", "slug", "code", "number", "num", "nbr", "username", "name"];
let foundMatch = nameProperties.some((lowercasePropName) => {
let index = lowercasePropNames.indexOf(lowercasePropName);
if (index >= 0) {
// We found a property that appears to be the resource's name. Get its info.
propInfo.name = propNames[index];
propInfo.value = data ? data[propInfo.name] : undefined;
if (schema.properties[propInfo.name]) {
propInfo.schema = schema.properties[propInfo.name];
}
else if (_.isDate(data[propInfo.name])) {
propInfo.schema = {
type: "string",
format: "date-time"
};
}
else {
propInfo.schema.type = typeof (data[propInfo.name]);
}
// If the property is valid, then we're done
return isValidResourceName(propInfo);
}
});
return foundMatch ? propInfo : undefined;
} | [
"function",
"getResourceNameByName",
"(",
"data",
",",
"schema",
")",
"{",
"/** @name PropertyInfo */",
"let",
"propInfo",
"=",
"{",
"name",
":",
"\"\"",
",",
"schema",
":",
"{",
"type",
":",
"\"\"",
"}",
",",
"value",
":",
"undefined",
"}",
";",
"// Get a list of all existing and possible properties of the resource",
"let",
"propNames",
"=",
"_",
".",
"union",
"(",
"_",
".",
"keys",
"(",
"schema",
".",
"properties",
")",
",",
"_",
".",
"keys",
"(",
"data",
")",
")",
";",
"// Lowercase property names, for comparison",
"let",
"lowercasePropNames",
"=",
"propNames",
".",
"map",
"(",
"(",
"propName",
")",
"=>",
"{",
"return",
"propName",
".",
"toLowerCase",
"(",
")",
";",
"}",
")",
";",
"// These properties are assumed to be unique IDs.",
"// If we find any of them in the schema, then use it as the REST resource's name.",
"let",
"nameProperties",
"=",
"[",
"\"id\"",
",",
"\"key\"",
",",
"\"slug\"",
",",
"\"code\"",
",",
"\"number\"",
",",
"\"num\"",
",",
"\"nbr\"",
",",
"\"username\"",
",",
"\"name\"",
"]",
";",
"let",
"foundMatch",
"=",
"nameProperties",
".",
"some",
"(",
"(",
"lowercasePropName",
")",
"=>",
"{",
"let",
"index",
"=",
"lowercasePropNames",
".",
"indexOf",
"(",
"lowercasePropName",
")",
";",
"if",
"(",
"index",
">=",
"0",
")",
"{",
"// We found a property that appears to be the resource's name. Get its info.",
"propInfo",
".",
"name",
"=",
"propNames",
"[",
"index",
"]",
";",
"propInfo",
".",
"value",
"=",
"data",
"?",
"data",
"[",
"propInfo",
".",
"name",
"]",
":",
"undefined",
";",
"if",
"(",
"schema",
".",
"properties",
"[",
"propInfo",
".",
"name",
"]",
")",
"{",
"propInfo",
".",
"schema",
"=",
"schema",
".",
"properties",
"[",
"propInfo",
".",
"name",
"]",
";",
"}",
"else",
"if",
"(",
"_",
".",
"isDate",
"(",
"data",
"[",
"propInfo",
".",
"name",
"]",
")",
")",
"{",
"propInfo",
".",
"schema",
"=",
"{",
"type",
":",
"\"string\"",
",",
"format",
":",
"\"date-time\"",
"}",
";",
"}",
"else",
"{",
"propInfo",
".",
"schema",
".",
"type",
"=",
"typeof",
"(",
"data",
"[",
"propInfo",
".",
"name",
"]",
")",
";",
"}",
"// If the property is valid, then we're done",
"return",
"isValidResourceName",
"(",
"propInfo",
")",
";",
"}",
"}",
")",
";",
"return",
"foundMatch",
"?",
"propInfo",
":",
"undefined",
";",
"}"
] | Tries to find the REST resource's name by searching for commonly-used property names like "id", "key", etc.
@param {*} data - The parsed resource data.
@param {object} schema - The JSON schema for the data.
@returns {PropertyInfo|undefined} | [
"Tries",
"to",
"find",
"the",
"REST",
"resource",
"s",
"name",
"by",
"searching",
"for",
"commonly",
"-",
"used",
"property",
"names",
"like",
"id",
"key",
"etc",
"."
] | 7544c22045945565f6555419b678fe51ba664a1f | https://github.com/APIDevTools/swagger-express-middleware/blob/7544c22045945565f6555419b678fe51ba664a1f/lib/mock/edit-collection.js#L200-L245 |
7,205 | APIDevTools/swagger-express-middleware | lib/mock/edit-collection.js | getResourceNameByRequired | function getResourceNameByRequired (data, schema) {
let propInfo = {
name: "",
schema: {
type: ""
},
value: undefined
};
let foundMatch = _.some(schema.required, (propName) => {
propInfo.name = propName;
propInfo.schema = schema.properties[propName];
propInfo.value = data[propName];
// If the property is valid, then we're done
return isValidResourceName(propInfo);
});
return foundMatch ? propInfo : undefined;
} | javascript | function getResourceNameByRequired (data, schema) {
let propInfo = {
name: "",
schema: {
type: ""
},
value: undefined
};
let foundMatch = _.some(schema.required, (propName) => {
propInfo.name = propName;
propInfo.schema = schema.properties[propName];
propInfo.value = data[propName];
// If the property is valid, then we're done
return isValidResourceName(propInfo);
});
return foundMatch ? propInfo : undefined;
} | [
"function",
"getResourceNameByRequired",
"(",
"data",
",",
"schema",
")",
"{",
"let",
"propInfo",
"=",
"{",
"name",
":",
"\"\"",
",",
"schema",
":",
"{",
"type",
":",
"\"\"",
"}",
",",
"value",
":",
"undefined",
"}",
";",
"let",
"foundMatch",
"=",
"_",
".",
"some",
"(",
"schema",
".",
"required",
",",
"(",
"propName",
")",
"=>",
"{",
"propInfo",
".",
"name",
"=",
"propName",
";",
"propInfo",
".",
"schema",
"=",
"schema",
".",
"properties",
"[",
"propName",
"]",
";",
"propInfo",
".",
"value",
"=",
"data",
"[",
"propName",
"]",
";",
"// If the property is valid, then we're done",
"return",
"isValidResourceName",
"(",
"propInfo",
")",
";",
"}",
")",
";",
"return",
"foundMatch",
"?",
"propInfo",
":",
"undefined",
";",
"}"
] | Tries to find the REST resource's name using the required properties in the JSON schema.
We're assuming that if the resource has a name, it'll be a required property.
@param {*} data - The parsed resource data.
@param {object} schema - The JSON schema for the data.
@returns {PropertyInfo|undefined} | [
"Tries",
"to",
"find",
"the",
"REST",
"resource",
"s",
"name",
"using",
"the",
"required",
"properties",
"in",
"the",
"JSON",
"schema",
".",
"We",
"re",
"assuming",
"that",
"if",
"the",
"resource",
"has",
"a",
"name",
"it",
"ll",
"be",
"a",
"required",
"property",
"."
] | 7544c22045945565f6555419b678fe51ba664a1f | https://github.com/APIDevTools/swagger-express-middleware/blob/7544c22045945565f6555419b678fe51ba664a1f/lib/mock/edit-collection.js#L255-L274 |
7,206 | openaps/oref0 | lib/determine-basal/determine-basal.js | round | function round(value, digits)
{
if (! digits) { digits = 0; }
var scale = Math.pow(10, digits);
return Math.round(value * scale) / scale;
} | javascript | function round(value, digits)
{
if (! digits) { digits = 0; }
var scale = Math.pow(10, digits);
return Math.round(value * scale) / scale;
} | [
"function",
"round",
"(",
"value",
",",
"digits",
")",
"{",
"if",
"(",
"!",
"digits",
")",
"{",
"digits",
"=",
"0",
";",
"}",
"var",
"scale",
"=",
"Math",
".",
"pow",
"(",
"10",
",",
"digits",
")",
";",
"return",
"Math",
".",
"round",
"(",
"value",
"*",
"scale",
")",
"/",
"scale",
";",
"}"
] | Rounds value to 'digits' decimal places | [
"Rounds",
"value",
"to",
"digits",
"decimal",
"places"
] | 86f601ea56210d7dc55babcff4a5a4e906fa9476 | https://github.com/openaps/oref0/blob/86f601ea56210d7dc55babcff4a5a4e906fa9476/lib/determine-basal/determine-basal.js#L20-L25 |
7,207 | anandanand84/technicalindicators | dist/index.js | fibonacciretracement | function fibonacciretracement(start, end) {
let levels = [0, 23.6, 38.2, 50, 61.8, 78.6, 100, 127.2, 161.8, 261.8, 423.6];
let retracements;
if (start < end) {
retracements = levels.map(function (level) {
let calculated = end - Math.abs(start - end) * (level) / 100;
return calculated > 0 ? calculated : 0;
});
}
else {
retracements = levels.map(function (level) {
let calculated = end + Math.abs(start - end) * (level) / 100;
return calculated > 0 ? calculated : 0;
});
}
return retracements;
} | javascript | function fibonacciretracement(start, end) {
let levels = [0, 23.6, 38.2, 50, 61.8, 78.6, 100, 127.2, 161.8, 261.8, 423.6];
let retracements;
if (start < end) {
retracements = levels.map(function (level) {
let calculated = end - Math.abs(start - end) * (level) / 100;
return calculated > 0 ? calculated : 0;
});
}
else {
retracements = levels.map(function (level) {
let calculated = end + Math.abs(start - end) * (level) / 100;
return calculated > 0 ? calculated : 0;
});
}
return retracements;
} | [
"function",
"fibonacciretracement",
"(",
"start",
",",
"end",
")",
"{",
"let",
"levels",
"=",
"[",
"0",
",",
"23.6",
",",
"38.2",
",",
"50",
",",
"61.8",
",",
"78.6",
",",
"100",
",",
"127.2",
",",
"161.8",
",",
"261.8",
",",
"423.6",
"]",
";",
"let",
"retracements",
";",
"if",
"(",
"start",
"<",
"end",
")",
"{",
"retracements",
"=",
"levels",
".",
"map",
"(",
"function",
"(",
"level",
")",
"{",
"let",
"calculated",
"=",
"end",
"-",
"Math",
".",
"abs",
"(",
"start",
"-",
"end",
")",
"*",
"(",
"level",
")",
"/",
"100",
";",
"return",
"calculated",
">",
"0",
"?",
"calculated",
":",
"0",
";",
"}",
")",
";",
"}",
"else",
"{",
"retracements",
"=",
"levels",
".",
"map",
"(",
"function",
"(",
"level",
")",
"{",
"let",
"calculated",
"=",
"end",
"+",
"Math",
".",
"abs",
"(",
"start",
"-",
"end",
")",
"*",
"(",
"level",
")",
"/",
"100",
";",
"return",
"calculated",
">",
"0",
"?",
"calculated",
":",
"0",
";",
"}",
")",
";",
"}",
"return",
"retracements",
";",
"}"
] | Calcaultes the fibonacci retracements for given start and end points
If calculating for up trend start should be low and end should be high and vice versa
returns an array of retracements level containing [0 , 23.6, 38.2, 50, 61.8, 78.6, 100, 127.2, 161.8, 261.8, 423.6]
@export
@param {number} start
@param {number} end
@returns {number[]} | [
"Calcaultes",
"the",
"fibonacci",
"retracements",
"for",
"given",
"start",
"and",
"end",
"points"
] | a2097051c65fe28d24f1e834419b8dda4773fdf7 | https://github.com/anandanand84/technicalindicators/blob/a2097051c65fe28d24f1e834419b8dda4773fdf7/dist/index.js#L3829-L3845 |
7,208 | melonjs/melonJS | src/video/webgl/compositor.js | function (x, y, w, h) {
this.gl.viewport(x, y, w, h);
} | javascript | function (x, y, w, h) {
this.gl.viewport(x, y, w, h);
} | [
"function",
"(",
"x",
",",
"y",
",",
"w",
",",
"h",
")",
"{",
"this",
".",
"gl",
".",
"viewport",
"(",
"x",
",",
"y",
",",
"w",
",",
"h",
")",
";",
"}"
] | Sets the viewport
@name setViewport
@memberOf me.WebGLRenderer.Compositor
@function
@param {Number} x x position of viewport
@param {Number} y y position of viewport
@param {Number} width width of viewport
@param {Number} height height of viewport | [
"Sets",
"the",
"viewport"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/webgl/compositor.js#L234-L236 |
|
7,209 | melonjs/melonJS | src/video/webgl/compositor.js | function (unit, image, filter, repeat, w, h, b, premultipliedAlpha) {
var gl = this.gl;
repeat = repeat || "no-repeat";
var isPOT = me.Math.isPowerOfTwo(w || image.width) && me.Math.isPowerOfTwo(h || image.height);
var texture = gl.createTexture();
var rs = (repeat.search(/^repeat(-x)?$/) === 0) && isPOT ? gl.REPEAT : gl.CLAMP_TO_EDGE;
var rt = (repeat.search(/^repeat(-y)?$/) === 0) && isPOT ? gl.REPEAT : gl.CLAMP_TO_EDGE;
gl.activeTexture(gl.TEXTURE0 + unit);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, rs);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, rt);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, (typeof premultipliedAlpha === "boolean") ? premultipliedAlpha : true);
if (w || h || b) {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w, h, b, gl.RGBA, gl.UNSIGNED_BYTE, image);
}
else {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
}
return texture;
} | javascript | function (unit, image, filter, repeat, w, h, b, premultipliedAlpha) {
var gl = this.gl;
repeat = repeat || "no-repeat";
var isPOT = me.Math.isPowerOfTwo(w || image.width) && me.Math.isPowerOfTwo(h || image.height);
var texture = gl.createTexture();
var rs = (repeat.search(/^repeat(-x)?$/) === 0) && isPOT ? gl.REPEAT : gl.CLAMP_TO_EDGE;
var rt = (repeat.search(/^repeat(-y)?$/) === 0) && isPOT ? gl.REPEAT : gl.CLAMP_TO_EDGE;
gl.activeTexture(gl.TEXTURE0 + unit);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, rs);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, rt);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, (typeof premultipliedAlpha === "boolean") ? premultipliedAlpha : true);
if (w || h || b) {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w, h, b, gl.RGBA, gl.UNSIGNED_BYTE, image);
}
else {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
}
return texture;
} | [
"function",
"(",
"unit",
",",
"image",
",",
"filter",
",",
"repeat",
",",
"w",
",",
"h",
",",
"b",
",",
"premultipliedAlpha",
")",
"{",
"var",
"gl",
"=",
"this",
".",
"gl",
";",
"repeat",
"=",
"repeat",
"||",
"\"no-repeat\"",
";",
"var",
"isPOT",
"=",
"me",
".",
"Math",
".",
"isPowerOfTwo",
"(",
"w",
"||",
"image",
".",
"width",
")",
"&&",
"me",
".",
"Math",
".",
"isPowerOfTwo",
"(",
"h",
"||",
"image",
".",
"height",
")",
";",
"var",
"texture",
"=",
"gl",
".",
"createTexture",
"(",
")",
";",
"var",
"rs",
"=",
"(",
"repeat",
".",
"search",
"(",
"/",
"^repeat(-x)?$",
"/",
")",
"===",
"0",
")",
"&&",
"isPOT",
"?",
"gl",
".",
"REPEAT",
":",
"gl",
".",
"CLAMP_TO_EDGE",
";",
"var",
"rt",
"=",
"(",
"repeat",
".",
"search",
"(",
"/",
"^repeat(-y)?$",
"/",
")",
"===",
"0",
")",
"&&",
"isPOT",
"?",
"gl",
".",
"REPEAT",
":",
"gl",
".",
"CLAMP_TO_EDGE",
";",
"gl",
".",
"activeTexture",
"(",
"gl",
".",
"TEXTURE0",
"+",
"unit",
")",
";",
"gl",
".",
"bindTexture",
"(",
"gl",
".",
"TEXTURE_2D",
",",
"texture",
")",
";",
"gl",
".",
"texParameteri",
"(",
"gl",
".",
"TEXTURE_2D",
",",
"gl",
".",
"TEXTURE_WRAP_S",
",",
"rs",
")",
";",
"gl",
".",
"texParameteri",
"(",
"gl",
".",
"TEXTURE_2D",
",",
"gl",
".",
"TEXTURE_WRAP_T",
",",
"rt",
")",
";",
"gl",
".",
"texParameteri",
"(",
"gl",
".",
"TEXTURE_2D",
",",
"gl",
".",
"TEXTURE_MAG_FILTER",
",",
"filter",
")",
";",
"gl",
".",
"texParameteri",
"(",
"gl",
".",
"TEXTURE_2D",
",",
"gl",
".",
"TEXTURE_MIN_FILTER",
",",
"filter",
")",
";",
"gl",
".",
"pixelStorei",
"(",
"gl",
".",
"UNPACK_PREMULTIPLY_ALPHA_WEBGL",
",",
"(",
"typeof",
"premultipliedAlpha",
"===",
"\"boolean\"",
")",
"?",
"premultipliedAlpha",
":",
"true",
")",
";",
"if",
"(",
"w",
"||",
"h",
"||",
"b",
")",
"{",
"gl",
".",
"texImage2D",
"(",
"gl",
".",
"TEXTURE_2D",
",",
"0",
",",
"gl",
".",
"RGBA",
",",
"w",
",",
"h",
",",
"b",
",",
"gl",
".",
"RGBA",
",",
"gl",
".",
"UNSIGNED_BYTE",
",",
"image",
")",
";",
"}",
"else",
"{",
"gl",
".",
"texImage2D",
"(",
"gl",
".",
"TEXTURE_2D",
",",
"0",
",",
"gl",
".",
"RGBA",
",",
"gl",
".",
"RGBA",
",",
"gl",
".",
"UNSIGNED_BYTE",
",",
"image",
")",
";",
"}",
"return",
"texture",
";",
"}"
] | Create a texture from an image
@name createTexture
@memberOf me.WebGLRenderer.Compositor
@function
@param {Number} unit Destination texture unit
@param {Image|Canvas|ImageData|UInt8Array[]|Float32Array[]} image Source image
@param {Number} filter gl.LINEAR or gl.NEAREST
@param {String} [repeat="no-repeat"] Image repeat behavior (see {@link me.ImageLayer#repeat})
@param {Number} [w] Source image width (Only use with UInt8Array[] or Float32Array[] source image)
@param {Number} [h] Source image height (Only use with UInt8Array[] or Float32Array[] source image)
@param {Number} [b] Source image border (Only use with UInt8Array[] or Float32Array[] source image)
@param {Number} [b] Source image border (Only use with UInt8Array[] or Float32Array[] source image)
@param {Boolean} [premultipliedAlpha=true] Multiplies the alpha channel into the other color channels
@return {WebGLTexture} A texture object | [
"Create",
"a",
"texture",
"from",
"an",
"image"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/webgl/compositor.js#L254-L279 |
|
7,210 | melonjs/melonJS | src/video/webgl/compositor.js | function () {
var indices = [
0, 1, 2,
2, 1, 3
];
// ~384KB index buffer
var data = new Array(MAX_LENGTH * INDICES_PER_QUAD);
for (var i = 0; i < data.length; i++) {
data[i] = indices[i % INDICES_PER_QUAD] +
~~(i / INDICES_PER_QUAD) * ELEMENTS_PER_QUAD;
}
return new Uint16Array(data);
} | javascript | function () {
var indices = [
0, 1, 2,
2, 1, 3
];
// ~384KB index buffer
var data = new Array(MAX_LENGTH * INDICES_PER_QUAD);
for (var i = 0; i < data.length; i++) {
data[i] = indices[i % INDICES_PER_QUAD] +
~~(i / INDICES_PER_QUAD) * ELEMENTS_PER_QUAD;
}
return new Uint16Array(data);
} | [
"function",
"(",
")",
"{",
"var",
"indices",
"=",
"[",
"0",
",",
"1",
",",
"2",
",",
"2",
",",
"1",
",",
"3",
"]",
";",
"// ~384KB index buffer",
"var",
"data",
"=",
"new",
"Array",
"(",
"MAX_LENGTH",
"*",
"INDICES_PER_QUAD",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"data",
".",
"length",
";",
"i",
"++",
")",
"{",
"data",
"[",
"i",
"]",
"=",
"indices",
"[",
"i",
"%",
"INDICES_PER_QUAD",
"]",
"+",
"~",
"~",
"(",
"i",
"/",
"INDICES_PER_QUAD",
")",
"*",
"ELEMENTS_PER_QUAD",
";",
"}",
"return",
"new",
"Uint16Array",
"(",
"data",
")",
";",
"}"
] | Create a full index buffer for the element array
@ignore | [
"Create",
"a",
"full",
"index",
"buffer",
"for",
"the",
"element",
"array"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/webgl/compositor.js#L307-L321 |
|
7,211 | melonjs/melonJS | src/video/webgl/compositor.js | function () {
this.sbSize <<= 1;
var stream = new Float32Array(this.sbSize * ELEMENT_SIZE * ELEMENTS_PER_QUAD);
stream.set(this.stream);
this.stream = stream;
} | javascript | function () {
this.sbSize <<= 1;
var stream = new Float32Array(this.sbSize * ELEMENT_SIZE * ELEMENTS_PER_QUAD);
stream.set(this.stream);
this.stream = stream;
} | [
"function",
"(",
")",
"{",
"this",
".",
"sbSize",
"<<=",
"1",
";",
"var",
"stream",
"=",
"new",
"Float32Array",
"(",
"this",
".",
"sbSize",
"*",
"ELEMENT_SIZE",
"*",
"ELEMENTS_PER_QUAD",
")",
";",
"stream",
".",
"set",
"(",
"this",
".",
"stream",
")",
";",
"this",
".",
"stream",
"=",
"stream",
";",
"}"
] | Resize the stream buffer, retaining its original contents
@ignore | [
"Resize",
"the",
"stream",
"buffer",
"retaining",
"its",
"original",
"contents"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/webgl/compositor.js#L327-L332 |
|
7,212 | melonjs/melonJS | src/video/webgl/compositor.js | function () {
if (this.length) {
var gl = this.gl;
// Copy data into stream buffer
var len = this.length * ELEMENT_SIZE * ELEMENTS_PER_QUAD;
gl.bufferData(
gl.ARRAY_BUFFER,
this.stream.subarray(0, len),
gl.STREAM_DRAW
);
// Draw the stream buffer
gl.drawElements(
gl.TRIANGLES,
this.length * INDICES_PER_QUAD,
gl.UNSIGNED_SHORT,
0
);
this.sbIndex = 0;
this.length = 0;
}
} | javascript | function () {
if (this.length) {
var gl = this.gl;
// Copy data into stream buffer
var len = this.length * ELEMENT_SIZE * ELEMENTS_PER_QUAD;
gl.bufferData(
gl.ARRAY_BUFFER,
this.stream.subarray(0, len),
gl.STREAM_DRAW
);
// Draw the stream buffer
gl.drawElements(
gl.TRIANGLES,
this.length * INDICES_PER_QUAD,
gl.UNSIGNED_SHORT,
0
);
this.sbIndex = 0;
this.length = 0;
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"length",
")",
"{",
"var",
"gl",
"=",
"this",
".",
"gl",
";",
"// Copy data into stream buffer",
"var",
"len",
"=",
"this",
".",
"length",
"*",
"ELEMENT_SIZE",
"*",
"ELEMENTS_PER_QUAD",
";",
"gl",
".",
"bufferData",
"(",
"gl",
".",
"ARRAY_BUFFER",
",",
"this",
".",
"stream",
".",
"subarray",
"(",
"0",
",",
"len",
")",
",",
"gl",
".",
"STREAM_DRAW",
")",
";",
"// Draw the stream buffer",
"gl",
".",
"drawElements",
"(",
"gl",
".",
"TRIANGLES",
",",
"this",
".",
"length",
"*",
"INDICES_PER_QUAD",
",",
"gl",
".",
"UNSIGNED_SHORT",
",",
"0",
")",
";",
"this",
".",
"sbIndex",
"=",
"0",
";",
"this",
".",
"length",
"=",
"0",
";",
"}",
"}"
] | Flush batched texture operations to the GPU
@name flush
@memberOf me.WebGLRenderer.Compositor
@function | [
"Flush",
"batched",
"texture",
"operations",
"to",
"the",
"GPU"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/webgl/compositor.js#L452-L475 |
|
7,213 | melonjs/melonJS | src/video/canvas/canvas_renderer.js | function (col, opaque) {
this.save();
this.resetTransform();
this.backBufferContext2D.globalCompositeOperation = opaque ? "copy" : "source-over";
this.backBufferContext2D.fillStyle = (col instanceof me.Color) ? col.toRGBA() : col;
this.fillRect(0, 0, this.backBufferCanvas.width, this.backBufferCanvas.height);
this.restore();
} | javascript | function (col, opaque) {
this.save();
this.resetTransform();
this.backBufferContext2D.globalCompositeOperation = opaque ? "copy" : "source-over";
this.backBufferContext2D.fillStyle = (col instanceof me.Color) ? col.toRGBA() : col;
this.fillRect(0, 0, this.backBufferCanvas.width, this.backBufferCanvas.height);
this.restore();
} | [
"function",
"(",
"col",
",",
"opaque",
")",
"{",
"this",
".",
"save",
"(",
")",
";",
"this",
".",
"resetTransform",
"(",
")",
";",
"this",
".",
"backBufferContext2D",
".",
"globalCompositeOperation",
"=",
"opaque",
"?",
"\"copy\"",
":",
"\"source-over\"",
";",
"this",
".",
"backBufferContext2D",
".",
"fillStyle",
"=",
"(",
"col",
"instanceof",
"me",
".",
"Color",
")",
"?",
"col",
".",
"toRGBA",
"(",
")",
":",
"col",
";",
"this",
".",
"fillRect",
"(",
"0",
",",
"0",
",",
"this",
".",
"backBufferCanvas",
".",
"width",
",",
"this",
".",
"backBufferCanvas",
".",
"height",
")",
";",
"this",
".",
"restore",
"(",
")",
";",
"}"
] | Clears the main framebuffer with the given color
@name clearColor
@memberOf me.CanvasRenderer.prototype
@function
@param {me.Color|String} color CSS color.
@param {Boolean} [opaque=false] Allow transparency [default] or clear the surface completely [true] | [
"Clears",
"the",
"main",
"framebuffer",
"with",
"the",
"given",
"color"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/canvas/canvas_renderer.js#L139-L146 |
|
7,214 | melonjs/melonJS | src/video/canvas/canvas_renderer.js | function (image, sx, sy, sw, sh, dx, dy, dw, dh) {
if (this.backBufferContext2D.globalAlpha < 1 / 255) {
// Fast path: don't draw fully transparent
return;
}
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;
}
this.backBufferContext2D.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh);
} | javascript | function (image, sx, sy, sw, sh, dx, dy, dw, dh) {
if (this.backBufferContext2D.globalAlpha < 1 / 255) {
// Fast path: don't draw fully transparent
return;
}
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;
}
this.backBufferContext2D.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh);
} | [
"function",
"(",
"image",
",",
"sx",
",",
"sy",
",",
"sw",
",",
"sh",
",",
"dx",
",",
"dy",
",",
"dw",
",",
"dh",
")",
"{",
"if",
"(",
"this",
".",
"backBufferContext2D",
".",
"globalAlpha",
"<",
"1",
"/",
"255",
")",
"{",
"// Fast path: don't draw fully transparent",
"return",
";",
"}",
"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",
";",
"}",
"this",
".",
"backBufferContext2D",
".",
"drawImage",
"(",
"image",
",",
"sx",
",",
"sy",
",",
"sw",
",",
"sh",
",",
"dx",
",",
"dy",
",",
"dw",
",",
"dh",
")",
";",
"}"
] | Draw an image onto the main using the canvas api
@name drawImage
@memberOf me.CanvasRenderer.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",
"onto",
"the",
"main",
"using",
"the",
"canvas",
"api"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/canvas/canvas_renderer.js#L203-L235 |
|
7,215 | melonjs/melonJS | src/video/canvas/canvas_renderer.js | function (x, y, w, h) {
this.strokeEllipse(x, y, w, h, true);
} | javascript | function (x, y, w, h) {
this.strokeEllipse(x, y, w, h, true);
} | [
"function",
"(",
"x",
",",
"y",
",",
"w",
",",
"h",
")",
"{",
"this",
".",
"strokeEllipse",
"(",
"x",
",",
"y",
",",
"w",
",",
"h",
",",
"true",
")",
";",
"}"
] | Fill an ellipse at the specified coordinates with given radius
@name fillEllipse
@memberOf me.CanvasRenderer.prototype
@function
@param {Number} x ellipse center point x-axis
@param {Number} y ellipse center point y-axis
@param {Number} w horizontal radius of the ellipse
@param {Number} h vertical radius of the ellipse | [
"Fill",
"an",
"ellipse",
"at",
"the",
"specified",
"coordinates",
"with",
"given",
"radius"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/canvas/canvas_renderer.js#L355-L357 |
|
7,216 | melonjs/melonJS | src/video/canvas/canvas_renderer.js | function (poly, fill) {
var context = this.backBufferContext2D;
if (context.globalAlpha < 1 / 255) {
// Fast path: don't draw fully transparent
return;
}
this.translate(poly.pos.x, poly.pos.y);
context.beginPath();
context.moveTo(poly.points[0].x, poly.points[0].y);
var point;
for (var i = 1; i < poly.points.length; i++) {
point = poly.points[i];
context.lineTo(point.x, point.y);
}
context.lineTo(poly.points[0].x, poly.points[0].y);
context[fill === true ? "fill" : "stroke"]();
context.closePath();
this.translate(-poly.pos.x, -poly.pos.y);
} | javascript | function (poly, fill) {
var context = this.backBufferContext2D;
if (context.globalAlpha < 1 / 255) {
// Fast path: don't draw fully transparent
return;
}
this.translate(poly.pos.x, poly.pos.y);
context.beginPath();
context.moveTo(poly.points[0].x, poly.points[0].y);
var point;
for (var i = 1; i < poly.points.length; i++) {
point = poly.points[i];
context.lineTo(point.x, point.y);
}
context.lineTo(poly.points[0].x, poly.points[0].y);
context[fill === true ? "fill" : "stroke"]();
context.closePath();
this.translate(-poly.pos.x, -poly.pos.y);
} | [
"function",
"(",
"poly",
",",
"fill",
")",
"{",
"var",
"context",
"=",
"this",
".",
"backBufferContext2D",
";",
"if",
"(",
"context",
".",
"globalAlpha",
"<",
"1",
"/",
"255",
")",
"{",
"// Fast path: don't draw fully transparent",
"return",
";",
"}",
"this",
".",
"translate",
"(",
"poly",
".",
"pos",
".",
"x",
",",
"poly",
".",
"pos",
".",
"y",
")",
";",
"context",
".",
"beginPath",
"(",
")",
";",
"context",
".",
"moveTo",
"(",
"poly",
".",
"points",
"[",
"0",
"]",
".",
"x",
",",
"poly",
".",
"points",
"[",
"0",
"]",
".",
"y",
")",
";",
"var",
"point",
";",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<",
"poly",
".",
"points",
".",
"length",
";",
"i",
"++",
")",
"{",
"point",
"=",
"poly",
".",
"points",
"[",
"i",
"]",
";",
"context",
".",
"lineTo",
"(",
"point",
".",
"x",
",",
"point",
".",
"y",
")",
";",
"}",
"context",
".",
"lineTo",
"(",
"poly",
".",
"points",
"[",
"0",
"]",
".",
"x",
",",
"poly",
".",
"points",
"[",
"0",
"]",
".",
"y",
")",
";",
"context",
"[",
"fill",
"===",
"true",
"?",
"\"fill\"",
":",
"\"stroke\"",
"]",
"(",
")",
";",
"context",
".",
"closePath",
"(",
")",
";",
"this",
".",
"translate",
"(",
"-",
"poly",
".",
"pos",
".",
"x",
",",
"-",
"poly",
".",
"pos",
".",
"y",
")",
";",
"}"
] | Stroke the given me.Polygon on the screen
@name strokePolygon
@memberOf me.CanvasRenderer.prototype
@function
@param {me.Polygon} poly the shape to draw | [
"Stroke",
"the",
"given",
"me",
".",
"Polygon",
"on",
"the",
"screen"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/canvas/canvas_renderer.js#L404-L424 |
|
7,217 | melonjs/melonJS | src/video/canvas/canvas_renderer.js | function (x, y) {
if (this.settings.subPixel === false) {
this.backBufferContext2D.translate(~~x, ~~y);
} else {
this.backBufferContext2D.translate(x, y);
}
} | javascript | function (x, y) {
if (this.settings.subPixel === false) {
this.backBufferContext2D.translate(~~x, ~~y);
} else {
this.backBufferContext2D.translate(x, y);
}
} | [
"function",
"(",
"x",
",",
"y",
")",
"{",
"if",
"(",
"this",
".",
"settings",
".",
"subPixel",
"===",
"false",
")",
"{",
"this",
".",
"backBufferContext2D",
".",
"translate",
"(",
"~",
"~",
"x",
",",
"~",
"~",
"y",
")",
";",
"}",
"else",
"{",
"this",
".",
"backBufferContext2D",
".",
"translate",
"(",
"x",
",",
"y",
")",
";",
"}",
"}"
] | Translates the context to the given position
@name translate
@memberOf me.CanvasRenderer.prototype
@function
@param {Number} x
@param {Number} y | [
"Translates",
"the",
"context",
"to",
"the",
"given",
"position"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/canvas/canvas_renderer.js#L629-L635 |
|
7,218 | melonjs/melonJS | src/level/tiled/TMXTileset.js | function (renderer, dx, dy, tmxTile) {
// check if any transformation is required
if (tmxTile.flipped) {
renderer.save();
// apply the tile current transform
renderer.translate(dx, dy);
renderer.transform(tmxTile.currentTransform);
// reset both values as managed through transform();
dx = dy = 0;
}
// check if the tile has an associated image
if (this.isCollection === true) {
// draw the tile
renderer.drawImage(
this.imageCollection[tmxTile.tileId],
0, 0,
tmxTile.width, tmxTile.height,
dx, dy,
tmxTile.width, tmxTile.height
);
} else {
// use the tileset texture
var offset = this.atlas[this.getViewTileId(tmxTile.tileId)].offset;
// draw the tile
renderer.drawImage(
this.image,
offset.x, offset.y,
this.tilewidth, this.tileheight,
dx, dy,
this.tilewidth + renderer.uvOffset, this.tileheight + renderer.uvOffset
);
}
if (tmxTile.flipped) {
// restore the context to the previous state
renderer.restore();
}
} | javascript | function (renderer, dx, dy, tmxTile) {
// check if any transformation is required
if (tmxTile.flipped) {
renderer.save();
// apply the tile current transform
renderer.translate(dx, dy);
renderer.transform(tmxTile.currentTransform);
// reset both values as managed through transform();
dx = dy = 0;
}
// check if the tile has an associated image
if (this.isCollection === true) {
// draw the tile
renderer.drawImage(
this.imageCollection[tmxTile.tileId],
0, 0,
tmxTile.width, tmxTile.height,
dx, dy,
tmxTile.width, tmxTile.height
);
} else {
// use the tileset texture
var offset = this.atlas[this.getViewTileId(tmxTile.tileId)].offset;
// draw the tile
renderer.drawImage(
this.image,
offset.x, offset.y,
this.tilewidth, this.tileheight,
dx, dy,
this.tilewidth + renderer.uvOffset, this.tileheight + renderer.uvOffset
);
}
if (tmxTile.flipped) {
// restore the context to the previous state
renderer.restore();
}
} | [
"function",
"(",
"renderer",
",",
"dx",
",",
"dy",
",",
"tmxTile",
")",
"{",
"// check if any transformation is required",
"if",
"(",
"tmxTile",
".",
"flipped",
")",
"{",
"renderer",
".",
"save",
"(",
")",
";",
"// apply the tile current transform",
"renderer",
".",
"translate",
"(",
"dx",
",",
"dy",
")",
";",
"renderer",
".",
"transform",
"(",
"tmxTile",
".",
"currentTransform",
")",
";",
"// reset both values as managed through transform();",
"dx",
"=",
"dy",
"=",
"0",
";",
"}",
"// check if the tile has an associated image",
"if",
"(",
"this",
".",
"isCollection",
"===",
"true",
")",
"{",
"// draw the tile",
"renderer",
".",
"drawImage",
"(",
"this",
".",
"imageCollection",
"[",
"tmxTile",
".",
"tileId",
"]",
",",
"0",
",",
"0",
",",
"tmxTile",
".",
"width",
",",
"tmxTile",
".",
"height",
",",
"dx",
",",
"dy",
",",
"tmxTile",
".",
"width",
",",
"tmxTile",
".",
"height",
")",
";",
"}",
"else",
"{",
"// use the tileset texture",
"var",
"offset",
"=",
"this",
".",
"atlas",
"[",
"this",
".",
"getViewTileId",
"(",
"tmxTile",
".",
"tileId",
")",
"]",
".",
"offset",
";",
"// draw the tile",
"renderer",
".",
"drawImage",
"(",
"this",
".",
"image",
",",
"offset",
".",
"x",
",",
"offset",
".",
"y",
",",
"this",
".",
"tilewidth",
",",
"this",
".",
"tileheight",
",",
"dx",
",",
"dy",
",",
"this",
".",
"tilewidth",
"+",
"renderer",
".",
"uvOffset",
",",
"this",
".",
"tileheight",
"+",
"renderer",
".",
"uvOffset",
")",
";",
"}",
"if",
"(",
"tmxTile",
".",
"flipped",
")",
"{",
"// restore the context to the previous state",
"renderer",
".",
"restore",
"(",
")",
";",
"}",
"}"
] | draw the x,y tile | [
"draw",
"the",
"x",
"y",
"tile"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/level/tiled/TMXTileset.js#L256-L295 |
|
7,219 | melonjs/melonJS | tasks/jsdoc-template/publish.js | 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) {
fs.mkdirSync(dest);
}
fs.readdirSync(src).forEach(function(childItemName) {
copyRecursiveSync(path.join(src, childItemName),
path.join(dest, childItemName));
});
} else {
contents = fs.readFileSync(src);
fs.writeFileSync(dest, contents);
}
}
} | javascript | 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) {
fs.mkdirSync(dest);
}
fs.readdirSync(src).forEach(function(childItemName) {
copyRecursiveSync(path.join(src, childItemName),
path.join(dest, childItemName));
});
} else {
contents = fs.readFileSync(src);
fs.writeFileSync(dest, contents);
}
}
} | [
"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",
")",
"{",
"fs",
".",
"mkdirSync",
"(",
"dest",
")",
";",
"}",
"fs",
".",
"readdirSync",
"(",
"src",
")",
".",
"forEach",
"(",
"function",
"(",
"childItemName",
")",
"{",
"copyRecursiveSync",
"(",
"path",
".",
"join",
"(",
"src",
",",
"childItemName",
")",
",",
"path",
".",
"join",
"(",
"dest",
",",
"childItemName",
")",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"contents",
"=",
"fs",
".",
"readFileSync",
"(",
"src",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"dest",
",",
"contents",
")",
";",
"}",
"}",
"}"
] | Look ma, it's cp -R.
@param {string} src The path to the thing to copy.
@param {string} dest The path to the new copy. | [
"Look",
"ma",
"it",
"s",
"cp",
"-",
"R",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/tasks/jsdoc-template/publish.js#L504-L525 |
|
7,220 | melonjs/melonJS | src/font/bitmaptextdata.js | 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[spaceCharCode] = glyph;
}
} | javascript | 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[spaceCharCode] = glyph;
}
} | [
"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",
"[",
"spaceCharCode",
"]",
"=",
"glyph",
";",
"}",
"}"
] | Creates a glyph to use for the space character
@private
@name _createSpaceGlyph
@memberOf me.BitmapTextData
@function | [
"Creates",
"a",
"glyph",
"to",
"use",
"for",
"the",
"space",
"character"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/font/bitmaptextdata.js#L103-L112 |
|
7,221 | melonjs/melonJS | src/physics/body.js | 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) {
this.vel.x = ~~(0.5 + this.vel.x - overlap.x) || 0;
if (this.bounce > 0) {
this.vel.x *= -this.bounce;
}
}
if (overlap.y !== 0) {
this.vel.y = ~~(0.5 + this.vel.y - overlap.y) || 0;
if (this.bounce > 0) {
this.vel.y *= -this.bounce;
}
// cancel the falling an jumping flags if necessary
var dir = Math.sign(this.gravity.y) || 1;
this.falling = overlap.y >= dir;
this.jumping = overlap.y <= -dir;
}
} | javascript | 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) {
this.vel.x = ~~(0.5 + this.vel.x - overlap.x) || 0;
if (this.bounce > 0) {
this.vel.x *= -this.bounce;
}
}
if (overlap.y !== 0) {
this.vel.y = ~~(0.5 + this.vel.y - overlap.y) || 0;
if (this.bounce > 0) {
this.vel.y *= -this.bounce;
}
// cancel the falling an jumping flags if necessary
var dir = Math.sign(this.gravity.y) || 1;
this.falling = overlap.y >= dir;
this.jumping = overlap.y <= -dir;
}
} | [
"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",
")",
"{",
"this",
".",
"vel",
".",
"x",
"=",
"~",
"~",
"(",
"0.5",
"+",
"this",
".",
"vel",
".",
"x",
"-",
"overlap",
".",
"x",
")",
"||",
"0",
";",
"if",
"(",
"this",
".",
"bounce",
">",
"0",
")",
"{",
"this",
".",
"vel",
".",
"x",
"*=",
"-",
"this",
".",
"bounce",
";",
"}",
"}",
"if",
"(",
"overlap",
".",
"y",
"!==",
"0",
")",
"{",
"this",
".",
"vel",
".",
"y",
"=",
"~",
"~",
"(",
"0.5",
"+",
"this",
".",
"vel",
".",
"y",
"-",
"overlap",
".",
"y",
")",
"||",
"0",
";",
"if",
"(",
"this",
".",
"bounce",
">",
"0",
")",
"{",
"this",
".",
"vel",
".",
"y",
"*=",
"-",
"this",
".",
"bounce",
";",
"}",
"// cancel the falling an jumping flags if necessary",
"var",
"dir",
"=",
"Math",
".",
"sign",
"(",
"this",
".",
"gravity",
".",
"y",
")",
"||",
"1",
";",
"this",
".",
"falling",
"=",
"overlap",
".",
"y",
">=",
"dir",
";",
"this",
".",
"jumping",
"=",
"overlap",
".",
"y",
"<=",
"-",
"dir",
";",
"}",
"}"
] | the built-in function to solve the collision response
@protected
@name respondToCollision
@memberOf me.Body
@function
@param {me.collision.ResponseObject} response the collision response object | [
"the",
"built",
"-",
"in",
"function",
"to",
"solve",
"the",
"collision",
"response"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/physics/body.js#L444-L471 |
|
7,222 | melonjs/melonJS | src/physics/body.js | 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 :
( x > 0) ? x : 0
);
vel.y = (
(ny < 0) ? ny :
( y > 0) ? y : 0
);
} | javascript | 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 :
( x > 0) ? x : 0
);
vel.y = (
(ny < 0) ? ny :
( y > 0) ? y : 0
);
} | [
"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",
":",
"(",
"x",
">",
"0",
")",
"?",
"x",
":",
"0",
")",
";",
"vel",
".",
"y",
"=",
"(",
"(",
"ny",
"<",
"0",
")",
"?",
"ny",
":",
"(",
"y",
">",
"0",
")",
"?",
"y",
":",
"0",
")",
";",
"}"
] | apply friction to a vector
@ignore | [
"apply",
"friction",
"to",
"a",
"vector"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/physics/body.js#L555-L571 |
|
7,223 | melonjs/melonJS | src/entity/draggable.js | function (e) {
if (this.dragging === false) {
this.dragging = true;
this.grabOffset.set(e.gameX, e.gameY);
this.grabOffset.sub(this.pos);
return false;
}
} | javascript | function (e) {
if (this.dragging === false) {
this.dragging = true;
this.grabOffset.set(e.gameX, e.gameY);
this.grabOffset.sub(this.pos);
return false;
}
} | [
"function",
"(",
"e",
")",
"{",
"if",
"(",
"this",
".",
"dragging",
"===",
"false",
")",
"{",
"this",
".",
"dragging",
"=",
"true",
";",
"this",
".",
"grabOffset",
".",
"set",
"(",
"e",
".",
"gameX",
",",
"e",
".",
"gameY",
")",
";",
"this",
".",
"grabOffset",
".",
"sub",
"(",
"this",
".",
"pos",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Gets called when the user starts dragging the entity
@name dragStart
@memberOf me.DraggableEntity
@function
@param {Object} x the pointer event | [
"Gets",
"called",
"when",
"the",
"user",
"starts",
"dragging",
"the",
"entity"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/entity/draggable.js#L92-L99 |
|
7,224 | melonjs/melonJS | src/entity/draggable.js | function (e) {
if (this.dragging === true) {
this.pos.set(e.gameX, e.gameY, this.pos.z); //TODO : z ?
this.pos.sub(this.grabOffset);
}
} | javascript | function (e) {
if (this.dragging === true) {
this.pos.set(e.gameX, e.gameY, this.pos.z); //TODO : z ?
this.pos.sub(this.grabOffset);
}
} | [
"function",
"(",
"e",
")",
"{",
"if",
"(",
"this",
".",
"dragging",
"===",
"true",
")",
"{",
"this",
".",
"pos",
".",
"set",
"(",
"e",
".",
"gameX",
",",
"e",
".",
"gameY",
",",
"this",
".",
"pos",
".",
"z",
")",
";",
"//TODO : z ?",
"this",
".",
"pos",
".",
"sub",
"(",
"this",
".",
"grabOffset",
")",
";",
"}",
"}"
] | Gets called when the user drags this entity around
@name dragMove
@memberOf me.DraggableEntity
@function
@param {Object} x the pointer event | [
"Gets",
"called",
"when",
"the",
"user",
"drags",
"this",
"entity",
"around"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/entity/draggable.js#L108-L113 |
|
7,225 | melonjs/melonJS | src/utils/color.js | 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 = alpha;
return this;
} | javascript | 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 = alpha;
return this;
} | [
"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",
"=",
"alpha",
";",
"return",
"this",
";",
"}"
] | Set this color to the specified value.
@name setColor
@memberOf me.Color
@function
@param {Number} r red component [0 .. 255]
@param {Number} g green component [0 .. 255]
@param {Number} b blue component [0 .. 255]
@param {Number} [alpha=1.0] alpha value [0.0 .. 1.0]
@return {me.Color} Reference to this object for method chaining | [
"Set",
"this",
"color",
"to",
"the",
"specified",
"value",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/utils/color.js#L213-L224 |
|
7,226 | melonjs/melonJS | src/utils/color.js | function (color) {
if (color instanceof me.Color) {
this.glArray.set(color.glArray);
return this;
}
return this.parseCSS(color);
} | javascript | function (color) {
if (color instanceof me.Color) {
this.glArray.set(color.glArray);
return this;
}
return this.parseCSS(color);
} | [
"function",
"(",
"color",
")",
"{",
"if",
"(",
"color",
"instanceof",
"me",
".",
"Color",
")",
"{",
"this",
".",
"glArray",
".",
"set",
"(",
"color",
".",
"glArray",
")",
";",
"return",
"this",
";",
"}",
"return",
"this",
".",
"parseCSS",
"(",
"color",
")",
";",
"}"
] | Copy a color object or CSS color into this one.
@name copy
@memberOf me.Color
@function
@param {me.Color|String} color
@return {me.Color} Reference to this object for method chaining | [
"Copy",
"a",
"color",
"object",
"or",
"CSS",
"color",
"into",
"this",
"one",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/utils/color.js#L245-L252 |
|
7,227 | melonjs/melonJS | src/utils/color.js | 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.glArray[3] + color.glArray[3]) / 2;
return this;
} | javascript | 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.glArray[3] + color.glArray[3]) / 2;
return this;
} | [
"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",
".",
"glArray",
"[",
"3",
"]",
"+",
"color",
".",
"glArray",
"[",
"3",
"]",
")",
"/",
"2",
";",
"return",
"this",
";",
"}"
] | Blend this color with the given one using addition.
@name add
@memberOf me.Color
@function
@param {me.Color} color
@return {me.Color} Reference to this object for method chaining | [
"Blend",
"this",
"color",
"with",
"the",
"given",
"one",
"using",
"addition",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/utils/color.js#L262-L269 |
|
7,228 | melonjs/melonJS | src/utils/color.js | function (scale) {
scale = me.Math.clamp(scale, 0, 1);
this.glArray[0] *= scale;
this.glArray[1] *= scale;
this.glArray[2] *= scale;
return this;
} | javascript | function (scale) {
scale = me.Math.clamp(scale, 0, 1);
this.glArray[0] *= scale;
this.glArray[1] *= scale;
this.glArray[2] *= scale;
return this;
} | [
"function",
"(",
"scale",
")",
"{",
"scale",
"=",
"me",
".",
"Math",
".",
"clamp",
"(",
"scale",
",",
"0",
",",
"1",
")",
";",
"this",
".",
"glArray",
"[",
"0",
"]",
"*=",
"scale",
";",
"this",
".",
"glArray",
"[",
"1",
"]",
"*=",
"scale",
";",
"this",
".",
"glArray",
"[",
"2",
"]",
"*=",
"scale",
";",
"return",
"this",
";",
"}"
] | Darken this color value by 0..1
@name darken
@memberOf me.Color
@function
@param {Number} scale
@return {me.Color} Reference to this object for method chaining | [
"Darken",
"this",
"color",
"value",
"by",
"0",
"..",
"1"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/utils/color.js#L279-L286 |
|
7,229 | melonjs/melonJS | src/utils/color.js | 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 | 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);
} | [
"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",
")",
";",
"}"
] | Parse a CSS color string and set this color to the corresponding
r,g,b values
@name parseCSS
@memberOf me.Color
@function
@param {String} color
@return {me.Color} Reference to this object for method chaining | [
"Parse",
"a",
"CSS",
"color",
"string",
"and",
"set",
"this",
"color",
"to",
"the",
"corresponding",
"r",
"g",
"b",
"values"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/utils/color.js#L348-L356 |
|
7,230 | melonjs/melonJS | src/utils/color.js | 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 | 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);
} | [
"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",
")",
";",
"}"
] | Parse an RGB or RGBA CSS color string
@name parseRGB
@memberOf me.Color
@function
@param {String} color
@return {me.Color} Reference to this object for method chaining | [
"Parse",
"an",
"RGB",
"or",
"RGBA",
"CSS",
"color",
"string"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/utils/color.js#L366-L375 |
|
7,231 | melonjs/melonJS | src/level/tiled/TMXTiledMap.js | readLayer | 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 | 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;
} | [
"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",
";",
"}"
] | read the layer Data
@ignore | [
"read",
"the",
"layer",
"Data"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/level/tiled/TMXTiledMap.js#L35-L40 |
7,232 | melonjs/melonJS | src/level/tiled/TMXTiledMap.js | readImageLayer | 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 || +data.x || 0,
+data.offsety || +data.y || 0,
Object.assign({
name: data.name,
image: data.image,
z: z
}, data.properties)
);
// set some additional flags
var visible = typeof(data.visible) !== "undefined" ? data.visible : true;
imageLayer.setOpacity(visible ? +data.opacity : 0);
return imageLayer;
} | javascript | 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 || +data.x || 0,
+data.offsety || +data.y || 0,
Object.assign({
name: data.name,
image: data.image,
z: z
}, data.properties)
);
// set some additional flags
var visible = typeof(data.visible) !== "undefined" ? data.visible : true;
imageLayer.setOpacity(visible ? +data.opacity : 0);
return imageLayer;
} | [
"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",
"||",
"+",
"data",
".",
"x",
"||",
"0",
",",
"+",
"data",
".",
"offsety",
"||",
"+",
"data",
".",
"y",
"||",
"0",
",",
"Object",
".",
"assign",
"(",
"{",
"name",
":",
"data",
".",
"name",
",",
"image",
":",
"data",
".",
"image",
",",
"z",
":",
"z",
"}",
",",
"data",
".",
"properties",
")",
")",
";",
"// set some additional flags",
"var",
"visible",
"=",
"typeof",
"(",
"data",
".",
"visible",
")",
"!==",
"\"undefined\"",
"?",
"data",
".",
"visible",
":",
"true",
";",
"imageLayer",
".",
"setOpacity",
"(",
"visible",
"?",
"+",
"data",
".",
"opacity",
":",
"0",
")",
";",
"return",
"imageLayer",
";",
"}"
] | read the Image Layer Data
@ignore | [
"read",
"the",
"Image",
"Layer",
"Data"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/level/tiled/TMXTiledMap.js#L46-L67 |
7,233 | melonjs/melonJS | src/level/tiled/TMXTiledMap.js | 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 TilesetGroup Object
this.tilesets = new me.TMXTilesetGroup();
}
// parse all tileset objects
if (typeof (data.tilesets) !== "undefined") {
var tilesets = data.tilesets;
tilesets.forEach(function (tileset) {
// add the new tileset
self.tilesets.add(readTileset(tileset));
});
}
// check if a user-defined background color is defined
if (this.backgroundcolor) {
this.layers.push(
me.pool.pull("me.ColorLayer",
"background_color",
this.backgroundcolor,
zOrder++
)
);
}
// check if a background image is defined
if (this.background_image) {
// add a new image layer
this.layers.push(
me.pool.pull("me.ImageLayer",
0, 0, {
name : "background_image",
image : this.background_image,
z : zOrder++
}
));
}
data.layers.forEach(function (layer) {
switch (layer.type) {
case "imagelayer":
self.layers.push(readImageLayer(self, layer, zOrder++));
break;
case "tilelayer":
self.layers.push(readLayer(self, layer, zOrder++));
break;
// get the object groups information
case "objectgroup":
self.objectGroups.push(readObjectGroup(self, layer, zOrder++));
break;
// get the object groups information
case "group":
self.objectGroups.push(readObjectGroup(self, layer, zOrder++));
break;
default:
break;
}
});
this.initialized = true;
} | javascript | 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 TilesetGroup Object
this.tilesets = new me.TMXTilesetGroup();
}
// parse all tileset objects
if (typeof (data.tilesets) !== "undefined") {
var tilesets = data.tilesets;
tilesets.forEach(function (tileset) {
// add the new tileset
self.tilesets.add(readTileset(tileset));
});
}
// check if a user-defined background color is defined
if (this.backgroundcolor) {
this.layers.push(
me.pool.pull("me.ColorLayer",
"background_color",
this.backgroundcolor,
zOrder++
)
);
}
// check if a background image is defined
if (this.background_image) {
// add a new image layer
this.layers.push(
me.pool.pull("me.ImageLayer",
0, 0, {
name : "background_image",
image : this.background_image,
z : zOrder++
}
));
}
data.layers.forEach(function (layer) {
switch (layer.type) {
case "imagelayer":
self.layers.push(readImageLayer(self, layer, zOrder++));
break;
case "tilelayer":
self.layers.push(readLayer(self, layer, zOrder++));
break;
// get the object groups information
case "objectgroup":
self.objectGroups.push(readObjectGroup(self, layer, zOrder++));
break;
// get the object groups information
case "group":
self.objectGroups.push(readObjectGroup(self, layer, zOrder++));
break;
default:
break;
}
});
this.initialized = true;
} | [
"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 TilesetGroup Object",
"this",
".",
"tilesets",
"=",
"new",
"me",
".",
"TMXTilesetGroup",
"(",
")",
";",
"}",
"// parse all tileset objects",
"if",
"(",
"typeof",
"(",
"data",
".",
"tilesets",
")",
"!==",
"\"undefined\"",
")",
"{",
"var",
"tilesets",
"=",
"data",
".",
"tilesets",
";",
"tilesets",
".",
"forEach",
"(",
"function",
"(",
"tileset",
")",
"{",
"// add the new tileset",
"self",
".",
"tilesets",
".",
"add",
"(",
"readTileset",
"(",
"tileset",
")",
")",
";",
"}",
")",
";",
"}",
"// check if a user-defined background color is defined",
"if",
"(",
"this",
".",
"backgroundcolor",
")",
"{",
"this",
".",
"layers",
".",
"push",
"(",
"me",
".",
"pool",
".",
"pull",
"(",
"\"me.ColorLayer\"",
",",
"\"background_color\"",
",",
"this",
".",
"backgroundcolor",
",",
"zOrder",
"++",
")",
")",
";",
"}",
"// check if a background image is defined",
"if",
"(",
"this",
".",
"background_image",
")",
"{",
"// add a new image layer",
"this",
".",
"layers",
".",
"push",
"(",
"me",
".",
"pool",
".",
"pull",
"(",
"\"me.ImageLayer\"",
",",
"0",
",",
"0",
",",
"{",
"name",
":",
"\"background_image\"",
",",
"image",
":",
"this",
".",
"background_image",
",",
"z",
":",
"zOrder",
"++",
"}",
")",
")",
";",
"}",
"data",
".",
"layers",
".",
"forEach",
"(",
"function",
"(",
"layer",
")",
"{",
"switch",
"(",
"layer",
".",
"type",
")",
"{",
"case",
"\"imagelayer\"",
":",
"self",
".",
"layers",
".",
"push",
"(",
"readImageLayer",
"(",
"self",
",",
"layer",
",",
"zOrder",
"++",
")",
")",
";",
"break",
";",
"case",
"\"tilelayer\"",
":",
"self",
".",
"layers",
".",
"push",
"(",
"readLayer",
"(",
"self",
",",
"layer",
",",
"zOrder",
"++",
")",
")",
";",
"break",
";",
"// get the object groups information",
"case",
"\"objectgroup\"",
":",
"self",
".",
"objectGroups",
".",
"push",
"(",
"readObjectGroup",
"(",
"self",
",",
"layer",
",",
"zOrder",
"++",
")",
")",
";",
"break",
";",
"// get the object groups information",
"case",
"\"group\"",
":",
"self",
".",
"objectGroups",
".",
"push",
"(",
"readObjectGroup",
"(",
"self",
",",
"layer",
",",
"zOrder",
"++",
")",
")",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"}",
")",
";",
"this",
".",
"initialized",
"=",
"true",
";",
"}"
] | parse the map
@ignore | [
"parse",
"the",
"map"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/level/tiled/TMXTiledMap.js#L271-L346 |
|
7,234 | melonjs/melonJS | src/level/tiled/TMXTiledMap.js | 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().forEach(function (layer) {
container.addChild(layer);
});
// add all Object instances
this.getObjects(flatten).forEach(function (object) {
container.addChild(object);
});
// set back auto-sort and auto-depth
container.autoSort = _sort;
container.autoDepth = _depth;
// force a sort
container.sort(true);
} | javascript | 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().forEach(function (layer) {
container.addChild(layer);
});
// add all Object instances
this.getObjects(flatten).forEach(function (object) {
container.addChild(object);
});
// set back auto-sort and auto-depth
container.autoSort = _sort;
container.autoDepth = _depth;
// force a sort
container.sort(true);
} | [
"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",
"(",
")",
".",
"forEach",
"(",
"function",
"(",
"layer",
")",
"{",
"container",
".",
"addChild",
"(",
"layer",
")",
";",
"}",
")",
";",
"// add all Object instances",
"this",
".",
"getObjects",
"(",
"flatten",
")",
".",
"forEach",
"(",
"function",
"(",
"object",
")",
"{",
"container",
".",
"addChild",
"(",
"object",
")",
";",
"}",
")",
";",
"// set back auto-sort and auto-depth",
"container",
".",
"autoSort",
"=",
"_sort",
";",
"container",
".",
"autoDepth",
"=",
"_depth",
";",
"// force a sort",
"container",
".",
"sort",
"(",
"true",
")",
";",
"}"
] | add all the map layers and objects to the given container
@name me.TMXTileMap#addTo
@public
@function
@param {me.Container} target container
@param {boolean} flatten if true, flatten all objects into the given container
@example
// create a new level object based on the TMX JSON object
var level = new me.TMXTileMap(levelId, me.loader.getTMX(levelId));
// add the level to the game world container
level.addTo(me.game.world, true); | [
"add",
"all",
"the",
"map",
"layers",
"and",
"objects",
"to",
"the",
"given",
"container"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/level/tiled/TMXTiledMap.js#L362-L386 |
|
7,235 | melonjs/melonJS | src/video/texture.js | 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 spritecount = me.pool.pull("me.Vector2d",
~~((width - margin + spacing) / (data.framewidth + spacing)),
~~((height - margin + spacing) / (data.frameheight + spacing))
);
// verifying the texture size
if ((width % (data.framewidth + spacing)) !== 0 ||
(height % (data.frameheight + spacing)) !== 0) {
// "truncate size"
width = spritecount.x * (data.framewidth + spacing);
height = spritecount.y * (data.frameheight + spacing);
// warning message
console.warn(
"Spritesheet Texture for image: " + image.src +
" is not divisible by " + (data.framewidth + spacing) +
"x" + (data.frameheight + spacing) +
", truncating effective size to " + width + "x" + height
);
}
// build the local atlas
for (var frame = 0, count = spritecount.x * spritecount.y; frame < count; frame++) {
var name = "" + frame;
atlas[name] = {
name : name,
texture : "default", // the source texture
offset : new me.Vector2d(
margin + (spacing + data.framewidth) * (frame % spritecount.x),
margin + (spacing + data.frameheight) * ~~(frame / spritecount.x)
),
anchorPoint : (data.anchorPoint || null),
trimmed : false,
width : data.framewidth,
height : data.frameheight,
angle : 0
};
this.addUvsMap(atlas, name, width, height);
}
me.pool.push(spritecount);
return atlas;
} | javascript | 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 spritecount = me.pool.pull("me.Vector2d",
~~((width - margin + spacing) / (data.framewidth + spacing)),
~~((height - margin + spacing) / (data.frameheight + spacing))
);
// verifying the texture size
if ((width % (data.framewidth + spacing)) !== 0 ||
(height % (data.frameheight + spacing)) !== 0) {
// "truncate size"
width = spritecount.x * (data.framewidth + spacing);
height = spritecount.y * (data.frameheight + spacing);
// warning message
console.warn(
"Spritesheet Texture for image: " + image.src +
" is not divisible by " + (data.framewidth + spacing) +
"x" + (data.frameheight + spacing) +
", truncating effective size to " + width + "x" + height
);
}
// build the local atlas
for (var frame = 0, count = spritecount.x * spritecount.y; frame < count; frame++) {
var name = "" + frame;
atlas[name] = {
name : name,
texture : "default", // the source texture
offset : new me.Vector2d(
margin + (spacing + data.framewidth) * (frame % spritecount.x),
margin + (spacing + data.frameheight) * ~~(frame / spritecount.x)
),
anchorPoint : (data.anchorPoint || null),
trimmed : false,
width : data.framewidth,
height : data.frameheight,
angle : 0
};
this.addUvsMap(atlas, name, width, height);
}
me.pool.push(spritecount);
return atlas;
} | [
"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",
"spritecount",
"=",
"me",
".",
"pool",
".",
"pull",
"(",
"\"me.Vector2d\"",
",",
"~",
"~",
"(",
"(",
"width",
"-",
"margin",
"+",
"spacing",
")",
"/",
"(",
"data",
".",
"framewidth",
"+",
"spacing",
")",
")",
",",
"~",
"~",
"(",
"(",
"height",
"-",
"margin",
"+",
"spacing",
")",
"/",
"(",
"data",
".",
"frameheight",
"+",
"spacing",
")",
")",
")",
";",
"// verifying the texture size",
"if",
"(",
"(",
"width",
"%",
"(",
"data",
".",
"framewidth",
"+",
"spacing",
")",
")",
"!==",
"0",
"||",
"(",
"height",
"%",
"(",
"data",
".",
"frameheight",
"+",
"spacing",
")",
")",
"!==",
"0",
")",
"{",
"// \"truncate size\"",
"width",
"=",
"spritecount",
".",
"x",
"*",
"(",
"data",
".",
"framewidth",
"+",
"spacing",
")",
";",
"height",
"=",
"spritecount",
".",
"y",
"*",
"(",
"data",
".",
"frameheight",
"+",
"spacing",
")",
";",
"// warning message",
"console",
".",
"warn",
"(",
"\"Spritesheet Texture for image: \"",
"+",
"image",
".",
"src",
"+",
"\" is not divisible by \"",
"+",
"(",
"data",
".",
"framewidth",
"+",
"spacing",
")",
"+",
"\"x\"",
"+",
"(",
"data",
".",
"frameheight",
"+",
"spacing",
")",
"+",
"\", truncating effective size to \"",
"+",
"width",
"+",
"\"x\"",
"+",
"height",
")",
";",
"}",
"// build the local atlas",
"for",
"(",
"var",
"frame",
"=",
"0",
",",
"count",
"=",
"spritecount",
".",
"x",
"*",
"spritecount",
".",
"y",
";",
"frame",
"<",
"count",
";",
"frame",
"++",
")",
"{",
"var",
"name",
"=",
"\"\"",
"+",
"frame",
";",
"atlas",
"[",
"name",
"]",
"=",
"{",
"name",
":",
"name",
",",
"texture",
":",
"\"default\"",
",",
"// the source texture",
"offset",
":",
"new",
"me",
".",
"Vector2d",
"(",
"margin",
"+",
"(",
"spacing",
"+",
"data",
".",
"framewidth",
")",
"*",
"(",
"frame",
"%",
"spritecount",
".",
"x",
")",
",",
"margin",
"+",
"(",
"spacing",
"+",
"data",
".",
"frameheight",
")",
"*",
"~",
"~",
"(",
"frame",
"/",
"spritecount",
".",
"x",
")",
")",
",",
"anchorPoint",
":",
"(",
"data",
".",
"anchorPoint",
"||",
"null",
")",
",",
"trimmed",
":",
"false",
",",
"width",
":",
"data",
".",
"framewidth",
",",
"height",
":",
"data",
".",
"frameheight",
",",
"angle",
":",
"0",
"}",
";",
"this",
".",
"addUvsMap",
"(",
"atlas",
",",
"name",
",",
"width",
",",
"height",
")",
";",
"}",
"me",
".",
"pool",
".",
"push",
"(",
"spritecount",
")",
";",
"return",
"atlas",
";",
"}"
] | build an atlas from the given spritesheet
@ignore | [
"build",
"an",
"atlas",
"from",
"the",
"given",
"spritesheet"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/texture.js#L210-L262 |
|
7,236 | melonjs/melonJS | src/video/texture.js | 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(","),
sx = +keys[0],
sy = +keys[1],
sw = +keys[2],
sh = +keys[3];
region = this.addQuadRegion(name, sx, sy, sw, sh);
}
return region.uvs;
} | javascript | 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(","),
sx = +keys[0],
sy = +keys[1],
sw = +keys[2],
sh = +keys[3];
region = this.addQuadRegion(name, sx, sy, sw, sh);
}
return region.uvs;
} | [
"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",
"(",
"\",\"",
")",
",",
"sx",
"=",
"+",
"keys",
"[",
"0",
"]",
",",
"sy",
"=",
"+",
"keys",
"[",
"1",
"]",
",",
"sw",
"=",
"+",
"keys",
"[",
"2",
"]",
",",
"sh",
"=",
"+",
"keys",
"[",
"3",
"]",
";",
"region",
"=",
"this",
".",
"addQuadRegion",
"(",
"name",
",",
"sx",
",",
"sy",
",",
"sw",
",",
"sh",
")",
";",
"}",
"return",
"region",
".",
"uvs",
";",
"}"
] | return the uvs mapping for the given region
@name getUVs
@memberOf me.Renderer.Texture
@function
@param {Object} region region (or frame) name
@return {Float32Array} region Uvs | [
"return",
"the",
"uvs",
"mapping",
"for",
"the",
"given",
"region"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/texture.js#L381-L395 |
|
7,237 | melonjs/melonJS | src/video/texture.js | function (name, settings) {
// instantiate a new sprite object
return me.pool.pull(
"me.Sprite",
0, 0,
Object.assign({
image: this,
region : name
}, settings || {})
);
} | javascript | function (name, settings) {
// instantiate a new sprite object
return me.pool.pull(
"me.Sprite",
0, 0,
Object.assign({
image: this,
region : name
}, settings || {})
);
} | [
"function",
"(",
"name",
",",
"settings",
")",
"{",
"// instantiate a new sprite object",
"return",
"me",
".",
"pool",
".",
"pull",
"(",
"\"me.Sprite\"",
",",
"0",
",",
"0",
",",
"Object",
".",
"assign",
"(",
"{",
"image",
":",
"this",
",",
"region",
":",
"name",
"}",
",",
"settings",
"||",
"{",
"}",
")",
")",
";",
"}"
] | Create a sprite object using the first region found using the specified name
@name createSpriteFromName
@memberOf me.Renderer.Texture
@function
@param {String} name name of the sprite
@param {Object} [settings] Additional settings passed to the {@link me.Sprite} contructor
@return {me.Sprite}
@example
// create a new texture object under the `game` namespace
game.texture = new me.video.renderer.Texture(
me.loader.getJSON("texture"),
me.loader.getImage("texture")
);
...
...
// add the coin sprite as renderable for the entity
this.renderable = game.texture.createSpriteFromName("coin.png");
// set the renderable position to bottom center
this.anchorPoint.set(0.5, 1.0); | [
"Create",
"a",
"sprite",
"object",
"using",
"the",
"first",
"region",
"found",
"using",
"the",
"specified",
"name"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/video/texture.js#L418-L428 |
|
7,238 | melonjs/melonJS | src/state/state.js | _renderFrame | 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) {
_animFrameId = window.requestAnimationFrame(_renderFrame);
}
} | javascript | 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) {
_animFrameId = window.requestAnimationFrame(_renderFrame);
}
} | [
"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",
")",
"{",
"_animFrameId",
"=",
"window",
".",
"requestAnimationFrame",
"(",
"_renderFrame",
")",
";",
"}",
"}"
] | this is only called when using requestAnimFrame stuff
@param {Number} time current timestamp in milliseconds
@ignore | [
"this",
"is",
"only",
"called",
"when",
"using",
"requestAnimFrame",
"stuff"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/state/state.js#L87-L97 |
7,239 | melonjs/melonJS | src/state/state.js | _switchState | 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[state]) {
// set the global variable
_state = state;
// call the reset function with _extraArgs as arguments
_stages[_state].stage.reset.apply(_stages[_state].stage, _extraArgs);
// and start the main loop of the
// new requested state
_startRunLoop();
// execute callback if defined
if (_onSwitchComplete) {
_onSwitchComplete();
}
// force repaint
me.game.repaint();
}
} | javascript | 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[state]) {
// set the global variable
_state = state;
// call the reset function with _extraArgs as arguments
_stages[_state].stage.reset.apply(_stages[_state].stage, _extraArgs);
// and start the main loop of the
// new requested state
_startRunLoop();
// execute callback if defined
if (_onSwitchComplete) {
_onSwitchComplete();
}
// force repaint
me.game.repaint();
}
} | [
"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",
"[",
"state",
"]",
")",
"{",
"// set the global variable",
"_state",
"=",
"state",
";",
"// call the reset function with _extraArgs as arguments",
"_stages",
"[",
"_state",
"]",
".",
"stage",
".",
"reset",
".",
"apply",
"(",
"_stages",
"[",
"_state",
"]",
".",
"stage",
",",
"_extraArgs",
")",
";",
"// and start the main loop of the",
"// new requested state",
"_startRunLoop",
"(",
")",
";",
"// execute callback if defined",
"if",
"(",
"_onSwitchComplete",
")",
"{",
"_onSwitchComplete",
"(",
")",
";",
"}",
"// force repaint",
"me",
".",
"game",
".",
"repaint",
"(",
")",
";",
"}",
"}"
] | start the SO main loop
@ignore | [
"start",
"the",
"SO",
"main",
"loop"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/state/state.js#L113-L142 |
7,240 | melonjs/melonJS | src/renderable/colorlayer.js | 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
);
renderer.setColor(color);
} | javascript | 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
);
renderer.setColor(color);
} | [
"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",
")",
";",
"renderer",
".",
"setColor",
"(",
"color",
")",
";",
"}"
] | draw the color layer
@ignore | [
"draw",
"the",
"color",
"layer"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/renderable/colorlayer.js#L47-L56 |
|
7,241 | melonjs/melonJS | src/physics/collision.js | flattenPointsOn | 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(normal);
if (dot < min) { min = dot; }
if (dot > max) { max = dot; }
}
result[0] = min;
result[1] = max;
} | javascript | 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(normal);
if (dot < min) { min = dot; }
if (dot > max) { max = dot; }
}
result[0] = min;
result[1] = max;
} | [
"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",
"(",
"normal",
")",
";",
"if",
"(",
"dot",
"<",
"min",
")",
"{",
"min",
"=",
"dot",
";",
"}",
"if",
"(",
"dot",
">",
"max",
")",
"{",
"max",
"=",
"dot",
";",
"}",
"}",
"result",
"[",
"0",
"]",
"=",
"min",
";",
"result",
"[",
"1",
"]",
"=",
"max",
";",
"}"
] | Flattens the specified array of points onto a unit vector axis,
resulting in a one dimensional range of the minimum and
maximum value on that axis.
@param {Array.<Vector>} points The points to flatten.
@param {Vector} normal The unit vector axis to flatten on.
@param {Array.<number>} result An array. After calling this function,
result[0] will be the minimum value,
result[1] will be the maximum value. | [
"Flattens",
"the",
"specified",
"array",
"of",
"points",
"onto",
"a",
"unit",
"vector",
"axis",
"resulting",
"in",
"a",
"one",
"dimensional",
"range",
"of",
"the",
"minimum",
"and",
"maximum",
"value",
"on",
"that",
"axis",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/physics/collision.js#L58-L70 |
7,242 | melonjs/melonJS | src/loader/loader.js | checkLoadStatus | 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);
// trigger the onload callback
// we call either the supplied callback (which takes precedence) or the global one
var callback = onload || api.onload;
setTimeout(function () {
callback();
me.event.publish(me.event.LOADER_COMPLETE);
}, 300);
}
else {
throw new Error("no load callback defined");
}
}
else {
timerId = setTimeout(function() {
checkLoadStatus(onload);
}, 100);
}
} | javascript | 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);
// trigger the onload callback
// we call either the supplied callback (which takes precedence) or the global one
var callback = onload || api.onload;
setTimeout(function () {
callback();
me.event.publish(me.event.LOADER_COMPLETE);
}, 300);
}
else {
throw new Error("no load callback defined");
}
}
else {
timerId = setTimeout(function() {
checkLoadStatus(onload);
}, 100);
}
} | [
"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",
")",
";",
"// trigger the onload callback",
"// we call either the supplied callback (which takes precedence) or the global one",
"var",
"callback",
"=",
"onload",
"||",
"api",
".",
"onload",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"callback",
"(",
")",
";",
"me",
".",
"event",
".",
"publish",
"(",
"me",
".",
"event",
".",
"LOADER_COMPLETE",
")",
";",
"}",
",",
"300",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"\"no load callback defined\"",
")",
";",
"}",
"}",
"else",
"{",
"timerId",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"checkLoadStatus",
"(",
"onload",
")",
";",
"}",
",",
"100",
")",
";",
"}",
"}"
] | check the loading status
@ignore | [
"check",
"the",
"loading",
"status"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/loader/loader.js#L32-L55 |
7,243 | melonjs/melonJS | src/loader/loader.js | preloadFontFace | 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);
document.body.style.fontFamily = data.name;
// onloaded callback
onload();
}, function (e) {
// rejected
onerror(data.name);
});
} | javascript | 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);
document.body.style.fontFamily = data.name;
// onloaded callback
onload();
}, function (e) {
// rejected
onerror(data.name);
});
} | [
"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",
")",
";",
"document",
".",
"body",
".",
"style",
".",
"fontFamily",
"=",
"data",
".",
"name",
";",
"// onloaded callback",
"onload",
"(",
")",
";",
"}",
",",
"function",
"(",
"e",
")",
"{",
"// rejected",
"onerror",
"(",
"data",
".",
"name",
")",
";",
"}",
")",
";",
"}"
] | load a font face
@example
preloadFontFace(
name: "'kenpixel'", type: "fontface", src: "url('data/font/kenvector_future.woff2')"
]);
@ignore | [
"load",
"a",
"font",
"face"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/loader/loader.js#L87-L100 |
7,244 | melonjs/melonJS | src/loader/loader.js | preloadJSON | 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.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)) {
// get the Texture Packer Atlas content
jsonList[data.name] = JSON.parse(xmlhttp.responseText);
// fire the callback
onload();
}
else {
onerror(data.name);
}
}
};
// send the request
xmlhttp.send();
} | javascript | 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.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)) {
// get the Texture Packer Atlas content
jsonList[data.name] = JSON.parse(xmlhttp.responseText);
// fire the callback
onload();
}
else {
onerror(data.name);
}
}
};
// send the request
xmlhttp.send();
} | [
"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",
".",
"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",
")",
")",
"{",
"// get the Texture Packer Atlas content",
"jsonList",
"[",
"data",
".",
"name",
"]",
"=",
"JSON",
".",
"parse",
"(",
"xmlhttp",
".",
"responseText",
")",
";",
"// fire the callback",
"onload",
"(",
")",
";",
"}",
"else",
"{",
"onerror",
"(",
"data",
".",
"name",
")",
";",
"}",
"}",
"}",
";",
"// send the request",
"xmlhttp",
".",
"send",
"(",
")",
";",
"}"
] | preload JSON files
@ignore | [
"preload",
"JSON",
"files"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/loader/loader.js#L207-L236 |
7,245 | melonjs/melonJS | src/shapes/poly.js | 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 = [];
points.forEach(function (point) {
_points.push(new me.Vector2d(point.x, point.y));
});
} else {
// array of me.Vector2d
this.points = points;
}
this.recalc();
this.updateBounds();
return this;
} | javascript | 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 = [];
points.forEach(function (point) {
_points.push(new me.Vector2d(point.x, point.y));
});
} else {
// array of me.Vector2d
this.points = points;
}
this.recalc();
this.updateBounds();
return this;
} | [
"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",
"=",
"[",
"]",
";",
"points",
".",
"forEach",
"(",
"function",
"(",
"point",
")",
"{",
"_points",
".",
"push",
"(",
"new",
"me",
".",
"Vector2d",
"(",
"point",
".",
"x",
",",
"point",
".",
"y",
")",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"// array of me.Vector2d",
"this",
".",
"points",
"=",
"points",
";",
"}",
"this",
".",
"recalc",
"(",
")",
";",
"this",
".",
"updateBounds",
"(",
")",
";",
"return",
"this",
";",
"}"
] | set new value to the Polygon
@name setShape
@memberOf me.Polygon.prototype
@function
@param {Number} x position of the Polygon
@param {Number} y position of the Polygon
@param {me.Vector2d[]} points array of vector defining the Polygon | [
"set",
"new",
"value",
"to",
"the",
"Polygon"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/shapes/poly.js#L94-L116 |
|
7,246 | melonjs/melonJS | src/shapes/poly.js | 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();
return this;
} | javascript | 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();
return this;
} | [
"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",
"(",
")",
";",
"return",
"this",
";",
"}"
] | Scale this Polygon by the given scalar.
@name scale
@memberOf me.Polygon.prototype
@function
@param {Number} x
@param {Number} [y=x]
@return {me.Polygon} Reference to this object for method chaining | [
"Scale",
"this",
"Polygon",
"by",
"the",
"given",
"scalar",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/shapes/poly.js#L189-L200 |
|
7,247 | melonjs/melonJS | src/entity/entity.js | 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 | 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);
} | [
"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",
")",
";",
"}"
] | update the bounds position when the body is modified
@private
@name onBodyUpdate
@memberOf me.Entity
@function | [
"update",
"the",
"bounds",
"position",
"when",
"the",
"body",
"is",
"modified"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/entity/entity.js#L176-L181 |
|
7,248 | melonjs/melonJS | src/shapes/rectangle.js | function () {
return (isFinite(this.pos.x) && isFinite(this.pos.y) && isFinite(this._width) && isFinite(this._height));
} | javascript | function () {
return (isFinite(this.pos.x) && isFinite(this.pos.y) && isFinite(this._width) && isFinite(this._height));
} | [
"function",
"(",
")",
"{",
"return",
"(",
"isFinite",
"(",
"this",
".",
"pos",
".",
"x",
")",
"&&",
"isFinite",
"(",
"this",
".",
"pos",
".",
"y",
")",
"&&",
"isFinite",
"(",
"this",
".",
"_width",
")",
"&&",
"isFinite",
"(",
"this",
".",
"_height",
")",
")",
";",
"}"
] | determines whether all coordinates of this rectangle are finite numbers.
@name isFinite
@memberOf me.Rect.prototype
@function
@return {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true. | [
"determines",
"whether",
"all",
"coordinates",
"of",
"this",
"rectangle",
"are",
"finite",
"numbers",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/shapes/rectangle.js#L283-L285 |
|
7,249 | melonjs/melonJS | src/level/LevelDirector.js | loadTMXLevel | 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();
if (setViewportBounds) {
// update the viewport bounds
me.game.viewport.setBounds(
0, 0,
Math.max(levelBounds.width, me.game.viewport.width),
Math.max(levelBounds.height, me.game.viewport.height)
);
}
// reset the GUID generator
// and pass the level id as parameter
me.utils.resetGUID(levelId, level.nextobjectid);
// Tiled use 0,0 anchor coordinates
container.anchorPoint.set(0, 0);
// add all level elements to the target container
level.addTo(container, flatten);
// sort everything (recursively)
container.sort(true);
container.autoSort = autoSort;
container.resize(levelBounds.width, levelBounds.height);
function resize_container() {
// center the map if smaller than the current viewport
container.pos.set(
Math.max(0, ~~((me.game.viewport.width - levelBounds.width) / 2)),
Math.max(0, ~~((me.game.viewport.height - levelBounds.height) / 2)),
0
);
}
if (setViewportBounds) {
resize_container();
// Replace the resize handler
if (onresize_handler) {
me.event.unsubscribe(onresize_handler);
}
onresize_handler = me.event.subscribe(me.event.VIEWPORT_ONRESIZE, resize_container);
}
} | javascript | 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();
if (setViewportBounds) {
// update the viewport bounds
me.game.viewport.setBounds(
0, 0,
Math.max(levelBounds.width, me.game.viewport.width),
Math.max(levelBounds.height, me.game.viewport.height)
);
}
// reset the GUID generator
// and pass the level id as parameter
me.utils.resetGUID(levelId, level.nextobjectid);
// Tiled use 0,0 anchor coordinates
container.anchorPoint.set(0, 0);
// add all level elements to the target container
level.addTo(container, flatten);
// sort everything (recursively)
container.sort(true);
container.autoSort = autoSort;
container.resize(levelBounds.width, levelBounds.height);
function resize_container() {
// center the map if smaller than the current viewport
container.pos.set(
Math.max(0, ~~((me.game.viewport.width - levelBounds.width) / 2)),
Math.max(0, ~~((me.game.viewport.height - levelBounds.height) / 2)),
0
);
}
if (setViewportBounds) {
resize_container();
// Replace the resize handler
if (onresize_handler) {
me.event.unsubscribe(onresize_handler);
}
onresize_handler = me.event.subscribe(me.event.VIEWPORT_ONRESIZE, resize_container);
}
} | [
"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",
"(",
")",
";",
"if",
"(",
"setViewportBounds",
")",
"{",
"// update the viewport bounds",
"me",
".",
"game",
".",
"viewport",
".",
"setBounds",
"(",
"0",
",",
"0",
",",
"Math",
".",
"max",
"(",
"levelBounds",
".",
"width",
",",
"me",
".",
"game",
".",
"viewport",
".",
"width",
")",
",",
"Math",
".",
"max",
"(",
"levelBounds",
".",
"height",
",",
"me",
".",
"game",
".",
"viewport",
".",
"height",
")",
")",
";",
"}",
"// reset the GUID generator",
"// and pass the level id as parameter",
"me",
".",
"utils",
".",
"resetGUID",
"(",
"levelId",
",",
"level",
".",
"nextobjectid",
")",
";",
"// Tiled use 0,0 anchor coordinates",
"container",
".",
"anchorPoint",
".",
"set",
"(",
"0",
",",
"0",
")",
";",
"// add all level elements to the target container",
"level",
".",
"addTo",
"(",
"container",
",",
"flatten",
")",
";",
"// sort everything (recursively)",
"container",
".",
"sort",
"(",
"true",
")",
";",
"container",
".",
"autoSort",
"=",
"autoSort",
";",
"container",
".",
"resize",
"(",
"levelBounds",
".",
"width",
",",
"levelBounds",
".",
"height",
")",
";",
"function",
"resize_container",
"(",
")",
"{",
"// center the map if smaller than the current viewport",
"container",
".",
"pos",
".",
"set",
"(",
"Math",
".",
"max",
"(",
"0",
",",
"~",
"~",
"(",
"(",
"me",
".",
"game",
".",
"viewport",
".",
"width",
"-",
"levelBounds",
".",
"width",
")",
"/",
"2",
")",
")",
",",
"Math",
".",
"max",
"(",
"0",
",",
"~",
"~",
"(",
"(",
"me",
".",
"game",
".",
"viewport",
".",
"height",
"-",
"levelBounds",
".",
"height",
")",
"/",
"2",
")",
")",
",",
"0",
")",
";",
"}",
"if",
"(",
"setViewportBounds",
")",
"{",
"resize_container",
"(",
")",
";",
"// Replace the resize handler",
"if",
"(",
"onresize_handler",
")",
"{",
"me",
".",
"event",
".",
"unsubscribe",
"(",
"onresize_handler",
")",
";",
"}",
"onresize_handler",
"=",
"me",
".",
"event",
".",
"subscribe",
"(",
"me",
".",
"event",
".",
"VIEWPORT_ONRESIZE",
",",
"resize_container",
")",
";",
"}",
"}"
] | Load a TMX level
@name loadTMXLevel
@memberOf me.game
@private
@param {String} level level id
@param {me.Container} target container
@param {boolean} flatten if true, flatten all objects into the given container
@param {boolean} setViewportBounds if true, set the viewport bounds to the map size
@ignore
@function | [
"Load",
"a",
"TMX",
"level"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/level/LevelDirector.js#L68-L120 |
7,250 | melonjs/melonJS | src/shapes/line.js | 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) * (Bx - Ax) = (By - Ay) * (Cx - Ax)
return (y - start.y) * (end.x - start.x) === (end.y - start.y) * (x - start.x);
} | javascript | 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) * (Bx - Ax) = (By - Ay) * (Cx - Ax)
return (y - start.y) * (end.x - start.x) === (end.y - start.y) * (x - start.x);
} | [
"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) * (Bx - Ax) = (By - Ay) * (Cx - Ax)",
"return",
"(",
"y",
"-",
"start",
".",
"y",
")",
"*",
"(",
"end",
".",
"x",
"-",
"start",
".",
"x",
")",
"===",
"(",
"end",
".",
"y",
"-",
"start",
".",
"y",
")",
"*",
"(",
"x",
"-",
"start",
".",
"x",
")",
";",
"}"
] | check if this line segment contains the specified point
@name containsPoint
@memberOf me.Line.prototype
@function
@param {Number} x x coordinate
@param {Number} y y coordinate
@return {boolean} true if contains | [
"check",
"if",
"this",
"line",
"segment",
"contains",
"the",
"specified",
"point"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/shapes/line.js#L35-L45 |
|
7,251 | melonjs/melonJS | src/font/text.js | 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;
context.textBaseline = font.textBaseline;
} | javascript | 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;
context.textBaseline = font.textBaseline;
} | [
"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",
";",
"context",
".",
"textBaseline",
"=",
"font",
".",
"textBaseline",
";",
"}"
] | apply the current font style to the given context
@ignore | [
"apply",
"the",
"current",
"font",
"style",
"to",
"the",
"given",
"context"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/font/text.js#L17-L26 |
|
7,252 | melonjs/melonJS | src/font/text.js | 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.pos.y !== y) {
this.pos.x = x;
this.pos.y = y;
this.isDirty = true;
}
// force update bounds
this.update(0);
// save the previous context
renderer.save();
// apply the defined alpha value
renderer.setGlobalAlpha(renderer.globalAlpha() * this.getOpacity());
} else {
// added directly to an object container
x = this.pos.x;
y = this.pos.y;
}
if (renderer.settings.subPixel === false) {
// clamp to pixel grid if required
x = ~~x;
y = ~~y;
}
// draw the text
renderer.drawFont(this._drawFont(renderer.getFontContext(), this._text, x, y, stroke || false));
// for backward compatibilty
if (typeof this.ancestor === "undefined") {
// restore previous context
renderer.restore();
}
// clear the dirty flag
this.isDirty = false;
} | javascript | 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.pos.y !== y) {
this.pos.x = x;
this.pos.y = y;
this.isDirty = true;
}
// force update bounds
this.update(0);
// save the previous context
renderer.save();
// apply the defined alpha value
renderer.setGlobalAlpha(renderer.globalAlpha() * this.getOpacity());
} else {
// added directly to an object container
x = this.pos.x;
y = this.pos.y;
}
if (renderer.settings.subPixel === false) {
// clamp to pixel grid if required
x = ~~x;
y = ~~y;
}
// draw the text
renderer.drawFont(this._drawFont(renderer.getFontContext(), this._text, x, y, stroke || false));
// for backward compatibilty
if (typeof this.ancestor === "undefined") {
// restore previous context
renderer.restore();
}
// clear the dirty flag
this.isDirty = false;
} | [
"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",
".",
"pos",
".",
"y",
"!==",
"y",
")",
"{",
"this",
".",
"pos",
".",
"x",
"=",
"x",
";",
"this",
".",
"pos",
".",
"y",
"=",
"y",
";",
"this",
".",
"isDirty",
"=",
"true",
";",
"}",
"// force update bounds",
"this",
".",
"update",
"(",
"0",
")",
";",
"// save the previous context",
"renderer",
".",
"save",
"(",
")",
";",
"// apply the defined alpha value",
"renderer",
".",
"setGlobalAlpha",
"(",
"renderer",
".",
"globalAlpha",
"(",
")",
"*",
"this",
".",
"getOpacity",
"(",
")",
")",
";",
"}",
"else",
"{",
"// added directly to an object container",
"x",
"=",
"this",
".",
"pos",
".",
"x",
";",
"y",
"=",
"this",
".",
"pos",
".",
"y",
";",
"}",
"if",
"(",
"renderer",
".",
"settings",
".",
"subPixel",
"===",
"false",
")",
"{",
"// clamp to pixel grid if required",
"x",
"=",
"~",
"~",
"x",
";",
"y",
"=",
"~",
"~",
"y",
";",
"}",
"// draw the text",
"renderer",
".",
"drawFont",
"(",
"this",
".",
"_drawFont",
"(",
"renderer",
".",
"getFontContext",
"(",
")",
",",
"this",
".",
"_text",
",",
"x",
",",
"y",
",",
"stroke",
"||",
"false",
")",
")",
";",
"// for backward compatibilty",
"if",
"(",
"typeof",
"this",
".",
"ancestor",
"===",
"\"undefined\"",
")",
"{",
"// restore previous context",
"renderer",
".",
"restore",
"(",
")",
";",
"}",
"// clear the dirty flag",
"this",
".",
"isDirty",
"=",
"false",
";",
"}"
] | draw a text at the specified coord
@name draw
@memberOf me.Text.prototype
@function
@param {me.CanvasRenderer|me.WebGLRenderer} renderer Reference to the destination renderer instance
@param {String} [text]
@param {Number} [x]
@param {Number} [y] | [
"draw",
"a",
"text",
"at",
"the",
"specified",
"coord"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/font/text.js#L332-L377 |
|
7,253 | melonjs/melonJS | src/renderable/GUI.js | 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) {
me.timer.clearTimeout(this.holdTimeout);
}
this.holdTimeout = me.timer.setTimeout(this.hold.bind(this), this.holdThreshold, false);
this.released = false;
}
return this.onClick.call(this, event);
}
} | javascript | 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) {
me.timer.clearTimeout(this.holdTimeout);
}
this.holdTimeout = me.timer.setTimeout(this.hold.bind(this), this.holdThreshold, false);
this.released = false;
}
return this.onClick.call(this, event);
}
} | [
"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",
")",
"{",
"me",
".",
"timer",
".",
"clearTimeout",
"(",
"this",
".",
"holdTimeout",
")",
";",
"}",
"this",
".",
"holdTimeout",
"=",
"me",
".",
"timer",
".",
"setTimeout",
"(",
"this",
".",
"hold",
".",
"bind",
"(",
"this",
")",
",",
"this",
".",
"holdThreshold",
",",
"false",
")",
";",
"this",
".",
"released",
"=",
"false",
";",
"}",
"return",
"this",
".",
"onClick",
".",
"call",
"(",
"this",
",",
"event",
")",
";",
"}",
"}"
] | function callback for the pointerdown event
@ignore | [
"function",
"callback",
"for",
"the",
"pointerdown",
"event"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/renderable/GUI.js#L124-L138 |
|
7,254 | melonjs/melonJS | src/renderable/GUI.js | function (event) {
if (this.released === false) {
this.released = true;
me.timer.clearTimeout(this.holdTimeout);
return this.onRelease.call(this, event);
}
} | javascript | function (event) {
if (this.released === false) {
this.released = true;
me.timer.clearTimeout(this.holdTimeout);
return this.onRelease.call(this, event);
}
} | [
"function",
"(",
"event",
")",
"{",
"if",
"(",
"this",
".",
"released",
"===",
"false",
")",
"{",
"this",
".",
"released",
"=",
"true",
";",
"me",
".",
"timer",
".",
"clearTimeout",
"(",
"this",
".",
"holdTimeout",
")",
";",
"return",
"this",
".",
"onRelease",
".",
"call",
"(",
"this",
",",
"event",
")",
";",
"}",
"}"
] | function callback for the pointerup event
@ignore | [
"function",
"callback",
"for",
"the",
"pointerup",
"event"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/renderable/GUI.js#L197-L203 |
|
7,255 | melonjs/melonJS | src/particles/emitter.js | 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 | 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);
}
} | [
"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",
")",
";",
"}",
"}"
] | Add count particles in the game world @ignore | [
"Add",
"count",
"particles",
"in",
"the",
"game",
"world"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/src/particles/emitter.js#L473-L479 |
|
7,256 | melonjs/melonJS | dist/melonjs.js | apply_methods | 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 `" + method + "` is not a function"
);
}
Object.defineProperty(Class.prototype, method, {
"configurable" : true,
"value" : descriptor[method]
});
});
} | javascript | 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 `" + method + "` is not a function"
);
}
Object.defineProperty(Class.prototype, method, {
"configurable" : true,
"value" : descriptor[method]
});
});
} | [
"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 `\"",
"+",
"method",
"+",
"\"` is not a function\"",
")",
";",
"}",
"Object",
".",
"defineProperty",
"(",
"Class",
".",
"prototype",
",",
"method",
",",
"{",
"\"configurable\"",
":",
"true",
",",
"\"value\"",
":",
"descriptor",
"[",
"method",
"]",
"}",
")",
";",
"}",
")",
";",
"}"
] | Apply methods to the class prototype.
@ignore | [
"Apply",
"methods",
"to",
"the",
"class",
"prototype",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L233-L248 |
7,257 | melonjs/melonJS | dist/melonjs.js | angle | function angle(v) {
return Math.acos(me.Math.clamp(this.dotProduct(v) / (this.length() * v.length()), -1, 1));
} | javascript | function angle(v) {
return Math.acos(me.Math.clamp(this.dotProduct(v) / (this.length() * v.length()), -1, 1));
} | [
"function",
"angle",
"(",
"v",
")",
"{",
"return",
"Math",
".",
"acos",
"(",
"me",
".",
"Math",
".",
"clamp",
"(",
"this",
".",
"dotProduct",
"(",
"v",
")",
"/",
"(",
"this",
".",
"length",
"(",
")",
"*",
"v",
".",
"length",
"(",
")",
")",
",",
"-",
"1",
",",
"1",
")",
")",
";",
"}"
] | return the angle between this vector and the passed one
@name angle
@memberOf me.Vector2d
@function
@param {me.Vector2d} v
@return {Number} angle in radians | [
"return",
"the",
"angle",
"between",
"this",
"vector",
"and",
"the",
"passed",
"one"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L3697-L3699 |
7,258 | melonjs/melonJS | dist/melonjs.js | floorSelf | function floorSelf() {
return this._set(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z));
} | javascript | function floorSelf() {
return this._set(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z));
} | [
"function",
"floorSelf",
"(",
")",
"{",
"return",
"this",
".",
"_set",
"(",
"Math",
".",
"floor",
"(",
"this",
".",
"x",
")",
",",
"Math",
".",
"floor",
"(",
"this",
".",
"y",
")",
",",
"Math",
".",
"floor",
"(",
"this",
".",
"z",
")",
")",
";",
"}"
] | Floor this vector values
@name floorSelf
@memberOf me.Vector3d
@function
@return {me.Vector3d} Reference to this object for method chaining | [
"Floor",
"this",
"vector",
"values"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L4015-L4017 |
7,259 | melonjs/melonJS | dist/melonjs.js | ceil | function ceil() {
return new me.Vector3d(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z));
} | javascript | function ceil() {
return new me.Vector3d(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z));
} | [
"function",
"ceil",
"(",
")",
"{",
"return",
"new",
"me",
".",
"Vector3d",
"(",
"Math",
".",
"ceil",
"(",
"this",
".",
"x",
")",
",",
"Math",
".",
"ceil",
"(",
"this",
".",
"y",
")",
",",
"Math",
".",
"ceil",
"(",
"this",
".",
"z",
")",
")",
";",
"}"
] | Ceil the vector values
@name ceil
@memberOf me.Vector3d
@function
@return {me.Vector3d} new me.Vector3d | [
"Ceil",
"the",
"vector",
"values"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L4026-L4028 |
7,260 | melonjs/melonJS | dist/melonjs.js | ceilSelf | function ceilSelf() {
return this._set(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z));
} | javascript | function ceilSelf() {
return this._set(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z));
} | [
"function",
"ceilSelf",
"(",
")",
"{",
"return",
"this",
".",
"_set",
"(",
"Math",
".",
"ceil",
"(",
"this",
".",
"x",
")",
",",
"Math",
".",
"ceil",
"(",
"this",
".",
"y",
")",
",",
"Math",
".",
"ceil",
"(",
"this",
".",
"z",
")",
")",
";",
"}"
] | Ceil this vector values
@name ceilSelf
@memberOf me.Vector3d
@function
@return {me.Vector3d} Reference to this object for method chaining | [
"Ceil",
"this",
"vector",
"values"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L4037-L4039 |
7,261 | melonjs/melonJS | dist/melonjs.js | setMuted | function setMuted(x, y, z) {
this._x = x;
this._y = y;
this._z = z;
return this;
} | javascript | function setMuted(x, y, z) {
this._x = x;
this._y = y;
this._z = z;
return this;
} | [
"function",
"setMuted",
"(",
"x",
",",
"y",
",",
"z",
")",
"{",
"this",
".",
"_x",
"=",
"x",
";",
"this",
".",
"_y",
"=",
"y",
";",
"this",
".",
"_z",
"=",
"z",
";",
"return",
"this",
";",
"}"
] | set the vector value without triggering the callback
@name setMuted
@memberOf me.ObservableVector3d
@function
@param {Number} x x value of the vector
@param {Number} y y value of the vector
@param {Number} z z value of the vector
@return {me.ObservableVector3d} Reference to this object for method chaining | [
"set",
"the",
"vector",
"value",
"without",
"triggering",
"the",
"callback"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L4872-L4877 |
7,262 | melonjs/melonJS | dist/melonjs.js | add | function add(v) {
return this._set(this._x + v.x, this._y + v.y, this._z + (v.z || 0));
} | javascript | function add(v) {
return this._set(this._x + v.x, this._y + v.y, this._z + (v.z || 0));
} | [
"function",
"add",
"(",
"v",
")",
"{",
"return",
"this",
".",
"_set",
"(",
"this",
".",
"_x",
"+",
"v",
".",
"x",
",",
"this",
".",
"_y",
"+",
"v",
".",
"y",
",",
"this",
".",
"_z",
"+",
"(",
"v",
".",
"z",
"||",
"0",
")",
")",
";",
"}"
] | Add the passed vector to this vector
@name add
@memberOf me.ObservableVector3d
@function
@param {me.Vector2d|me.Vector3d|me.ObservableVector2d|me.ObservableVector3d} v
@return {me.ObservableVector3d} Reference to this object for method chaining | [
"Add",
"the",
"passed",
"vector",
"to",
"this",
"vector"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L4904-L4906 |
7,263 | melonjs/melonJS | dist/melonjs.js | equals | function equals(v) {
return this._x === v.x && this._y === v.y && this._z === (v.z || this._z);
} | javascript | function equals(v) {
return this._x === v.x && this._y === v.y && this._z === (v.z || this._z);
} | [
"function",
"equals",
"(",
"v",
")",
"{",
"return",
"this",
".",
"_x",
"===",
"v",
".",
"x",
"&&",
"this",
".",
"_y",
"===",
"v",
".",
"y",
"&&",
"this",
".",
"_z",
"===",
"(",
"v",
".",
"z",
"||",
"this",
".",
"_z",
")",
";",
"}"
] | return true if the two vectors are the same
@name equals
@memberOf me.ObservableVector3d
@function
@param {me.Vector2d|me.Vector3d|me.ObservableVector2d|me.ObservableVector3d} v
@return {Boolean} | [
"return",
"true",
"if",
"the",
"two",
"vectors",
"are",
"the",
"same"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L5119-L5121 |
7,264 | melonjs/melonJS | dist/melonjs.js | dotProduct | function dotProduct(v) {
return this._x * v.x + this._y * v.y + this._z * (v.z || 1);
} | javascript | function dotProduct(v) {
return this._x * v.x + this._y * v.y + this._z * (v.z || 1);
} | [
"function",
"dotProduct",
"(",
"v",
")",
"{",
"return",
"this",
".",
"_x",
"*",
"v",
".",
"x",
"+",
"this",
".",
"_y",
"*",
"v",
".",
"y",
"+",
"this",
".",
"_z",
"*",
"(",
"v",
".",
"z",
"||",
"1",
")",
";",
"}"
] | return the dot product of this vector and the passed one
@name dotProduct
@memberOf me.ObservableVector3d
@function
@param {me.Vector2d|me.Vector3d|me.ObservableVector2d|me.ObservableVector3d} v
@return {Number} The dot product. | [
"return",
"the",
"dot",
"product",
"of",
"this",
"vector",
"and",
"the",
"passed",
"one"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L5174-L5176 |
7,265 | melonjs/melonJS | dist/melonjs.js | setTransform | 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
a[5] = arguments[5]; // f - m21
a[6] = arguments[6]; // g - m02
a[7] = arguments[7]; // h - m12
a[8] = arguments[8]; // i - m22
} else if (arguments.length === 6) {
a[0] = arguments[0]; // a
a[1] = arguments[2]; // c
a[2] = arguments[4]; // e
a[3] = arguments[1]; // b
a[4] = arguments[3]; // d
a[5] = arguments[5]; // f
a[6] = 0; // g
a[7] = 0; // h
a[8] = 1; // i
}
return this;
} | javascript | 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
a[5] = arguments[5]; // f - m21
a[6] = arguments[6]; // g - m02
a[7] = arguments[7]; // h - m12
a[8] = arguments[8]; // i - m22
} else if (arguments.length === 6) {
a[0] = arguments[0]; // a
a[1] = arguments[2]; // c
a[2] = arguments[4]; // e
a[3] = arguments[1]; // b
a[4] = arguments[3]; // d
a[5] = arguments[5]; // f
a[6] = 0; // g
a[7] = 0; // h
a[8] = 1; // i
}
return this;
} | [
"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",
"a",
"[",
"5",
"]",
"=",
"arguments",
"[",
"5",
"]",
";",
"// f - m21",
"a",
"[",
"6",
"]",
"=",
"arguments",
"[",
"6",
"]",
";",
"// g - m02",
"a",
"[",
"7",
"]",
"=",
"arguments",
"[",
"7",
"]",
";",
"// h - m12",
"a",
"[",
"8",
"]",
"=",
"arguments",
"[",
"8",
"]",
";",
"// i - m22",
"}",
"else",
"if",
"(",
"arguments",
".",
"length",
"===",
"6",
")",
"{",
"a",
"[",
"0",
"]",
"=",
"arguments",
"[",
"0",
"]",
";",
"// a",
"a",
"[",
"1",
"]",
"=",
"arguments",
"[",
"2",
"]",
";",
"// c",
"a",
"[",
"2",
"]",
"=",
"arguments",
"[",
"4",
"]",
";",
"// e",
"a",
"[",
"3",
"]",
"=",
"arguments",
"[",
"1",
"]",
";",
"// b",
"a",
"[",
"4",
"]",
"=",
"arguments",
"[",
"3",
"]",
";",
"// d",
"a",
"[",
"5",
"]",
"=",
"arguments",
"[",
"5",
"]",
";",
"// f",
"a",
"[",
"6",
"]",
"=",
"0",
";",
"// g",
"a",
"[",
"7",
"]",
"=",
"0",
";",
"// h",
"a",
"[",
"8",
"]",
"=",
"1",
";",
"// i",
"}",
"return",
"this",
";",
"}"
] | set the matrix to the specified value
@name setTransform
@memberOf me.Matrix2d
@function
@param {Number} a
@param {Number} b
@param {Number} c
@param {Number} d
@param {Number} e
@param {Number} f
@param {Number} [g=0]
@param {Number} [h=0]
@param {Number} [i=1]
@return {me.Matrix2d} Reference to this object for method chaining | [
"set",
"the",
"matrix",
"to",
"the",
"specified",
"value"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L5306-L5348 |
7,266 | melonjs/melonJS | dist/melonjs.js | multiplyVectorInverse | 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] * a[1]) * invD;
return v;
} | javascript | 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] * a[1]) * invD;
return v;
} | [
"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",
"]",
"*",
"a",
"[",
"1",
"]",
")",
"*",
"invD",
";",
"return",
"v",
";",
"}"
] | Transforms the given vector using the inverted current 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",
"using",
"the",
"inverted",
"current",
"matrix",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L5474-L5482 |
7,267 | melonjs/melonJS | dist/melonjs.js | setShape | 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.radius;
this.radiusSq.set(r, r).scaleV(this.ratio);
this.updateBounds();
return this;
} | javascript | 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.radius;
this.radiusSq.set(r, r).scaleV(this.ratio);
this.updateBounds();
return this;
} | [
"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",
".",
"radius",
";",
"this",
".",
"radiusSq",
".",
"set",
"(",
"r",
",",
"r",
")",
".",
"scaleV",
"(",
"this",
".",
"ratio",
")",
";",
"this",
".",
"updateBounds",
"(",
")",
";",
"return",
"this",
";",
"}"
] | set new value to the Ellipse shape
@name setShape
@memberOf me.Ellipse.prototype
@function
@param {Number} x position of the ellipse
@param {Number} y position of the ellipse
@param {Number} w width (diameter) of the ellipse
@param {Number} h height (diameter) of the ellipse | [
"set",
"new",
"value",
"to",
"the",
"Ellipse",
"shape"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L5760-L5771 |
7,268 | melonjs/melonJS | dist/melonjs.js | scale | 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 | 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);
} | [
"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",
")",
";",
"}"
] | Scale this Ellipse by the specified scalar.
@name scale
@memberOf me.Ellipse.prototype
@function
@param {Number} x
@param {Number} [y=x]
@return {me.Ellipse} Reference to this object for method chaining | [
"Scale",
"this",
"Ellipse",
"by",
"the",
"specified",
"scalar",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L5797-L5800 |
7,269 | melonjs/melonJS | dist/melonjs.js | splitEarcut | 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)) {
// split the polygon in two by the diagonal
var c = splitPolygon(a, b);
// filter colinear points around the cuts
a = filterPoints(a, a.next);
c = filterPoints(c, c.next);
// run earcut on each half
earcutLinked(a, triangles, dim, minX, minY, invSize);
earcutLinked(c, triangles, dim, minX, minY, invSize);
return;
}
b = b.next;
}
a = a.next;
} while (a !== start);
} | javascript | 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)) {
// split the polygon in two by the diagonal
var c = splitPolygon(a, b);
// filter colinear points around the cuts
a = filterPoints(a, a.next);
c = filterPoints(c, c.next);
// run earcut on each half
earcutLinked(a, triangles, dim, minX, minY, invSize);
earcutLinked(c, triangles, dim, minX, minY, invSize);
return;
}
b = b.next;
}
a = a.next;
} while (a !== start);
} | [
"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",
")",
")",
"{",
"// split the polygon in two by the diagonal",
"var",
"c",
"=",
"splitPolygon",
"(",
"a",
",",
"b",
")",
";",
"// filter colinear points around the cuts",
"a",
"=",
"filterPoints",
"(",
"a",
",",
"a",
".",
"next",
")",
";",
"c",
"=",
"filterPoints",
"(",
"c",
",",
"c",
".",
"next",
")",
";",
"// run earcut on each half",
"earcutLinked",
"(",
"a",
",",
"triangles",
",",
"dim",
",",
"minX",
",",
"minY",
",",
"invSize",
")",
";",
"earcutLinked",
"(",
"c",
",",
"triangles",
",",
"dim",
",",
"minX",
",",
"minY",
",",
"invSize",
")",
";",
"return",
";",
"}",
"b",
"=",
"b",
".",
"next",
";",
"}",
"a",
"=",
"a",
".",
"next",
";",
"}",
"while",
"(",
"a",
"!==",
"start",
")",
";",
"}"
] | try splitting polygon into two and triangulate them independently | [
"try",
"splitting",
"polygon",
"into",
"two",
"and",
"triangulate",
"them",
"independently"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L6175-L6198 |
7,270 | melonjs/melonJS | dist/melonjs.js | zOrder | 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;
x = (x | (x << 1)) & 0x55555555;
y = (y | (y << 8)) & 0x00FF00FF;
y = (y | (y << 4)) & 0x0F0F0F0F;
y = (y | (y << 2)) & 0x33333333;
y = (y | (y << 1)) & 0x55555555;
return x | (y << 1);
} | javascript | 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;
x = (x | (x << 1)) & 0x55555555;
y = (y | (y << 8)) & 0x00FF00FF;
y = (y | (y << 4)) & 0x0F0F0F0F;
y = (y | (y << 2)) & 0x33333333;
y = (y | (y << 1)) & 0x55555555;
return x | (y << 1);
} | [
"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",
";",
"x",
"=",
"(",
"x",
"|",
"(",
"x",
"<<",
"1",
")",
")",
"&",
"0x55555555",
";",
"y",
"=",
"(",
"y",
"|",
"(",
"y",
"<<",
"8",
")",
")",
"&",
"0x00FF00FF",
";",
"y",
"=",
"(",
"y",
"|",
"(",
"y",
"<<",
"4",
")",
")",
"&",
"0x0F0F0F0F",
";",
"y",
"=",
"(",
"y",
"|",
"(",
"y",
"<<",
"2",
")",
")",
"&",
"0x33333333",
";",
"y",
"=",
"(",
"y",
"|",
"(",
"y",
"<<",
"1",
")",
")",
"&",
"0x55555555",
";",
"return",
"x",
"|",
"(",
"y",
"<<",
"1",
")",
";",
"}"
] | z-order of a point given coords and inverse of the longer side of data bbox | [
"z",
"-",
"order",
"of",
"a",
"point",
"given",
"coords",
"and",
"inverse",
"of",
"the",
"longer",
"side",
"of",
"data",
"bbox"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L6366-L6382 |
7,271 | melonjs/melonJS | dist/melonjs.js | pointInTriangle | 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 | 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;
} | [
"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",
";",
"}"
] | check if a point lies within a convex triangle | [
"check",
"if",
"a",
"point",
"lies",
"within",
"a",
"convex",
"triangle"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L6397-L6401 |
7,272 | melonjs/melonJS | dist/melonjs.js | area | function area(p, q, r) {
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
} | javascript | function area(p, q, r) {
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
} | [
"function",
"area",
"(",
"p",
",",
"q",
",",
"r",
")",
"{",
"return",
"(",
"q",
".",
"y",
"-",
"p",
".",
"y",
")",
"*",
"(",
"r",
".",
"x",
"-",
"q",
".",
"x",
")",
"-",
"(",
"q",
".",
"x",
"-",
"p",
".",
"x",
")",
"*",
"(",
"r",
".",
"y",
"-",
"q",
".",
"y",
")",
";",
"}"
] | signed area of a triangle | [
"signed",
"area",
"of",
"a",
"triangle"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L6410-L6412 |
7,273 | melonjs/melonJS | dist/melonjs.js | splitPolygon | 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.prev = bp;
return b2;
} | javascript | 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.prev = bp;
return b2;
} | [
"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",
".",
"prev",
"=",
"bp",
";",
"return",
"b2",
";",
"}"
] | link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two; if one belongs to the outer ring and another to a hole, it merges it into a single ring | [
"link",
"two",
"polygon",
"vertices",
"with",
"a",
"bridge",
";",
"if",
"the",
"vertices",
"belong",
"to",
"the",
"same",
"ring",
"it",
"splits",
"polygon",
"into",
"two",
";",
"if",
"one",
"belongs",
"to",
"the",
"outer",
"ring",
"and",
"another",
"to",
"a",
"hole",
"it",
"merges",
"it",
"into",
"a",
"single",
"ring"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L6464-L6483 |
7,274 | melonjs/melonJS | dist/melonjs.js | transform | 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 | 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;
} | [
"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",
";",
"}"
] | apply the given transformation matrix to this Polygon
@name transform
@memberOf me.Polygon.prototype
@function
@param {me.Matrix2d} matrix the transformation matrix
@return {me.Polygon} Reference to this object for method chaining | [
"apply",
"the",
"given",
"transformation",
"matrix",
"to",
"this",
"Polygon"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L6713-L6724 |
7,275 | melonjs/melonJS | dist/melonjs.js | clone | 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 | function clone() {
var copy = [];
this.points.forEach(function (point) {
copy.push(point.clone());
});
return new me.Polygon(this.pos.x, this.pos.y, copy);
} | [
"function",
"clone",
"(",
")",
"{",
"var",
"copy",
"=",
"[",
"]",
";",
"this",
".",
"points",
".",
"forEach",
"(",
"function",
"(",
"point",
")",
"{",
"copy",
".",
"push",
"(",
"point",
".",
"clone",
"(",
")",
")",
";",
"}",
")",
";",
"return",
"new",
"me",
".",
"Polygon",
"(",
"this",
".",
"pos",
".",
"x",
",",
"this",
".",
"pos",
".",
"y",
",",
"copy",
")",
";",
"}"
] | clone this Polygon
@name clone
@memberOf me.Polygon.prototype
@function
@return {me.Polygon} new Polygon | [
"clone",
"this",
"Polygon"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L6992-L6998 |
7,276 | melonjs/melonJS | dist/melonjs.js | setShape | 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); // 0, 1
}
this._super(me.Polygon, "setShape", [x, y, points]); // private properties to cache width & height
this._width = this.points[2].x; // w
this._height = this.points[2].y; // h
return this;
} | javascript | 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); // 0, 1
}
this._super(me.Polygon, "setShape", [x, y, points]); // private properties to cache width & height
this._width = this.points[2].x; // w
this._height = this.points[2].y; // h
return this;
} | [
"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",
")",
";",
"// 0, 1",
"}",
"this",
".",
"_super",
"(",
"me",
".",
"Polygon",
",",
"\"setShape\"",
",",
"[",
"x",
",",
"y",
",",
"points",
"]",
")",
";",
"// private properties to cache width & height",
"this",
".",
"_width",
"=",
"this",
".",
"points",
"[",
"2",
"]",
".",
"x",
";",
"// w",
"this",
".",
"_height",
"=",
"this",
".",
"points",
"[",
"2",
"]",
".",
"y",
";",
"// h",
"return",
"this",
";",
"}"
] | set new value to the rectangle shape
@name setShape
@memberOf me.Rect.prototype
@function
@param {Number} x position of the Rectangle
@param {Number} y position of the Rectangle
@param {Number|Array} w|points width of the rectangle, or an array of vector defining the rectangle
@param {Number} [h] height of the rectangle, if a numeral width parameter is specified
@return {me.Rect} this rectangle | [
"set",
"new",
"value",
"to",
"the",
"rectangle",
"shape"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L7044-L7066 |
7,277 | melonjs/melonJS | dist/melonjs.js | setPoints | 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);
bottom = Math.max(bottom, point.y);
});
this.setShape(x, y, right - x, bottom - y);
return this;
} | javascript | 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);
bottom = Math.max(bottom, point.y);
});
this.setShape(x, y, right - x, bottom - y);
return this;
} | [
"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",
")",
";",
"bottom",
"=",
"Math",
".",
"max",
"(",
"bottom",
",",
"point",
".",
"y",
")",
";",
"}",
")",
";",
"this",
".",
"setShape",
"(",
"x",
",",
"y",
",",
"right",
"-",
"x",
",",
"bottom",
"-",
"y",
")",
";",
"return",
"this",
";",
"}"
] | resize the rectangle to contain all the given points coordinates.
@name setPoints
@memberOf me.Rect.prototype
@function
@param {me.Vector2d[]} points array of vector defining a shape
@return {me.Rect} this shape bounding box Rectangle object | [
"resize",
"the",
"rectangle",
"to",
"contain",
"all",
"the",
"given",
"points",
"coordinates",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L7102-L7115 |
7,278 | melonjs/melonJS | dist/melonjs.js | copy | function copy(rect) {
return this.setShape(rect.pos.x, rect.pos.y, rect._width, rect._height);
} | javascript | function copy(rect) {
return this.setShape(rect.pos.x, rect.pos.y, rect._width, rect._height);
} | [
"function",
"copy",
"(",
"rect",
")",
"{",
"return",
"this",
".",
"setShape",
"(",
"rect",
".",
"pos",
".",
"x",
",",
"rect",
".",
"pos",
".",
"y",
",",
"rect",
".",
"_width",
",",
"rect",
".",
"_height",
")",
";",
"}"
] | copy the position and size of the given rectangle into this one
@name copy
@memberOf me.Rect.prototype
@function
@param {me.Rect} rect Source rectangle
@return {me.Rect} new rectangle | [
"copy",
"the",
"position",
"and",
"size",
"of",
"the",
"given",
"rectangle",
"into",
"this",
"one"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L7163-L7165 |
7,279 | melonjs/melonJS | dist/melonjs.js | union | 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 | 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;
} | [
"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",
";",
"}"
] | merge this rectangle with another one
@name union
@memberOf me.Rect.prototype
@function
@param {me.Rect} rect other rectangle to union with
@return {me.Rect} the union(ed) rectangle | [
"merge",
"this",
"rectangle",
"with",
"another",
"one"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L7202-L7210 |
7,280 | melonjs/melonJS | dist/melonjs.js | containsPoint | function containsPoint(x, y) {
return x >= this.left && x <= this.right && y >= this.top && y <= this.bottom;
} | javascript | function containsPoint(x, y) {
return x >= this.left && x <= this.right && y >= this.top && y <= this.bottom;
} | [
"function",
"containsPoint",
"(",
"x",
",",
"y",
")",
"{",
"return",
"x",
">=",
"this",
".",
"left",
"&&",
"x",
"<=",
"this",
".",
"right",
"&&",
"y",
">=",
"this",
".",
"top",
"&&",
"y",
"<=",
"this",
".",
"bottom",
";",
"}"
] | check if this rectangle contains the specified point
@name containsPoint
@memberOf me.Rect.prototype
@function
@param {Number} x x coordinate
@param {Number} y y coordinate
@return {boolean} true if contains | [
"check",
"if",
"this",
"rectangle",
"contains",
"the",
"specified",
"point"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L7245-L7247 |
7,281 | melonjs/melonJS | dist/melonjs.js | equals | function equals(r) {
return r.left === this.left && r.right === this.right && r.top === this.top && r.bottom === this.bottom;
} | javascript | function equals(r) {
return r.left === this.left && r.right === this.right && r.top === this.top && r.bottom === this.bottom;
} | [
"function",
"equals",
"(",
"r",
")",
"{",
"return",
"r",
".",
"left",
"===",
"this",
".",
"left",
"&&",
"r",
".",
"right",
"===",
"this",
".",
"right",
"&&",
"r",
".",
"top",
"===",
"this",
".",
"top",
"&&",
"r",
".",
"bottom",
"===",
"this",
".",
"bottom",
";",
"}"
] | check if this rectangle is identical to the specified one
@name equals
@memberOf me.Rect.prototype
@function
@param {me.Rect} rect
@return {boolean} true if equals | [
"check",
"if",
"this",
"rectangle",
"is",
"identical",
"to",
"the",
"specified",
"one"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L7257-L7259 |
7,282 | melonjs/melonJS | dist/melonjs.js | removeShape | 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 | 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;
} | [
"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",
";",
"}"
] | remove the specified shape from the body shape list
@name removeShape
@memberOf me.Body
@public
@function
@param {me.Polygon|me.Line|me.Ellipse} shape a shape object
@return {Number} the shape array length | [
"remove",
"the",
"specified",
"shape",
"from",
"the",
"body",
"shape",
"list"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L7944-L7950 |
7,283 | melonjs/melonJS | dist/melonjs.js | computeVelocity | 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) {
this.applyFriction(vel);
} // apply gravity if defined
if (this.gravity.y) {
vel.x += this.gravity.x * this.mass * me.timer.tick;
}
if (this.gravity.y) {
vel.y += this.gravity.y * this.mass * me.timer.tick; // check if falling / jumping
this.falling = vel.y * Math.sign(this.gravity.y) > 0;
this.jumping = this.falling ? false : this.jumping;
} // cap velocity
if (vel.y !== 0) {
vel.y = me.Math.clamp(vel.y, -this.maxVel.y, this.maxVel.y);
}
if (vel.x !== 0) {
vel.x = me.Math.clamp(vel.x, -this.maxVel.x, this.maxVel.x);
}
} | javascript | 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) {
this.applyFriction(vel);
} // apply gravity if defined
if (this.gravity.y) {
vel.x += this.gravity.x * this.mass * me.timer.tick;
}
if (this.gravity.y) {
vel.y += this.gravity.y * this.mass * me.timer.tick; // check if falling / jumping
this.falling = vel.y * Math.sign(this.gravity.y) > 0;
this.jumping = this.falling ? false : this.jumping;
} // cap velocity
if (vel.y !== 0) {
vel.y = me.Math.clamp(vel.y, -this.maxVel.y, this.maxVel.y);
}
if (vel.x !== 0) {
vel.x = me.Math.clamp(vel.x, -this.maxVel.x, this.maxVel.x);
}
} | [
"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",
")",
"{",
"this",
".",
"applyFriction",
"(",
"vel",
")",
";",
"}",
"// apply gravity if defined",
"if",
"(",
"this",
".",
"gravity",
".",
"y",
")",
"{",
"vel",
".",
"x",
"+=",
"this",
".",
"gravity",
".",
"x",
"*",
"this",
".",
"mass",
"*",
"me",
".",
"timer",
".",
"tick",
";",
"}",
"if",
"(",
"this",
".",
"gravity",
".",
"y",
")",
"{",
"vel",
".",
"y",
"+=",
"this",
".",
"gravity",
".",
"y",
"*",
"this",
".",
"mass",
"*",
"me",
".",
"timer",
".",
"tick",
";",
"// check if falling / jumping",
"this",
".",
"falling",
"=",
"vel",
".",
"y",
"*",
"Math",
".",
"sign",
"(",
"this",
".",
"gravity",
".",
"y",
")",
">",
"0",
";",
"this",
".",
"jumping",
"=",
"this",
".",
"falling",
"?",
"false",
":",
"this",
".",
"jumping",
";",
"}",
"// cap velocity",
"if",
"(",
"vel",
".",
"y",
"!==",
"0",
")",
"{",
"vel",
".",
"y",
"=",
"me",
".",
"Math",
".",
"clamp",
"(",
"vel",
".",
"y",
",",
"-",
"this",
".",
"maxVel",
".",
"y",
",",
"this",
".",
"maxVel",
".",
"y",
")",
";",
"}",
"if",
"(",
"vel",
".",
"x",
"!==",
"0",
")",
"{",
"vel",
".",
"x",
"=",
"me",
".",
"Math",
".",
"clamp",
"(",
"vel",
".",
"x",
",",
"-",
"this",
".",
"maxVel",
".",
"x",
",",
"this",
".",
"maxVel",
".",
"x",
")",
";",
"}",
"}"
] | compute the new velocity value
@ignore | [
"compute",
"the",
"new",
"velocity",
"value"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L8120-L8155 |
7,284 | melonjs/melonJS | dist/melonjs.js | QT_ARRAY_POP | 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 {
return new me.QuadTree(bounds, max_objects, max_levels, level);
}
} | javascript | 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 {
return new me.QuadTree(bounds, max_objects, max_levels, level);
}
} | [
"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",
"{",
"return",
"new",
"me",
".",
"QuadTree",
"(",
"bounds",
",",
"max_objects",
",",
"max_levels",
",",
"level",
")",
";",
"}",
"}"
] | will pop a quadtree object from the array
or create a new one if the array is empty | [
"will",
"pop",
"a",
"quadtree",
"object",
"from",
"the",
"array",
"or",
"create",
"a",
"new",
"one",
"if",
"the",
"array",
"is",
"empty"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L8214-L8226 |
7,285 | melonjs/melonJS | dist/melonjs.js | scale | 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 | 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;
} | [
"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",
";",
"}"
] | scale the renderable around his anchor point. Scaling actually applies changes
to the currentTransform member wich is used by the renderer to scale the object
when rendering. It does not scale the object itself. For example if the renderable
is an image, the image.width and image.height properties are unaltered but the currentTransform
member will be changed.
@name scale
@memberOf me.Renderable.prototype
@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.Renderable} Reference to this object for method chaining | [
"scale",
"the",
"renderable",
"around",
"his",
"anchor",
"point",
".",
"Scaling",
"actually",
"applies",
"changes",
"to",
"the",
"currentTransform",
"member",
"wich",
"is",
"used",
"by",
"the",
"renderer",
"to",
"scale",
"the",
"object",
"when",
"rendering",
".",
"It",
"does",
"not",
"scale",
"the",
"object",
"itself",
".",
"For",
"example",
"if",
"the",
"renderable",
"is",
"an",
"image",
"the",
"image",
".",
"width",
"and",
"image",
".",
"height",
"properties",
"are",
"unaltered",
"but",
"the",
"currentTransform",
"member",
"will",
"be",
"changed",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L9890-L9899 |
7,286 | melonjs/melonJS | dist/melonjs.js | resize | function resize(w, h) {
this._super(me.Renderable, "resize", [this.repeatX ? Infinity : w, this.repeatY ? Infinity : h]);
} | javascript | function resize(w, h) {
this._super(me.Renderable, "resize", [this.repeatX ? Infinity : w, this.repeatY ? Infinity : h]);
} | [
"function",
"resize",
"(",
"w",
",",
"h",
")",
"{",
"this",
".",
"_super",
"(",
"me",
".",
"Renderable",
",",
"\"resize\"",
",",
"[",
"this",
".",
"repeatX",
"?",
"Infinity",
":",
"w",
",",
"this",
".",
"repeatY",
"?",
"Infinity",
":",
"h",
"]",
")",
";",
"}"
] | resize the Image Layer to match the given size
@name resize
@memberOf me.ImageLayer.prototype
@function
@param {Number} w new width
@param {Number} h new height | [
"resize",
"the",
"Image",
"Layer",
"to",
"match",
"the",
"given",
"size"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L10448-L10450 |
7,287 | melonjs/melonJS | dist/melonjs.js | onDeactivateEvent | function onDeactivateEvent() {
// cancel all event subscriptions
me.event.unsubscribe(this.vpChangeHdlr);
me.event.unsubscribe(this.vpResizeHdlr);
me.event.unsubscribe(this.vpLoadedHdlr);
} | javascript | function onDeactivateEvent() {
// cancel all event subscriptions
me.event.unsubscribe(this.vpChangeHdlr);
me.event.unsubscribe(this.vpResizeHdlr);
me.event.unsubscribe(this.vpLoadedHdlr);
} | [
"function",
"onDeactivateEvent",
"(",
")",
"{",
"// cancel all event subscriptions",
"me",
".",
"event",
".",
"unsubscribe",
"(",
"this",
".",
"vpChangeHdlr",
")",
";",
"me",
".",
"event",
".",
"unsubscribe",
"(",
"this",
".",
"vpResizeHdlr",
")",
";",
"me",
".",
"event",
".",
"unsubscribe",
"(",
"this",
".",
"vpLoadedHdlr",
")",
";",
"}"
] | called when the layer is removed from the game world or a container | [
"called",
"when",
"the",
"layer",
"is",
"removed",
"from",
"the",
"game",
"world",
"or",
"a",
"container"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L10542-L10547 |
7,288 | melonjs/melonJS | dist/melonjs.js | reverseAnimation | 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 | 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;
} | [
"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",
";",
"}"
] | reverse the given or current animation if none is specified
@name reverseAnimation
@memberOf me.Sprite.prototype
@function
@param {String} [name] animation id
@return {me.Sprite} Reference to this object for method chaining
@see me.Sprite#animationspeed | [
"reverse",
"the",
"given",
"or",
"current",
"animation",
"if",
"none",
"is",
"specified"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L10958-L10966 |
7,289 | melonjs/melonJS | dist/melonjs.js | setRegion | 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
this.current.angle = region.angle; // update the default "current" size
this.width = this.current.width = region.width;
this.height = this.current.height = region.height; // set global anchortPoint if defined
if (region.anchorPoint) {
this.anchorPoint.set(this._flip.x && region.trimmed === true ? 1 - region.anchorPoint.x : region.anchorPoint.x, this._flip.y && region.trimmed === true ? 1 - region.anchorPoint.y : region.anchorPoint.y);
}
return this;
} | javascript | 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
this.current.angle = region.angle; // update the default "current" size
this.width = this.current.width = region.width;
this.height = this.current.height = region.height; // set global anchortPoint if defined
if (region.anchorPoint) {
this.anchorPoint.set(this._flip.x && region.trimmed === true ? 1 - region.anchorPoint.x : region.anchorPoint.x, this._flip.y && region.trimmed === true ? 1 - region.anchorPoint.y : region.anchorPoint.y);
}
return this;
} | [
"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",
"this",
".",
"current",
".",
"angle",
"=",
"region",
".",
"angle",
";",
"// update the default \"current\" size",
"this",
".",
"width",
"=",
"this",
".",
"current",
".",
"width",
"=",
"region",
".",
"width",
";",
"this",
".",
"height",
"=",
"this",
".",
"current",
".",
"height",
"=",
"region",
".",
"height",
";",
"// set global anchortPoint if defined",
"if",
"(",
"region",
".",
"anchorPoint",
")",
"{",
"this",
".",
"anchorPoint",
".",
"set",
"(",
"this",
".",
"_flip",
".",
"x",
"&&",
"region",
".",
"trimmed",
"===",
"true",
"?",
"1",
"-",
"region",
".",
"anchorPoint",
".",
"x",
":",
"region",
".",
"anchorPoint",
".",
"x",
",",
"this",
".",
"_flip",
".",
"y",
"&&",
"region",
".",
"trimmed",
"===",
"true",
"?",
"1",
"-",
"region",
".",
"anchorPoint",
".",
"y",
":",
"region",
".",
"anchorPoint",
".",
"y",
")",
";",
"}",
"return",
"this",
";",
"}"
] | change the current texture atlas region for this sprite
@see me.Texture.getRegion
@name setRegion
@memberOf me.Sprite.prototype
@function
@param {Object} region typically returned through me.Texture.getRegion()
@return {me.Sprite} Reference to this object for method chaining
@example
// change the sprite to "shadedDark13.png";
mySprite.setRegion(game.texture.getRegion("shadedDark13.png")); | [
"change",
"the",
"current",
"texture",
"atlas",
"region",
"for",
"this",
"sprite"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L10996-L11015 |
7,290 | melonjs/melonJS | dist/melonjs.js | setAnimationFrame | function setAnimationFrame(idx) {
this.current.idx = (idx || 0) % this.current.length;
return this.setRegion(this.getAnimationFrameObjectByIndex(this.current.idx));
} | javascript | function setAnimationFrame(idx) {
this.current.idx = (idx || 0) % this.current.length;
return this.setRegion(this.getAnimationFrameObjectByIndex(this.current.idx));
} | [
"function",
"setAnimationFrame",
"(",
"idx",
")",
"{",
"this",
".",
"current",
".",
"idx",
"=",
"(",
"idx",
"||",
"0",
")",
"%",
"this",
".",
"current",
".",
"length",
";",
"return",
"this",
".",
"setRegion",
"(",
"this",
".",
"getAnimationFrameObjectByIndex",
"(",
"this",
".",
"current",
".",
"idx",
")",
")",
";",
"}"
] | force the current animation frame index.
@name setAnimationFrame
@memberOf me.Sprite.prototype
@function
@param {Number} [index=0] animation frame index
@return {me.Sprite} Reference to this object for method chaining
@example
// reset the current animation to the first frame
this.setAnimationFrame(); | [
"force",
"the",
"current",
"animation",
"frame",
"index",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L11028-L11031 |
7,291 | melonjs/melonJS | dist/melonjs.js | onAnchorUpdate | 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 | 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);
} | [
"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",
")",
";",
"}"
] | called when the anchor point value is changed
@private
@name onAnchorUpdate
@memberOf me.Sprite.prototype
@function | [
"called",
"when",
"the",
"anchor",
"point",
"value",
"is",
"changed"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L11131-L11137 |
7,292 | melonjs/melonJS | dist/melonjs.js | update | 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 true;
} // else only return true/false based on the parent function
return updated;
} | javascript | 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 true;
} // else only return true/false based on the parent function
return updated;
} | [
"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",
"true",
";",
"}",
"// else only return true/false based on the parent function",
"return",
"updated",
";",
"}"
] | return true if the object has been clicked
@ignore | [
"return",
"true",
"if",
"the",
"object",
"has",
"been",
"clicked"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L11292-L11308 |
7,293 | melonjs/melonJS | dist/melonjs.js | leave | function leave(event) {
this.hover = false;
this.release.call(this, event);
return this.onOut.call(this, event);
} | javascript | function leave(event) {
this.hover = false;
this.release.call(this, event);
return this.onOut.call(this, event);
} | [
"function",
"leave",
"(",
"event",
")",
"{",
"this",
".",
"hover",
"=",
"false",
";",
"this",
".",
"release",
".",
"call",
"(",
"this",
",",
"event",
")",
";",
"return",
"this",
".",
"onOut",
".",
"call",
"(",
"this",
",",
"event",
")",
";",
"}"
] | function callback for the pointerLeave event
@ignore | [
"function",
"callback",
"for",
"the",
"pointerLeave",
"event"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L11374-L11378 |
7,294 | melonjs/melonJS | dist/melonjs.js | onActivateEvent | 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));
me.input.registerPointerEvent("pointerenter", this, this.enter.bind(this));
me.input.registerPointerEvent("pointerleave", this, this.leave.bind(this));
} | javascript | 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));
me.input.registerPointerEvent("pointerenter", this, this.enter.bind(this));
me.input.registerPointerEvent("pointerleave", this, this.leave.bind(this));
} | [
"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",
")",
")",
";",
"me",
".",
"input",
".",
"registerPointerEvent",
"(",
"\"pointerenter\"",
",",
"this",
",",
"this",
".",
"enter",
".",
"bind",
"(",
"this",
")",
")",
";",
"me",
".",
"input",
".",
"registerPointerEvent",
"(",
"\"pointerleave\"",
",",
"this",
",",
"this",
".",
"leave",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
] | function called when added to the game world or a container
@ignore | [
"function",
"called",
"when",
"added",
"to",
"the",
"game",
"world",
"or",
"a",
"container"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L11444-L11451 |
7,295 | melonjs/melonJS | dist/melonjs.js | onDeactivateEvent | 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.input.releasePointerEvent("pointerleave", this);
me.timer.clearTimeout(this.holdTimeout);
} | javascript | 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.input.releasePointerEvent("pointerleave", this);
me.timer.clearTimeout(this.holdTimeout);
} | [
"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",
".",
"input",
".",
"releasePointerEvent",
"(",
"\"pointerleave\"",
",",
"this",
")",
";",
"me",
".",
"timer",
".",
"clearTimeout",
"(",
"this",
".",
"holdTimeout",
")",
";",
"}"
] | function called when removed from the game world or a container
@ignore | [
"function",
"called",
"when",
"removed",
"from",
"the",
"game",
"world",
"or",
"a",
"container"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L11457-L11465 |
7,296 | melonjs/melonJS | dist/melonjs.js | getChildAt | 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 | 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()");
}
} | [
"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()\"",
")",
";",
"}",
"}"
] | Returns the Child at the specified index
@name getChildAt
@memberOf me.Container.prototype
@function
@param {Number} index | [
"Returns",
"the",
"Child",
"at",
"the",
"specified",
"index"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L11782-L11788 |
7,297 | melonjs/melonJS | dist/melonjs.js | getNextChild | function getNextChild(child) {
var index = this.children.indexOf(child) - 1;
if (index >= 0 && index < this.children.length) {
return this.getChildAt(index);
}
return undefined;
} | javascript | function getNextChild(child) {
var index = this.children.indexOf(child) - 1;
if (index >= 0 && index < this.children.length) {
return this.getChildAt(index);
}
return undefined;
} | [
"function",
"getNextChild",
"(",
"child",
")",
"{",
"var",
"index",
"=",
"this",
".",
"children",
".",
"indexOf",
"(",
"child",
")",
"-",
"1",
";",
"if",
"(",
"index",
">=",
"0",
"&&",
"index",
"<",
"this",
".",
"children",
".",
"length",
")",
"{",
"return",
"this",
".",
"getChildAt",
"(",
"index",
")",
";",
"}",
"return",
"undefined",
";",
"}"
] | Returns the next child within the container or undefined if none
@name getNextChild
@memberOf me.Container
@function
@param {me.Renderable} child | [
"Returns",
"the",
"next",
"child",
"within",
"the",
"container",
"or",
"undefined",
"if",
"none"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L11808-L11816 |
7,298 | melonjs/melonJS | dist/melonjs.js | getChildByType | 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 = objList.concat(obj.getChildByType(_class));
}
}
return objList;
} | javascript | 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 = objList.concat(obj.getChildByType(_class));
}
}
return objList;
} | [
"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",
"=",
"objList",
".",
"concat",
"(",
"obj",
".",
"getChildByType",
"(",
"_class",
")",
")",
";",
"}",
"}",
"return",
"objList",
";",
"}"
] | returns the list of childs with the specified class type
@name getChildByType
@memberOf me.Container.prototype
@public
@function
@param {Object} class type
@return {me.Renderable[]} Array of children | [
"returns",
"the",
"list",
"of",
"childs",
"with",
"the",
"specified",
"class",
"type"
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L11892-L11908 |
7,299 | melonjs/melonJS | dist/melonjs.js | updateChildBounds | 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 instanceof me.Container) {
childBounds = child.childBounds;
} else {
childBounds = child.getBounds();
} // TODO : returns an "empty" rect instead of null (e.g. EntityObject)
// TODO : getBounds should always return something anyway
if (childBounds !== null) {
this.childBounds.union(childBounds);
}
}
}
return this.childBounds;
} | javascript | 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 instanceof me.Container) {
childBounds = child.childBounds;
} else {
childBounds = child.getBounds();
} // TODO : returns an "empty" rect instead of null (e.g. EntityObject)
// TODO : getBounds should always return something anyway
if (childBounds !== null) {
this.childBounds.union(childBounds);
}
}
}
return this.childBounds;
} | [
"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",
"instanceof",
"me",
".",
"Container",
")",
"{",
"childBounds",
"=",
"child",
".",
"childBounds",
";",
"}",
"else",
"{",
"childBounds",
"=",
"child",
".",
"getBounds",
"(",
")",
";",
"}",
"// TODO : returns an \"empty\" rect instead of null (e.g. EntityObject)",
"// TODO : getBounds should always return something anyway",
"if",
"(",
"childBounds",
"!==",
"null",
")",
"{",
"this",
".",
"childBounds",
".",
"union",
"(",
"childBounds",
")",
";",
"}",
"}",
"}",
"return",
"this",
".",
"childBounds",
";",
"}"
] | resizes the child bounds rectangle, based on children bounds.
@name updateChildBounds
@memberOf me.Container.prototype
@function
@return {me.Rect} updated child bounds | [
"resizes",
"the",
"child",
"bounds",
"rectangle",
"based",
"on",
"children",
"bounds",
"."
] | 6c1823cc245df7c958db243a0531506eb838d72c | https://github.com/melonjs/melonJS/blob/6c1823cc245df7c958db243a0531506eb838d72c/dist/melonjs.js#L11949-L11971 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.