Game Development Reference
In-Depth Information
Time for action - creating a menu scene
Let's create a new file and add a menu scene to our game:
1. Right-click on the src folder and select New | Lua File ; call the new file MenuS-
cene.lua .
2. 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")
3. 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 con-
structor (always called ctor ), but I wanted to stress the importance of returning
the class at the end of its declaration.
4. So moving just below the constructor, let's continue building up our scene:
Search WWH ::




Custom Search