Created
September 29, 2012 03:20
-
-
Save krisavi/3803050 to your computer and use it in GitHub Desktop.
some modifications from other branch...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -1293,6 +1293,16 @@ | |
return null; | |
}; | |
+ api.getEntityByID = function(id) | |
+ { | |
+ for (var i = objCount, obj; i--, obj = gameObjects[i];) { | |
+ if(obj.isEntity && obj.settings.id == id) { | |
+ return obj; | |
+ } | |
+ } | |
+ return null; | |
+ }; | |
+ | |
/** | |
* add a HUD obj to the game manager | |
* @name me.game#addHUD | |
@@ -1422,7 +1432,11 @@ | |
}; | |
api.moveToTop = function(shape) { | |
- var biggest = -9999; | |
+ gameObjects.splice(gameObjects.indexOf(shape), 1); | |
+ gameObjects.unshift(shape); | |
+ api.repaint(); | |
+ /* | |
+ var biggest = -9999; | |
for(var i = objCount, obj; i--, obj = gameObjects[i];) { | |
if(obj.z > biggest) biggest = obj.z; | |
} | |
@@ -1433,25 +1447,40 @@ | |
for(var i = objCount, obj; i--, obj = gameObjects[i];) { | |
obj.z = objCount - i; | |
} | |
- | |
+ */ | |
}; | |
/** | |
- * <p>Sort all objects (using object z property value).</p> | |
+ * <p>Sort all the game objects.</p> | |
* <p>Normally all objects loaded through the LevelDirector are automatically sorted. | |
- * this function is however usefull if you create and add object during the game.</p> | |
+ * this function is however usefull if you create and add object during the game, | |
+ * or need a specific sorting algorithm.<p> | |
* @name me.game#sort | |
* @public | |
* @function | |
- */ | |
- | |
- api.sort = function() { | |
- // sort order is inverted, | |
- // since we use a reverse loop for the display | |
- gameObjects.sort(function(a, b) { | |
- return (b.z - a.z); | |
- }); | |
- | |
+ * @param {Function} [sort_func="sorted on z property value"] sort function | |
+ * @example | |
+ * // user defined sort funtion (Z sort based on Y value) | |
+ * function mySort(a, b) { | |
+ * var result = (b.z - a.z); | |
+ * return (result ? result : ((b.pos && b.pos.y) - (a.pos && a.pos.y)) || 0); | |
+ * } </p> | |
+ * // call me.game.sort with our sorting function | |
+ * me.game.sort(mySort); | |
+ */ | |
+ | |
+ api.sort = function(sort_func) { | |
+ if (typeof(sort_func) !== "function") { | |
+ // sort order is inverted, | |
+ // since we use a reverse loop for the display | |
+ gameObjects.sort(function(a, b) { | |
+ return (b.z - a.z); | |
+ }); | |
+ } | |
+ else { | |
+ // user defined sort | |
+ gameObjects.sort(sort_func); | |
+ } | |
// make sure we redraw everything | |
api.repaint(); | |
}; | |
@@ -7200,7 +7229,7 @@ | |
*/ | |
me.input = (function() { | |
- // hold public stuff in our singletong | |
+ // hold public stuff in our singleton | |
var obj = {}; | |
/*--------------------------------------------- | |
@@ -7369,7 +7398,20 @@ | |
} | |
}; | |
- | |
+ function getContainerPos() { | |
+ var obj = me.video.getScreenCanvas(); | |
+ var top = 0; | |
+ var left = 0; | |
+ while (obj && obj.tagName != "BODY") { | |
+ top += obj.offsetTop; | |
+ left += obj.offsetLeft; | |
+ obj = obj.offsetParent; | |
+ } | |
+ return { | |
+ top: top, | |
+ left: left | |
+ }; | |
+ }; | |
/** | |
* translate Mouse Coordinates | |
@@ -7380,8 +7422,20 @@ | |
obj.touches.length=0; | |
// non touch event (mouse) | |
if (!e.touches) { | |
+ /* | |
+ Kris modification start | |
+ Fixed the zoom in and zoom out bug. Lines 7401:7414 included too. | |
+ original lines were: | |
var x = e.pageX - obj.mouse.offset.x; | |
var y = e.pageY - obj.mouse.offset.y; | |
+ */ | |
+ var x = e.clientX - getContainerPos().left + window.pageXOffset; | |
+ var y = e.clientY - getContainerPos().top + window.pageYOffset; | |
+ if (e.type === 'mousedown' || e.type === 'touchstart') | |
+ { | |
+ //console.log(getContainerPos().left, getContainerPos().top); | |
+ } | |
+ /* Kris mdification end */ | |
if (me.sys.scale != 1.0) { | |
x/=me.sys.scale; | |
y/=me.sys.scale; | |
@@ -10611,7 +10665,7 @@ | |
/** @ignore */ | |
me.Tween.Easing.Bounce.EaseIn = function(k) { | |
- return 1 - Tween.Easing.Bounce.EaseOut(1 - k); | |
+ return 1 - me.Tween.Easing.Bounce.EaseOut(1 - k); | |
}; | |
/** @ignore */ | |
@@ -10640,8 +10694,8 @@ | |
me.Tween.Easing.Bounce.EaseInOut = function(k) { | |
if (k < 0.5) | |
- return Tween.Easing.Bounce.EaseIn(k * 2) * 0.5; | |
- return Tween.Easing.Bounce.EaseOut(k * 2 - 1) * 0.5 + 0.5; | |
+ return me.Tween.Easing.Bounce.EaseIn(k * 2) * 0.5; | |
+ return me.Tween.Easing.Bounce.EaseOut(k * 2 - 1) * 0.5 + 0.5; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment