I’m currently trying to get my head around using storyboard and I’m creating a basic scrolly shooter. I’ve got some very basic two layer parallax scrolling working, but what I’d like to do is have some random scenery that spawns every 5 to 10 seconds to make it seem a bit more random. Just as a starter I’ve got eight different tree images (tree1.png, tree2.png etc) that I’d like it to pick from at random.
Problem is, not knowing storyboard very well, I’m not quite sure how to work it.
This is my code so far for the scrolling…
[lua]-- requires
local physics = require “physics”
physics.start()
require “sprite”
local storyboard = require (“storyboard”)
local scene = storyboard.newScene()
local _w=display.contentWidth
local _h=display.contentHeight
local _x=display.contentCenterX
local _y=display.contentCenterY
local _m=math.random
local fgSpeed=2
local bgSpeed=1
print(" “)
print (“Entered Game scene”)
print(” ")
function scene:createScene(event)
local screenGroup = self.view
local background=display.newGroup()
screenGroup:insert(background)
local midground=display.newGroup()
screenGroup:insert(midground)
local foreground=display.newGroup()
screenGroup:insert(foreground)
local bg=display.newRect(background,0,0,_w,_h)
local bgGrad=graphics.newGradient(
{0,0,105}, – Start Color
{68,0,144}, – End Color
“down” – direction
)
bg:setFillColor(bgGrad)
bgfloor=display.newRect(0,_h-50,_w, 50)
bgfloor:setFillColor(0,0,0)
foreground:insert(bgfloor)
ground1=display.newImage(“ground1.png”)
ground1:setReferencePoint(display.BottomLeftReferencePoint)
ground1.x = 0
ground1.startX=1024
ground1.y = _h-50
ground1.speed = fgSpeed
ground1.recycle=1024
foreground:insert(ground1)
ground2=display.newImage(“ground2.png”)
ground2:setReferencePoint(display.BottomLeftReferencePoint)
ground2.x = 1024
ground2.startX=1024
ground2.y = _h-50
ground2.speed = fgSpeed
ground2.recycle=1024
foreground:insert(ground2)
ground3=display.newImage(“ground1.png”)
ground3:setReferencePoint(display.BottomLeftReferencePoint)
ground3.x = 0
ground3.alpha=.5
ground3.startX=1024
ground3.y = _h-75
ground3.speed = bgSpeed
ground3.recycle=1024
background:insert(ground3)
ground4=display.newImage(“ground2.png”)
ground4:setReferencePoint(display.BottomLeftReferencePoint)
ground4.x = 1024
ground4.alpha=.5
ground4.startX=1023
ground4.y = _h-75
ground4.speed = bgSpeed
ground4.recycle=1024
background:insert(ground4)
end
function scrollStuff(self,event)
if self.x < -self.recycle then
self.x = self.startX
else
self.x = self.x - self.speed
end
end
function createStuff(event)
– create stuff here
end
function scene:enterScene(event)
ground1.enterFrame = scrollStuff
Runtime:addEventListener(“enterFrame”, ground1)
ground2.enterFrame = scrollStuff
Runtime:addEventListener(“enterFrame”, ground2)
ground3.enterFrame = scrollStuff
Runtime:addEventListener(“enterFrame”, ground3)
ground4.enterFrame = scrollStuff
Runtime:addEventListener(“enterFrame”, ground4)
end
scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
return scene[/lua]
Any help at all would be greatfuly received.
[import]uid: 7841 topic_id: 35200 reply_id: 335200[/import]