Hi, I'm trying to use the TiledAsWorldEditor tool to make my levels and assign collision detection fixtures to them.
I have a terrain layer and a collision layer, which both seem to work just fine. The polygons show up when I use debugdraw.
gamescene = gideros.class(Sprite)
function gamescene:init()
Level = TiledAsWorldEditor.new("level.lua")
self:addChild(Level)
TiledAsWorldEditor:EnableDebugDrawing(world)
end
The problem is that I now want to add a player "character" to this scene without having to use Tiled editor. I'd just ike to manually add the sprite + body to the world.
Obviously I'd need to use local body = self.world:createBody{type = b2.DYNAMIC_BODY}, but the problem is that "world" is in the TiledAsWorldEditor, and not in my scene. This is why I get the following error when I try to add the body:
gamescene.lua:53: attempt to index field 'world' (a nil value)
Now, how do I use "world" inside my scene so that it works?
Here's the code of the entire scene, hopefully it helps:
http://pastebin.com/9Xwj1AnT
Comments
Likes: Karriz
Ultimate Games on Appstore
Ultimate Games on Google Play
If I just directly write self.B2_Worlds[1], I get the error attempt to index field 'B2_Worlds' (a nil value)
I also tried TiledAsWorldEditor.B2_Worlds[1], but it gives me the same error.
Do I need to use something like recuire() or dofile()?
Edit: Level.B2_Worlds[1] worked!