Time for action – creating a menu scene
Let's create a new file and add a menu scene to our game:
- Right-click on the
src
folder and select New | Lua File; call the new fileMenuScene.lua
. - Let's create a class that extends a scene. We first load our own module of all the game's constants (this file already exists in the starter project):
local constants = require ("constants")
- Then we build our class:
local MenuScene = class("MenuScene", function() return cc.Scene:create() end) function MenuScene.create() local scene = MenuScene.new() return scene end function MenuScene:ctor() self.visibleSize = cc.Director:getInstance():getVisibleSize() self.middle = {x = self.visibleSize.width * 0.5, y = self.visibleSize.height * 0.5} self.origin = cc.Director:getInstance():getVisibleOrigin() self:init() end return MenuScene
We'll add the methods next, including the
init
method we called in the class constructor (always calledctor...