Yes i see it i am changing the code. Dropping the icons from both sides is kind of tricky and btw why are you using the
pcall function for…
like this one:
pcall(function() table.insert(self.imageCache, iconObj) end)
Yes i see it i am changing the code. Dropping the icons from both sides is kind of tricky and btw why are you using the
pcall function for…
like this one:
pcall(function() table.insert(self.imageCache, iconObj) end)
lol, because at one point in my sleep deprivation I had gotten to the point of not really caring if it inserted into the image cache or not lol
disclaimer: I don’t really recommend what I did but there are times when it has its uses inside of lua.
pcall is a really good way to try something without error-ing back to the app
try{ //do something } catch(e){ //do nothing on error just keep moving along //because we don't care if it throws an error }
Hehe So i did what you said
its all one array now, i made a function that adds icons in the middle indexes for all columns because i dont want that empty.
The problem is in another function i made a function that handles the touch,
If i move left:
if gEvent.xStart > gEvent.x and swipeLength > 10 then
print(“swipe left”)
for columnX=1,6 do
local tmpObj = self.topGrid[columnX][6].gridObj
if columnX == 1 then
table.insert(self.topGrid[7],6,tmpObj)
table.remove(self.topGrid[7],6)
transition.to(tmpObj, {transition = easing.outBack, time = 200, x = 722, onComplete = function(iObj) end})
else
table.insert(self.topGrid[columnX - 1],6,tmpObj)
table.remove(self.topGrid[columnX - 1],6)
transition.to(tmpObj, {transition = easing.outBack, time = 200, x = tmpObj.x - 107, onComplete = function(iObj) end})
end
end
How do you move the icons…they are not stored in the array lol and is this the best way to do it:
array = 1,2,3,4,5,6,7
if move left it should look like this array = 2,3,4,5,6,7,1
the numbers are icons
No real need to add/remove like that ie: table.insert, table.remove you can simply just add a index value to the icon like index = 1, index = 2 etc. and then just get the index from grid table for its x/y etc. and then just transition that way.
You are on the right path but a lot of the answer to the question “is this the best way” really depends on other factors like for example if a match is found do you destroy the match and load in more icons or do they lock or remain in the grid etc.
The grid itself should always remain intact and only the actual value of what is in the grid position should be changed, the rest should be just moving to those grid positions and updating data.
But if i want to “match” the icons (3 or more) i should know where they are in the grid…and moving the x value is just the icon it self… i cant match based on that…right ??
My biggest problem stays i dont know how to move the icons they are not inside the self.topGrid[x][y].gridObj its another table in it
Just so its clear the top and bottom grids can be shoved into the middle pushing the other away (if there is room)
|F|
A|B|C
D| |E
swipe up from the first index:
A|F|
D|B|C
| |E
I will be away from computer until tomorrow, but I will write you a up a quick Check function that can check matches and if it can swipe down/left etc. which should give you an idea of how to move forward
Thanks m8 for helping. I think the first game you make is the most important game to understand it all.
There are 2 scenarios I can come up with but I don’t know if corona supports that.
First one:
In the grid make a variable with the name for the sprite. Make a draw function that checks the whole grid and draws all the sprites.(loop).
Second one:
Moving the display elements in the arrays but I don’t know if this is possible I don’t understand how you can move a display that is already in a element in a array. Every time i get into the gridObj directly and move the x nothing happens. And to check if there is a match I need to move the elements in the array.
I tried allot but i dont think this can work…you cant know which icon is where to match i really think i have to use the grid and shift the objects with every swipe and draw the animation.
function scene:AddMiddleIcons() local tmpIcons = {"icon\_1", "icon\_2", "icon\_3", "icon\_4", "icon\_5"} local speed = 500 for columnX=1,7 do local gridObj = self.topGrid[columnX][6].gridObj print(gridObj.x) local iconObj = display.newImage(self.sceneGroup, self.gameArtSheet , self.gameArtInfo:getFrameIndex(tmpIcons[math.random(1, 5)])) self.topGrid[columnX][6].gridObj = iconObj iconObj.anchorX, iconObj.anchorY = 0.5, 0.5 iconObj.x = gridObj.x + (gridObj.width \* .5) iconObj.y = (gridObj.y + (gridObj.height \* .5)) self.topGrid[columnX][6].gridObj = iconObj iconObj.xScale,iconObj.yScale = 4 iconObj.alpha = 0 transition.to(iconObj, {transition = easing.outBounce, time=speed,alpha = 1,xScale = 1,yScale = 1, onComplete=function(iObj) self.topGrid[columnX][6].iconObj = iObj self.topGrid[columnX][6].active = true end }) speed = speed + 100 end local mContainer = display.newRect((display.contentWidth \* .5),(self.topBG.y + self.topBG.height), 749, 100) mContainer.anchorX, mContainer.anchorY = 0.5, 0 mContainer:setFillColor(0,0,0,0.01) mContainer.touch = function(gObj, gEvent) local swipeLengthX = math.abs(gEvent.x - gEvent.xStart) local swipeLengthY = math.abs(gEvent.y - gEvent.yStart) local t = gEvent.target local phase = gEvent.phase if "began" == phase then return true elseif "ended" == phase or "cancelled" == phase then if gEvent.xStart \> gEvent.x and swipeLengthX \> 10 then print("swipe left") shift(self.topGrid,"left") for columnX=1,#self.topGrid do local tmpObj = self.topGrid[columnX][6].gridObj if tmpObj.x \< 85 then tmpObj.x = 742 transition.to(tmpObj, {transition = easing.outBack, time = 200, x = 722, onComplete = function(iObj) end}) else -- table.insert(self.topGrid[columnX - 1],6,tmpObj) -- table.remove(self.topGrid[columnX - 1],6) transition.to(tmpObj, {transition = easing.outBack, time = 200, x = tmpObj.x - 107, onComplete = function(iObj)end}) end end elseif gEvent.xStart \< gEvent.x and swipeLengthX \> 10 then print("swipe right") for columnX=1,#self.topGrid do local tmpObj = self.topGrid[columnX][6].gridObj if tmpObj.x \> 710 then tmpObj.x = 60 transition.to(tmpObj, {transition = easing.outBack, time = 200, x = 80, onComplete = function(iObj) end}) else transition.to(tmpObj, {transition = easing.outBack, time = 200, x = tmpObj.x + 107, onComplete = function(iObj)end}) end end elseif gEvent.yStart \< gEvent.y and swipeLengthY \> 10 then print("swipe down") for columnY=1,11 do local tmpObj = self.topGrid[1][columnY].gridObj transition.to(tmpObj, {transition = easing.outBack, time = 200, y = tmpObj.y + 100, onComplete = function(iObj) end}) end end end return true end mContainer:addEventListener("touch") mContainer:toFront() end
Pretty sure it will work as below is one of the very first games I made using corona and it was made in under a week using the same type of logic and it isn’t very polished and was more of a proof of concept for something else I was working on.
Google Play
https://play.google.com/store/apps/details?id=com.purplebean.uguessit
iTunes
https://itunes.apple.com/us/app/u-guess-it/id635813137?mt=8
It plays much better on iPad as I had no idea what was what on Google Play at the time
Anyhoot, I am going to piece together some stuff for you just got really swamped next few days then I will be getting back to it
I tried everything to get it into a table and move the grid but lua doesnt have allot of choice like other languages. you cant even store a 2d array simple, its very weird lol.
But what i wanted to say is what was your idea to do a check if the same icons…can you explain it…?
Hey Christopher I got a long way with your help. I am moving the grids and so on but I have a question.
When the icons enter the field with a transition to. Sometimes I am moving that column up or down but the transition to is already set to go to the y that was empty at the moment it moved but after I moved the column up a icon is shifted to it. Now the icons are on top of each other and one does not exist in the table (it’s overwritten)
How can such a problem be solved if you know what I mean ?