{"action":"created","issue":{"url":"https://api.github.com/repos/craftyjs/Crafty/issues/786","labels_url":"https://api.github.com/repos/craftyjs/Crafty/issues/786/labels{/name}","comments_url":"https://api.github.com/repos/craftyjs/Crafty/issues/786/comments","events_url":"https://api.github.com/repos/craftyjs/Crafty/issues/786/events","html_url":"https://github.com/craftyjs/Crafty/issues/786","id":34094997,"number":786,"title":"Init parameters for entities?","user":{"login":"gregtillbrook","id":2115835,"avatar_url":"https://avatars.githubusercontent.com/u/2115835?v=3","gravatar_id":"","url":"https://api.github.com/users/gregtillbrook","html_url":"https://github.com/gregtillbrook","followers_url":"https://api.github.com/users/gregtillbrook/followers","following_url":"https://api.github.com/users/gregtillbrook/following{/other_user}","gists_url":"https://api.github.com/users/gregtillbrook/gists{/gist_id}","starred_url":"https://api.github.com/users/gregtillbrook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gregtillbrook/subscriptions","organizations_url":"https://api.github.com/users/gregtillbrook/orgs","repos_url":"https://api.github.com/users/gregtillbrook/repos","events_url":"https://api.github.com/users/gregtillbrook/events{/privacy}","received_events_url":"https://api.github.com/users/gregtillbrook/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2014-05-22T15:47:33Z","updated_at":"2015-07-27T09:45:35Z","closed_at":"2015-07-27T09:45:35Z","body":"Hiya, Im getting into Crafty atm and really enjoying it - but Im stumped on something that Im hoping is just me missing a trick.\r\n\r\nI have some code like this;\r\n```Javascript\r\nCrafty.c(\"turret\", {\r\n\tshoot:function(){\r\n\t\tCrafty.e('bullet')\r\n\t\t\t.attr({\r\n\t\t\t\tx: this._x + some_math,\r\n\t\t\t\ty: this._y + some_math,\r\n\t\t\t\t//rotation is set here but it's too late \r\n                                //as init already called\r\n\t\t\t\trotation: this._rotation\r\n\t\t\t});\r\n\t}\r\n});\r\n\r\nCrafty.c(\"bullet\", {\r\n\tinit:function(){\r\n\t\tvar bulletSpeed 100;\r\n\r\n\t\t//I want to init the speed here but \r\n                //how to pass turret rotation in?\r\n\t\tthis.xspeed = bulletSpeed * Math.sin(this._rotation);\r\n\t\tthis.yspeed = bulletSpeed * Math.cos(this._rotation);\t\r\n\r\n\t\tthis.bind(\"EnterFrame\", function(params) {\r\n\t\t\tthis.x += this.xspeed;\r\n\t\t\tthis.y -= this.yspeed;\r\n\t\t});\r\n\t}\r\n});\r\n```\r\n\r\nSo you can see my problem is I want to set bullet direction based upon turret at fire time. I'd _like_ to be able to do something like;\r\n```Javascript\r\nCrafty.e('bullet',{\r\n   x: this._x + some_math,\r\n   y: this._y + some_math,\r\n   rotation: this._rotation\r\n });\r\n```\r\nBut it seems like there's no way to pass parameters into the contructor/init method. The best workaround I could see was to define an \"after init\" method to be called like;\r\n```Javascript\r\nCrafty.e('bullet')\r\n   .afterInit({\r\n      x: this._x + some_math,\r\n      y: this._y + some_math,\r\n      rotation: this._rotation\r\n    });\r\n```\r\nBut thats inelegant as it's just cludging a second init method. So - am I missing a cleaner way to do this? Or would this be something you'd be open to adding?\r\n\r\nCheers,\r\nGreg"},"comment":{"url":"https://api.github.com/repos/craftyjs/Crafty/issues/comments/125148638","html_url":"https://github.com/craftyjs/Crafty/issues/786#issuecomment-125148638","issue_url":"https://api.github.com/repos/craftyjs/Crafty/issues/786","id":125148638,"user":{"login":"gregtillbrook","id":2115835,"avatar_url":"https://avatars.githubusercontent.com/u/2115835?v=3","gravatar_id":"","url":"https://api.github.com/users/gregtillbrook","html_url":"https://github.com/gregtillbrook","followers_url":"https://api.github.com/users/gregtillbrook/followers","following_url":"https://api.github.com/users/gregtillbrook/following{/other_user}","gists_url":"https://api.github.com/users/gregtillbrook/gists{/gist_id}","starred_url":"https://api.github.com/users/gregtillbrook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gregtillbrook/subscriptions","organizations_url":"https://api.github.com/users/gregtillbrook/orgs","repos_url":"https://api.github.com/users/gregtillbrook/repos","events_url":"https://api.github.com/users/gregtillbrook/events{/privacy}","received_events_url":"https://api.github.com/users/gregtillbrook/received_events","type":"User","site_admin":false},"created_at":"2015-07-27T09:45:34Z","updated_at":"2015-07-27T09:45:34Z","body":"Ive long since moved on to other things so will close this one down."}}