u014314614
奏响曲
采纳率0%
2017-05-29 06:18 阅读 1.1k

Cocos2d-x Lua初学者:按照官方案例敲的图片无法显示

5

目录结构

这个是MainScene.lua文件

local MainScene = class("MainScene", cc.load("mvc").ViewBase)

--创建菜单
local function CreateTestMenu()
    local menuLayer = cc.Layer:create()
    --返回回调
    local function clossCallback()
        cc.Director:getInstance():endToLua()
    end

    --添加关闭菜单
    local  s = cc.Director:getInstance():getWinSize()
    local CloseItem = cc.MenuItemImage:create("Images/close.png", "Images/close.png")
    CloseItem:registerScriptTapHandler(clossCallback)
    CloseItem:setPosition(cc.p(s.width - 30, s.height - 30))

    local CloseMenu = cc.Menu:create()
    CloseMenu:setPosition(0, 0)
    CloseMenu:addChild(CloseItem)
    menuLayer:addChild(CloseMenu)
    local targetPlatform = cc.Application:getInstance():getTargetPlatform()
    if (cc.PLATFORM_OS_IPHONE == targetPlatform) or (cc.PLATFORM_OS_IPAD == targetPlatform) then
        CloseMenu:setVisible(false)
    end

    return menuLayer
end

function MainScene:onCreate()

    local scene = cc.Scene:create()
    scene:addChild(CreateTestMenu())
    if cc.Director:getInstance():getRunningScene() then
        cc.Director:getInstance():replaceScene(scene)
    else
        cc.Director:getInstance():runWithScene(scene)
    end

end

return MainScene

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

相关推荐