So Ive kind of figured out what I’m doing and kind of not lol. What I have for code right now is a for loop putting random “lily” images on the screen in rows/columns and a jump event to move the frog to the images. the issue is that it only “works” on the first image but won’t work on the rest, but it doesn’t “center” the frog on top of the lily either. the code for that is this:
[lua] local rowCount = 4
local columnCount = 4
local imgSize = 160
for row = 0, rowCount do – Loop through the rows
local col = math.random(columnCount) – Choose a column randomly
local x = (col * imgSize) - imgSize – subtracting imgSize to start from 0
local y = row * imgSize
lily = display.newImageRect(“lily.png”, imgSize, imgSize)
lily.x = x
lily.y = y
lily.anchorX = 0
lily.anchorY = 0
sceneGroup:insert(lily)
end
local frog = display.newImageRect(“frog.png”,160,160)
frog.anchorX = .5
frog.anchorY = .5
frog.x = display.contentCenterX
frog.y = display.contentCenterY + 400
sceneGroup:insert(frog)
local function jump(event)
if event.phase == “began” then
frog.x = lily.x
frog.y = lily.y
end
return true
end
lily:addEventListener(“touch”,jump)
end
scene:addEventListener( “createScene”, scene )
return scene[/lua]
Now to test some theories I had I created a “new” game and made a jump event for each lily on the screen and it works when i click on either of them. The issue with this is that I want to make it so when a jump is made to the lily the images all move down to the previous image and a new one is made on the top of the screen in a random location. Im assuming this has to be done with a loop right? Anywhere is is the code that “works” in the “new” game:
[lua]display.setStatusBar(display.HiddenStatusBar)
water = display.newImageRect(“water.jpg”, 1698, 1131)
water.x = display.contentWidth / 2
water.y = display.contentHeight / 2
lily1 = display.newImageRect(“lily.png”, 160, 160)
lily1.x = display.contentWidth / 2
lily1.y = display.contentHeight / 2
lily2 = display.newImageRect(“lily.png”, 160, 160)
lily2.x = display.contentWidth / 3
lily2.y = display.contentHeight / 3
frog = display.newImageRect(“frog.jpg”, 160, 160)
frog.x = display.contentWidth / 2
frog.y = display.contentHeight
local function jump1(event)
if event.phase == “began” then
frog.x = lily1.x
frog.y = lily1.y
end
return true
end
local function jump2(event)
if event.phase == “began” then
frog.x = lily2.x
frog.y = lily2.y
end
return true
end
local function endGame(event)
if event.phase == “began” then
local text = display.newText(“YOU FELL IN THE WATER!!!”, 315,300,native.systemFont,48)
text:setFillColor(0,0,0)
frog.alpha = 0
end
return true
end[/lua]