{"action":"created","issue":{"url":"https://api.github.com/repos/qiciengine/qiciengine/issues/7","repository_url":"https://api.github.com/repos/qiciengine/qiciengine","labels_url":"https://api.github.com/repos/qiciengine/qiciengine/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/qiciengine/qiciengine/issues/7/comments","events_url":"https://api.github.com/repos/qiciengine/qiciengine/issues/7/events","html_url":"https://github.com/qiciengine/qiciengine/issues/7","id":133415628,"number":7,"title":"Drawing Sprites from Tiled Objects?","user":{"login":"Morabaraba","id":11364489,"avatar_url":"https://avatars.githubusercontent.com/u/11364489?v=3","gravatar_id":"","url":"https://api.github.com/users/Morabaraba","html_url":"https://github.com/Morabaraba","followers_url":"https://api.github.com/users/Morabaraba/followers","following_url":"https://api.github.com/users/Morabaraba/following{/other_user}","gists_url":"https://api.github.com/users/Morabaraba/gists{/gist_id}","starred_url":"https://api.github.com/users/Morabaraba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Morabaraba/subscriptions","organizations_url":"https://api.github.com/users/Morabaraba/orgs","repos_url":"https://api.github.com/users/Morabaraba/repos","events_url":"https://api.github.com/users/Morabaraba/events{/privacy}","received_events_url":"https://api.github.com/users/Morabaraba/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-13T08:57:40Z","updated_at":"2016-02-16T13:51:17Z","closed_at":null,"body":"Hi,\r\n\r\nI'm trying to create sprites out of my objects.\r\n\r\n```javascript\r\nTileObjectCreator.prototype.awake = function() {\r\n    var self = this;\r\n    console.log('this', this, 'arguments', arguments);\r\n\r\n    console.log( 'layers', this.tilemap ? this.tilemap.layers : undefined); \r\n    if (self.tilemap) {\r\n        // just for debugging\r\n        window.layers = [];\r\n        window.objs = [];\r\n        // loop layers and seachh for ObjectLayer\r\n        self.tilemap.layers.forEach(function(layer, index, array) {\r\n\t\t\tif (layer instanceof qc.ObjectLayer) {\r\n                var tiledLayer = self.tilemap._getLayerJson(index, 'objectgroup');\r\n                window.layers.push(layer);\r\n                tiledLayer.objects.forEach(function(obj, index, array) {  \r\n                    window.objs.push(obj);\r\n                    /*\r\nself.game.assets.load('hall', 'Assets/texture/bbg_cave_hall.bin', function(asset) {\r\n        // 创建精灵对象\r\n        var sprite = self.game.add.sprite();\r\n        sprite.texture = asset;\r\n        sprite.resetNativeSize();\r\n    });\r\n*/\r\n                });\r\n            } \r\n        });\r\n    }\r\n```\r\n\r\nSo previously using phaser I would have\r\n\r\n```javascript\r\n_.each(layer, function(object) {\r\n\t\t\t// So tiled objects can use a key as in a key name you loaded with phaser.load into the cache\r\n\t\t\tvar key;\r\n\t\t\tif (object.properties.key) {\r\n\t\t\t\tkey = object.properties.key;\r\n\t\t\t} else {\r\n\t\t\t\tkey = 'gid-' + object.gid;\r\n\t\t\t\t// here we forge bitmaps from the `tileset[0]` using the gid assigned by [Tiled]\r\n\t\t\t\tvar bitmap = this.game.add.bitmapData(32, 32, key, true);\r\n\t\t\t\t// and how do we know there will only be one tileset\r\n\t\t\t\tthis.tilesets[0].draw(bitmap.context, 0, 0, object.gid);\r\n\t\t\t\t//var bitmap = this.game.add.BitmapData(32, 32, 'gid-' + object.gid, true);\r\n\t\t\t\tkey = bitmap;\r\n\t\t\t}\r\n```\r\n\r\nSo I found `tilemap.tilesets[0]` and see it is a `qc.Atlas` but I want to use the gid to get the frame from the atlas, to use with my sprite.\r\n\r\nI'm sure there must be a easier way?"},"comment":{"url":"https://api.github.com/repos/qiciengine/qiciengine/issues/comments/184689934","html_url":"https://github.com/qiciengine/qiciengine/issues/7#issuecomment-184689934","issue_url":"https://api.github.com/repos/qiciengine/qiciengine/issues/7","id":184689934,"user":{"login":"armoonqici","id":16714266,"avatar_url":"https://avatars.githubusercontent.com/u/16714266?v=3","gravatar_id":"","url":"https://api.github.com/users/armoonqici","html_url":"https://github.com/armoonqici","followers_url":"https://api.github.com/users/armoonqici/followers","following_url":"https://api.github.com/users/armoonqici/following{/other_user}","gists_url":"https://api.github.com/users/armoonqici/gists{/gist_id}","starred_url":"https://api.github.com/users/armoonqici/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/armoonqici/subscriptions","organizations_url":"https://api.github.com/users/armoonqici/orgs","repos_url":"https://api.github.com/users/armoonqici/repos","events_url":"https://api.github.com/users/armoonqici/events{/privacy}","received_events_url":"https://api.github.com/users/armoonqici/received_events","type":"User","site_admin":false},"created_at":"2016-02-16T13:51:17Z","updated_at":"2016-02-16T13:51:17Z","body":"1. Pack the atlas.\r\n2. using like:\r\n`sprite.texture = atlas;\r\nsprite.frame = gid-0;\r\nsprite.resetNativeSize();`\r\n"}}