Starting scene lua.
StartScene = Core.class(Sprite)
self.onLevel = 1
function StartScene:init()
sceneButton = {}
for i = 1, 9 do
sceneButton[i] = Bitmap.new(Texture.new("images/button.png"))
sceneButton[i]:setScale(0.2, 0.2)
self:addChild(sceneButton[i])
end
sceneButton[1]:setPosition( (conf.maxx/2-sceneButton[1]:getWidth()/2) /4 + 20 , 20)
sceneButton[4]:setPosition((conf.maxx/2-sceneButton[2]:getWidth()/2) / 4 + 20, conf.maxy/2-sceneButton[2]:getHeight()/2)
sceneButton[7]:setPosition((conf.maxx/2-sceneButton[3]:getWidth()/2) / 4 + 20, conf.maxy-sceneButton[3]:getHeight()-20)
------
sceneButton[2]:setPosition(conf.maxx/2-sceneButton[1]:getWidth()/2, 20)
sceneButton[5]:setPosition(conf.maxx/2-sceneButton[2]:getWidth()/2, conf.maxy/2-sceneButton[2]:getHeight()/2)
sceneButton[8]:setPosition(conf.maxx/2-sceneButton[3]:getWidth()/2, conf.maxy-sceneButton[3]:getHeight()-20)
------
sceneButton[3]:setPosition((conf.maxx/2-sceneButton[1]:getWidth()/2) * 1.65, 20)
sceneButton[6]:setPosition((conf.maxx/2-sceneButton[2]:getWidth()/2) * 1.65, conf.maxy/2-sceneButton[2]:getHeight()/2)
sceneButton[9]:setPosition((conf.maxx/2-sceneButton[3]:getWidth()/2) * 1.65, conf.maxy-sceneButton[3]:getHeight()-20)
numberText = {}
for i = 1, 9 do
numberText[i] = TextField.new(nil, i)
numberText[i]:setScale(3)
self:addChild(numberText[i])
numberText[i]:setVisible(false)
end
numberText[1]:setPosition( (conf.maxx/2-numberText[1]:getWidth()/2) /4 + 43,70 )
numberText[2]:setPosition( (conf.maxx/2-numberText[1]:getWidth()/2) /4 + 173,70 )
numberText[3]:setPosition( (conf.maxx/2-numberText[1]:getWidth()/2) /4 + 303,70 )
--
numberText[4]:setPosition( (conf.maxx/2-numberText[1]:getWidth()/2) /4 + 43,172 )
numberText[5]:setPosition( (conf.maxx/2-numberText[1]:getWidth()/2) /4 + 173,172 )
numberText[6]:setPosition( (conf.maxx/2-numberText[1]:getWidth()/2) /4 + 303,172 )
--
numberText[7]:setPosition( (conf.maxx/2-numberText[1]:getWidth()/2) /4 + 43,270 )
numberText[8]:setPosition( (conf.maxx/2-numberText[1]:getWidth()/2) /4 + 173,270 )
numberText[9]:setPosition( (conf.maxx/2-numberText[1]:getWidth()/2) /4 + 303,270 )
self:addEventListener(Event.MOUSE_DOWN, self.btnClick, self)
end
for i = 1, 9 do
if self.onLevel >= i then
numberText[i]:setVisible(true)
end
end
function StartScene:btnClick(event)
local x = event.x
local y = event.y
for i = 1, 9 do
if sceneButton[i]:hitTestPoint(x, y) and numberText[i]:isVisible() then
event:stopPropagation()
sceneManager:changeScene("level1", conf.transitionTime, conf.transition, conf.easing) -- "level[i]" ?
end
end
end |
level 1 lua
if self.points == 60 then
--self.onLevel = self.onLevel + 1
sceneManager:changeScene("start", conf.transitionTime, conf.transition, conf.easing) -- "level[i]" ?
end |
I have a few questions
------------------
1. when I run the program, it crashed, because of the self.onLevel in the start lua. I am trying to set it up so that after 60 points is reached, is switches to the second scene.
2.sceneManager:changeScene("level1", conf.transitionTime, conf.transition, conf.easing) how would you say level[i], instead of level 1? Thanks for the help
Comments
1 - you could use Timer(), os.timer() or Event.ENTERFRAME to add 1 on each call.
I would go for timer class so that you can choose the speed of your counter.
my example would change level on timer events, given the appropriate scenemanager call.
Actually only once if it is placed inside a scene -because changing scene should destroy the first one, that contains the timer .
Coming to the answer of your question, (I hope ) you need something to check if and when 60 points are reached: you can use an enterframe event, and your guess in the first post seems fine to me.
self doesn't exist here.
Try this:
keeping my previous suggestion about self.onLevel, try also including the for statement inside init()