Game Development Reference
In-Depth Information
self:addChild(frame)
end
With this, we added a background and two other sprites, plus an animation of a
pterodactyl flying in the background. Once again, the calls are remarkably similar
to the ones in C++.
5. Now let's add a menu with a play button (all this still inside the init method):
--create play button
local function playGame()
local bgMusicPath =
cc.FileUtils:getInstance():fullPathForFilename("background.mp3")
cc.SimpleAudioEngine:getInstance():playMusic(bgMusicPath,
true)
local scene = require("GameScene")
local gameScene = scene.create()
cc.Director:getInstance():replaceScene(gameScene)
end
local btnPlay =
cc.MenuItemImage:create("playBtn.png",
"playBtnOver.png")
btnPlay:setPosition(0,0)
btnPlay:registerScriptTapHandler(playGame)
local menu = cc.Menu:create(btnPlay)
menu:setPosition(self.middle.x, 80)
self:addChild(menu)
Typing the button's callback inside the same method where the callback is referenced is
similar to writing a block or even a lambda function in C++.
Search WWH ::




Custom Search