Skip to content

Commit

Permalink
Release 0.6.3
Browse files Browse the repository at this point in the history
* small fixes

* fix bug with isLookScene
* small fix TextureUtil
* fix triggers in j2DsEngine

+ BaseNode.rotateTo()
  • Loading branch information
devinterx committed Apr 23, 2016
1 parent 0fc2c0f commit 934c0ed
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 77 deletions.
6 changes: 3 additions & 3 deletions dist/js/j2ds.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/j2ds.min.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @authors Skaner, DeVinterX
* @license zlib
* @version 0.6.2
* @version 0.6.3
*/

if (global === undefined) {
Expand Down
42 changes: 21 additions & 21 deletions src/js/core/Dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,55 @@
this.j2Ds = j2Ds;
};

Dom.prototype.id = function (_id) {
return document.getElementById(_id);
Dom.prototype.id = function (id) {
return document.getElementById(id);
};

Dom.prototype.name = function (_id) {
return document.getElementsByName(_id)[0];
Dom.prototype.name = function (id) {
return document.getElementsByName(id)[0];
};

Dom.prototype.tag = function (_id, _parent) {
var finder = _parent || document;
return finder.getElementsByTagName(_id);
Dom.prototype.tag = function (id, parent) {
var finder = parent || document;
return finder.getElementsByTagName(id);
};

Dom.prototype.goURL = function (_url) {
document.location.href = _url;
Dom.prototype.goURL = function (url) {
document.location.href = url;
};

Dom.prototype.reloadURL = function () {
document.location.href = document.location.href;
};

Dom.prototype.attach = function (_id, _parent) {
Dom.prototype.attach = function (id, parent) {
var dom = this;
this.j2Ds.events.addEvent('dom:loaded', function (_parent) {
if (!_parent) {
dom.tag('body')[0].appendChild(_id);
this.j2Ds.events.addEvent('dom:loaded', function (parent) {
if (!parent) {
dom.tag('body')[0].appendChild(id);
} else {
dom.id(_parent).appendChild(_id);
dom.id(parent).appendChild(id);
}
});
};

Dom.prototype.injectJavaScript = function (_code) {
var code = _code.toString();
Dom.prototype.injectJavaScript = function (code) {
code = code.toString();
code = code.replace(/[\n\r\t]/g, ';');
document.location.href = 'javascript: var injectFunction = (function() {setTimeout(' + code + ', 0);}); injectFunction();';
};

Dom.prototype.callJava = function (_code) {
document.location.href = 'javacall:' + _code;
Dom.prototype.callJava = function (code) {
document.location.href = 'javacall:' + code;
};

Dom.prototype.send = function (_path, _func) {
Dom.prototype.send = function (path, callback) {
var ajax = new XMLHttpRequest();
ajax.open('GET', _path, true);
ajax.open('GET', path, true);
ajax.onreadystatechange = function () {
if (ajax.readyState == 4) {
if (ajax.status == 200) {
_func(ajax.responseText);
callback(ajax.responseText);
}
}
};
Expand Down
66 changes: 33 additions & 33 deletions src/js/core/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@

/*функции*/

Scene.prototype.setView = function (_id) {
this.view = this.j2Ds.viewManager.views[_id];
Scene.prototype.setView = function (id) {
this.view = this.j2Ds.viewManager.views[id];
};

Scene.prototype.getView = function () {
Expand Down Expand Up @@ -130,8 +130,8 @@
this.origHeight = this.height;
this.width = this.j2Ds.getDeviceManager().width;
this.height = this.j2Ds.getDeviceManager().height;
for (var i in this.j2Ds.layers.list) {
layer = this.j2Ds.layers.list[i];
for (var i in this.j2Ds.layers.layersList) {
layer = this.j2Ds.layers.layersList[i];
tmpCanvas.width = layer.width;
tmpCanvas.height = layer.height;
tmpContext.drawImage(layer.canvas, 0, 0);
Expand All @@ -147,8 +147,8 @@
} else {
this.width = this.origWidth;
this.height = this.origHeight;
for (var i in this.j2Ds.layers.list) {
layer = this.j2Ds.layers.list[i];
for (var i in this.j2Ds.layers.layersList) {
layer = this.j2Ds.layers.layersList[i];
layer.width = this.origWidth;
layer.height = this.origHeight;
layer.canvas.width = this.origWidth;
Expand All @@ -164,16 +164,16 @@
if (!this.canFullScreen) return;
var layer;
if (_true) {
for (var i in this.j2Ds.layers.list) {
layer = this.j2Ds.layers.list[i].canvas;
for (var i in this.j2Ds.layers.layersList) {
layer = this.j2Ds.layers.layersList[i].canvas;
layer.style.width = this.j2Ds.getDeviceManager().width + 'px';
layer.style.height = this.j2Ds.getDeviceManager().height + 'px';
this.offsetWidth = this.j2Ds.getDeviceManager().width;
this.offsetHeight = this.j2Ds.getDeviceManager().height;
}
} else {
for (var i in this.j2Ds.layers.list) {
layer = this.j2Ds.layers.list[i].canvas;
for (var i in this.j2Ds.layers.layersList) {
layer = this.j2Ds.layers.layersList[i].canvas;
layer.style.width = this.width + 'px';
layer.style.height = this.height + 'px';
this.offsetWidth = this.width;
Expand All @@ -198,25 +198,25 @@
}
};

Scene.prototype.init = function (_w, _h, _canDeactivate) {
Scene.prototype.init = function (width, height, canDeactivate) {
var scene = this;

scene.j2Ds.events.onEvent('scene:beforeInit');

scene.width = _w;
scene.height = _h;
scene.width = width;
scene.height = height;

scene.origWidth = _w;
scene.origHeight = _h;
scene.origWidth = width;
scene.origHeight = height;

scene.offsetWidth = _w;
scene.offsetHeight = _h;
scene.offsetWidth = width;
scene.offsetHeight = height;

scene.offsetLeft = 0;
scene.offsetTop = 0;


scene.j2Ds.canDeactivate = _canDeactivate != false;
scene.j2Ds.canDeactivate = canDeactivate != false;

scene.j2Ds.layers.add('sceneNode', 0);

Expand Down Expand Up @@ -250,7 +250,7 @@
}
};

for (var i in scene.j2Ds.layers.list) {
for (var i in scene.j2Ds.layers.layersList) {
scene.j2Ds.dom.attach(scene.j2Ds.layers.layer(i).canvas);
}

Expand All @@ -260,35 +260,35 @@
};
};

Scene.prototype.initCanvas = function (_id, _canDeactivate) {
Scene.prototype.initCanvas = function (id, canDeactivate) {
var scene = this;

scene.canFullScreen = false;

scene.layerName = _id;
scene.layerName = id;

scene.j2Ds.events.onEvent('scene:beforeInit');

scene.width = parseInt(scene.j2Ds.dom.id(_id).width);
scene.height = parseInt(scene.j2Ds.dom.id(_id).height);
scene.width = parseInt(scene.j2Ds.dom.id(id).width);
scene.height = parseInt(scene.j2Ds.dom.id(id).height);

scene.origWidth = scene.width;
scene.origHeight = scene.height;

scene.offsetWidth = parseInt(scene.j2Ds.dom.id(_id).offsetWidth);
scene.offsetHeight = parseInt(scene.j2Ds.dom.id(_id).offsetHeight);
scene.offsetWidth = parseInt(scene.j2Ds.dom.id(id).offsetWidth);
scene.offsetHeight = parseInt(scene.j2Ds.dom.id(id).offsetHeight);

scene.offsetLeft = parseInt(scene.j2Ds.dom.id(_id).offsetLeft);
scene.offsetTop = parseInt(scene.j2Ds.dom.id(_id).offsetTop);
scene.offsetLeft = parseInt(scene.j2Ds.dom.id(id).offsetLeft);
scene.offsetTop = parseInt(scene.j2Ds.dom.id(id).offsetTop);

scene.stylePosition = scene.j2Ds.dom.id(_id).style.position == 'fixed' ? 'fixed' : 'absolute';
scene.stylePosition = scene.j2Ds.dom.id(id).style.position == 'fixed' ? 'fixed' : 'absolute';

scene.j2Ds.canDeactivate = _canDeactivate != false;
scene.j2Ds.canDeactivate = canDeactivate != false;

scene.j2Ds.layers.add(_id, 0, 1);
scene.j2Ds.layers.add(id, 0, 1);

scene.context = scene.j2Ds.layers.layer(_id).context;
scene.canvas = scene.j2Ds.layers.layer(_id).canvas;
scene.context = scene.j2Ds.layers.layer(id).context;
scene.canvas = scene.j2Ds.layers.layer(id).canvas;
scene.visible = true;

scene.cancelClear = false;
Expand Down Expand Up @@ -316,7 +316,7 @@
}
};

for (var i in scene.j2Ds.layers.list) {
for (var i in scene.j2Ds.layers.layersList) {
scene.j2Ds.dom.attach(scene.j2Ds.layers.layer(i).canvas);
}

Expand Down
15 changes: 8 additions & 7 deletions src/js/j2Ds.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @authors Skaner, DeVinterX
* @license zlib
* @version 0.6.2
* @version 0.6.3
*/

(function (root, factory) {
Expand Down Expand Up @@ -104,8 +104,8 @@

/*------------------ 2D движок --------------------*/
var j2DsEngine = function () {
this.vector = {};
this.math = {};
this.vector = {}; //TODO:: is need?
this.math = {}; //TODO:: is need?
this.dom = {};
this.now = Date.now();
this.dt = 0;
Expand All @@ -125,10 +125,10 @@

this.getInfo = function () {
return {
'name': 'j2DsEngine',
'version': '0.6.2',
'git': 'https://github.com/SkanerSoft/j2DsEngine',
'site': 'http://j2DsEngine.ru',
'name': 'j2Ds',
'version': '0.6.3',
'git': 'https://github.com/SkanerSoft/j2Ds',
'site': 'http://j2ds.ru',
'description': 'HTML5 2D Game Engine',
'author': 'Skaner'
};
Expand Down Expand Up @@ -227,6 +227,7 @@
this.dom = new DOM(this);
this.gui = new GUI(this);
this.resources = new ResourceManager(this);
this.trigger = new TriggerManager(this);
this.timeManager = new TimeManager(this);
this.deviceManager = DeviceManager();
this.errorManager = new ErrorManager(this);
Expand Down
2 changes: 1 addition & 1 deletion src/js/managers/ErrorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

ErrorManager.prototype.init = function (_true) {
var errorManager = this;
errorManager.enabled = true;
errorManager.enabled = _true || true;

var runBtn = document.createElement('div');
runBtn.innerHTML = '<b>RUN</b>';
Expand Down
14 changes: 11 additions & 3 deletions src/js/nodes/BaseNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @authors Skaner, DeVinterX
* @license zlib
* @version 0.6.2
* @version 0.6.3
*/

(function (root, factory) {
Expand Down Expand Up @@ -161,8 +161,8 @@
};

BaseNode.prototype.isLookScene = function () {
return (this.pos.x > j2Ds.scene.view.pos.x + j2Ds.scene.width || this.pos.x + this.size.x < j2Ds.scene.view.pos.x)
|| (this.pos.y > j2Ds.scene.view.pos.y + j2Ds.scene.height || this.pos.y + this.size.y < j2Ds.scene.view.pos.y);
return !((this.pos.x > j2Ds.scene.view.pos.x + j2Ds.scene.width || this.pos.x + this.size.x < j2Ds.scene.view.pos.x)
|| (this.pos.y > j2Ds.scene.view.pos.y + j2Ds.scene.height || this.pos.y + this.size.y < j2Ds.scene.view.pos.y));
};

BaseNode.prototype.turn = function (angle) {
Expand All @@ -178,6 +178,14 @@
return this.angle;
};

BaseNode.prototype.rotateTo = function (_to, _t) {
_t = _t ? _t : 1;
this.setRotation((Math.atan2(
(_to.y - this.getPosition().y),
(_to.x - this.getPosition().x)
) * (180 / Math.PI)) / _t);
};

BaseNode.prototype.isOutScene = function () {
var vector = {};

Expand Down
14 changes: 7 additions & 7 deletions src/js/utils/TextureUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @authors Skaner, DeVinterX
* @license zlib
* @version 0.6.2
* @version 0.6.3
*/

(function (root, factory) {
Expand All @@ -21,14 +21,14 @@
this.j2Ds = j2Ds;
};

TextureUtil.prototype.createImageMap = function (_w, _h, callback) {
TextureUtil.prototype.createImageMap = function (width, height, callback) {
var textureUtil = this;
textureUtil.j2Ds.resources.add();
var image = {
img: null,
loaded: false,
width: _w,
height: _h
width: width,
height: height
};

image.img = document.createElement('canvas');
Expand All @@ -51,7 +51,7 @@
};
};

textureUtil.j2Ds.resources.ok('createImageMap_' + w + 'x' + h);
textureUtil.j2Ds.resources.ok('createImageMap_' + width + 'x' + height);

return image;
};
Expand All @@ -71,8 +71,8 @@
image.img.src = path;

image.img.addEventListener('load', function () {
image.width = o.img.width;
image.height = o.img.height;
image.width = image.img.width;
image.height = image.img.height;
image.loaded = true;
textureUtil.j2Ds.resources.ok(path);
});
Expand Down

0 comments on commit 934c0ed

Please sign in to comment.