Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to access world when using TiledAsWorldEditor — Gideros Forum

How to access world when using TiledAsWorldEditor

KarrizKarriz Member
edited July 2013 in General questions
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

  • Accepted Answer
    As I remember there is no world in TileAsWorldEditor class. Try to call Self.B2_Worlds[world_id] (world_id default is 0/ or 1)

    Likes: Karriz

    +1 -1 (+1 / -0 )Share on Facebook
  • KarrizKarriz Member
    edited July 2013
    Okay, it seems that the default world is 1 in this case, so calling that should work, but I'm just not sure how.

    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!
Sign In or Register to comment.