{"action":"created","issue":{"url":"https://api.github.com/repos/craftyjs/Crafty/issues/954","labels_url":"https://api.github.com/repos/craftyjs/Crafty/issues/954/labels{/name}","comments_url":"https://api.github.com/repos/craftyjs/Crafty/issues/954/comments","events_url":"https://api.github.com/repos/craftyjs/Crafty/issues/954/events","html_url":"https://github.com/craftyjs/Crafty/issues/954","id":101373954,"number":954,"title":"_clamp increases bound values when using scale()","user":{"login":"gopeter","id":1242960,"avatar_url":"https://avatars.githubusercontent.com/u/1242960?v=3","gravatar_id":"","url":"https://api.github.com/users/gopeter","html_url":"https://github.com/gopeter","followers_url":"https://api.github.com/users/gopeter/followers","following_url":"https://api.github.com/users/gopeter/following{/other_user}","gists_url":"https://api.github.com/users/gopeter/gists{/gist_id}","starred_url":"https://api.github.com/users/gopeter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gopeter/subscriptions","organizations_url":"https://api.github.com/users/gopeter/orgs","repos_url":"https://api.github.com/users/gopeter/repos","events_url":"https://api.github.com/users/gopeter/events{/privacy}","received_events_url":"https://api.github.com/users/gopeter/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-08-17T09:04:55Z","updated_at":"2015-08-17T13:04:48Z","closed_at":null,"body":"When `_clamp` is called and `scale()` is set, the bounds increases by every call of `_clamp` because the values are multiplicated by its reference. That's how `console.log(bound.max.x)` looks like:\r\n\r\n![bildschirmfoto 2015-08-17 um 10 56 07](https://cloud.githubusercontent.com/assets/1242960/9301509/4cac72da-44cf-11e5-89bd-b69d1342b5c8.png)\r\n\r\nMaking a deep copy of the bound object solves the problem. Because I don't know how to make a deep copy correctly, I can't provide a pull request. I fixed it very dirty:\r\n\r\n````\r\nvar b = this.bounds || Crafty.map.boundaries();\r\nvar bound = JSON.parse(JSON.stringify(b));\r\n            \r\nbound.max.x *= this._scale;\r\nbound.min.x *= this._scale;\r\nbound.max.y *= this._scale;\r\nbound.min.y *= this._scale;\r\n````\r\n\r\nJust to let you know :)\r\n\r\nAnother problem I've encountered is the calculation of the the viewport when using `follow()` and `scale()` together. The camera doesn't stop on the bottom and right border when reaching the bound because the `scale` factor isn't included in the calculation, so I fixed it like this:\r\n\r\n`if (Crafty.viewport.y < -bound.max.y + Crafty.viewport.height)` becomes `if (Crafty.viewport.y < (-bound.max.y + Crafty.viewport.height) / this._scale)` (and so on).\r\n\r\nYou can check out a demo here: https://debd.com/clients/oetinger/kk-game-pirates-viewport-pirates/test.html\r\n\r\nIf you are going to the very bottom you'll see that the camera does't stop correctly and always shows the player in the middle of the screen even though the game border/bound is already reached."},"comment":{"url":"https://api.github.com/repos/craftyjs/Crafty/issues/comments/131811253","html_url":"https://github.com/craftyjs/Crafty/issues/954#issuecomment-131811253","issue_url":"https://api.github.com/repos/craftyjs/Crafty/issues/954","id":131811253,"user":{"login":"gopeter","id":1242960,"avatar_url":"https://avatars.githubusercontent.com/u/1242960?v=3","gravatar_id":"","url":"https://api.github.com/users/gopeter","html_url":"https://github.com/gopeter","followers_url":"https://api.github.com/users/gopeter/followers","following_url":"https://api.github.com/users/gopeter/following{/other_user}","gists_url":"https://api.github.com/users/gopeter/gists{/gist_id}","starred_url":"https://api.github.com/users/gopeter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gopeter/subscriptions","organizations_url":"https://api.github.com/users/gopeter/orgs","repos_url":"https://api.github.com/users/gopeter/repos","events_url":"https://api.github.com/users/gopeter/events{/privacy}","received_events_url":"https://api.github.com/users/gopeter/received_events","type":"User","site_admin":false},"created_at":"2015-08-17T13:04:48Z","updated_at":"2015-08-17T13:04:48Z","body":"The bounds increases every time the player moves. Bounds should increase only once per scale."}}