It looks like you're new here. If you want to get involved, click one of these buttons!
--/////////////////////////////////////////////////////////////////////////////////////////////// --make your grid 2d table grid = {} local gridWidth = application:getContentWidth() / 40 local gridHeight = (application:getContentHeight() / 40) - 1 --so there is room for my menu for i = 1, gridWidth do table.insert(grid,{}) for j = 1, gridHeight do table.insert(grid[i],j) -- Why can't I put brackets around the [j] too? grid[i][j] = Sprite.new() grid[i][j]:addChild(Bitmap.new(Texture.new("images/square.png"))) grid[i][j]:setPosition((i-1) * 40, (j-1) * 40) self:addChild(grid[i][j]) end end --///////////////////////////////////////////////////////////////////////////////////////////////// --x and y coordinates when the object is released local function onMouseUp(self, event) print(event.x, event.y) local break_for_flag = false -- Why is there break_for_flag? for i = 1, gridWidth do for j = 1, gridHeight do if grid[i][j]:hitTestPoint(event.x, event.y) then --Why do I have use hitTestPoint? For some reason self:setPosition(grid[i][j]:getPosition()) --if I do not use hitTestPoint my sprites go -- to coordinate (0,0). break_for_flag = true break end -- Are the for statements there so each square in the grid end -- follows or is exposed (can't think of the right word) to the -- if statement? if break_for_flag then -- Why is this if statement here? break end end if self.isFocus then self.isFocus = false event:stopPropagation() end end |
Comments
Hopefully this helps and isn't too crazy confusing--I haven't had enough coffee today lol--but these forums are pretty friendly as long as you don't expect someone to code up the whole app we are glad to help make things easier
On with the comments!:
Likes: QuasarCreator, chipster123