I have a SailBoat game that was using a static image for the background. I wanted to try to get the water to move so I tried several things. I ended up using the same image 4 times, each time with a slightly different Width and Height and X and Y placement. I set each image Alpha to be .2 and then I use the transition library to slowly move the images. After tweaking the speed, placement and size I finally have what looks random ocean waves. I am very pleased with how it turned out.
You can check out the effect and test out my game here:
https://dl.dropboxusercontent.com/u/97869025/SailboatBattle.apk
I am a few weeks from publishing the game so please let me know if you find any bugs
Chris Rennie
Here’s the code I use for the effect.
local background = display.newImageRect( “ocean.png”, display.contentWidth+100, display.contentHeight+100 )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = -50, -50
background.alpha=.2
local background2 = display.newImageRect( “ocean.png”, display.contentWidth+140, display.contentHeight+140 )
background2:setReferencePoint( display.TopLeftReferencePoint )
background2.x, background2.y = -50, -50
background2.alpha=.2
local background3 = display.newImageRect( “ocean.png”, display.contentWidth+180, display.contentHeight+180 )
background3:setReferencePoint( display.TopLeftReferencePoint )
background3.x, background3.y = -60, -50
background3.alpha=.2
local background4 = display.newImageRect( “ocean.png”, display.contentWidth+200, display.contentHeight+200 )
background4:setReferencePoint( display.TopLeftReferencePoint )
background4.x, background4.y = -60, -50
background4.alpha=.2
local xx=20
local yy=10
function backListener(e)
xx= -xx
yy=-yy
transition.to(background, {time=4600,x=-50+xx})
transition.to(background2, {time=5000,x=-50-xx})
transition.to(background3, {time=4500,y=-50+yy})
transition.to(background4, {time=5000,y=-50-yy})
timer.performWithDelay(5000, backListener)
end