It looks like you're new here. If you want to get involved, click one of these buttons!
Game = Core.class(Sprite) function Game:init() application:setBackgroundColor(0x303030) local size = 6 self.grid = Sprite.new() local function generateGrid(size) for i = 1, size do for j = 1, size do local cell = Pixel.new(0x4F4F4F, 1, W / size - 2, W / size - 2) cell:setAnchorPoint(0.5, 0.5) cell:setPosition((W / size) * j - W / size / 2, (W / size) * i - W / size / 2) cell.xOrd = j cell.yOrd = i self.grid:addChild(cell) local indx = (i - 1) * size + j self.grid:getChildAt(indx):addEventListener(Event.MOUSE_DOWN, cellTouched(indx), self) end end self:addChild(self.grid) end generateGrid(size) end function cellTouched(self, event) local cell = self.grid:getChildAt(7) if cell:hitTestPoint(event.x, event.y) then cell:setColor(0xCFCFCF) print(cell.xOrd, cell.yOrd) end end |
Comments
Likes: definisto
Likes: MoKaLux
Likes: MoKaLux