Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
TileMap/Class question — Gideros Forum

TileMap/Class question

GreywineGreywine Member
edited December 2015 in General questions
o

Likes: MoKaLux

+1 -1 (+1 / -0 )Share on Facebook

Comments

  • o ?
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • o, o, o, Merry Christmas! :)
    My Gideros games: www.totebo.com
    +1 -1 (+2 / -0 )Share on Facebook
  • Hi. Sorry about the post from Tuesday.

    I'm back trying to get a simple roguelike game up and running. That is: a topdown, 2d scroller. I'm using TileMap to get the graphics on the screen. The problem is when I go to change a tile with setTile I get the following error:

    classes/TileMap.lua:62: attempt to call method 'setTile' (a nil value)
    stack traceback:
    classes/TileMap.lua:62: in function 'changeTile'
    main.lua:22: in main chunk

    I'm not sure what that means. I've created a Sprite group that holds -- and successfully displays --all the TileMap layers I want in a variable called self.sWorldlayers in a class called WorldMap.

    Here's the function that's the culprit:

    function WorldMap:changeTile(layer, entry, x, y)
    --this function changes the self.tWorldmap array entry and the tile in self.sWorldlayers
    l = self.tWorldmap[layer]
    l[mapindex(x, y)] = entry
    local s = self.sWorldlayers:getChildAt(layer)
    print(s)
    s:setTile(x, y, entry, 1)
    end

    Maybe it's a class/instance thing? Or a parent/child thing? Or a Sprite/table thing? I admit I'm still fuzzy on some of these relationships.

    Thanks.
    zip
    zip
    RPG 0.2.zip
    1M
  • it looks like setTile isn't something 's' has. So it must be that 's' isn't a tilemap.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • Hi SinisterSoft,

    It looks like self.sWorldlayers isn't coming out of my WorldMap class. When I try to reference in other WorldMap functions, it doesn't work. Any idea why?

    function WorldMap:init()
    self.tWorldmap = {}
    self.sWorldlayers = Sprite.new()

    self.tWorldmap = loadfile("classes/TileSets.lua")()
    local t = Tiles.new(self.tWorldmap[constants.LAYER_BG], "images/tileset-background-108px.png")
    self.sWorldlayers:addChildAt(t, constants.LAYER_BG)
    local t = Tiles.new(self.tWorldmap[constants.LAYER_MONSTERS], "images/tileset-monsters-108px.png")
    self.sWorldlayers:addChildAt(t, constants.LAYER_MONSTERS)
    self.sWorldlayers:setPosition(constants.OFFSET_X, constants.OFFSET_Y)

    self:addChild(self.sWorldlayers)
    end
Sign In or Register to comment.