Skip to content

Instantly share code, notes, and snippets.

@geoffb
Created January 10, 2011 17:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geoffb/773101 to your computer and use it in GitHub Desktop.
Save geoffb/773101 to your computer and use it in GitHub Desktop.
ImpactJS Weltmiester: Don't consider entity offset when snapping to grid.
diff --git a/htdocs/lib/weltmeister/edit-entities.js b/htdocs/lib/weltmeister/edit-entities.js
index f9d9250..6272f3e 100644
--- a/htdocs/lib/weltmeister/edit-entities.js
+++ b/htdocs/lib/weltmeister/edit-entities.js
@@ -141,7 +141,7 @@ wm.EditEntities = ig.Class.extend({
for( var i = 0; i < this.entities.length; i++ ) {
var ent = this.entities[i];
if( ent.touches(this.selector) ) {
- this.selector.offset = {x: (x - ent.pos.x + ent.offset.x), y: (y - ent.pos.y + ent.offset.y)};
+ this.selector.offset = {x: (x - ent.pos.x), y: (y - ent.pos.y)};
this.selectEntity( ent );
this.wasSelectedOnScaleBorder = this.isOnScaleBorder( ent, this.selector );
return ent;
@@ -236,11 +236,9 @@ wm.EditEntities = ig.Class.extend({
moveSelectedEntity: function( x, y ) {
x =
- ( (x - this.selector.offset.x ) / this.gridSize ).round()
- * this.gridSize + this.selectedEntity.offset.x;
+ ( (x - this.selector.offset.x ) / this.gridSize ).round() * this.gridSize;
y =
- ( (y - this.selector.offset.y ) / this.gridSize ).round()
- * this.gridSize + this.selectedEntity.offset.y;
+ ( (y - this.selector.offset.y ) / this.gridSize ).round() * this.gridSize;
// new position?
if( this.selectedEntity.pos.x != x || this.selectedEntity.pos.y != y ) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment