加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

(12) 初学cocos2dx lua

发布时间:2020-12-14 19:26:30 所属栏目:百科 来源:网络整理
导读:最基本的层 [plain] view plain copy functioncreateInGameLayer() localinGameLayer=cc.Layer:create() returninGameLayer end 最基本的场景 localsceneGame=cc.Scene:create() sceneGame:addChild(createInGameLayer()) cc.Director:getInstance():runWith

最基本的层

[plain] view plain copy
  1. functioncreateInGameLayer()
  2. localinGameLayer=cc.Layer:create()
  3. returninGameLayer
  4. end

最基本的场景

    localsceneGame=cc.Scene:create()
  1. sceneGame:addChild(createInGameLayer())
  2. cc.Director:getInstance():runWithScene(sceneGame)
  3. cc.Director:getInstance():replaceScene(cc.TransitionFade:create(1,WelcomeScene.createScene()))

最基本的精灵

    localbg=cc.Sprite:create("farm.jpg")
  1. bg:setAnchorPoint(0,0)
  2. inGameLayer:addChild(bg)
  3. returninGameLayer
  4. end

最基本的定时器
    localfunctiontick()
  1. end
  2. cc.Director:getInstance():getScheduler():scheduleScriptFunc(tick,false)


最基本的触摸事件

    localtouchBeginPoint=nil
  1. localfunctiononTouchBegan(touch,event)
  2. locallocation=touch:getLocation()
  3. cclog("onTouchBegan:%0.2f,%0.2f",location.x,location.y)
  4. touchBeginPoint={x=location.x,y=location.y}
  5. --CCTOUCHBEGANeventmustreturntrue
  6. --[[多点
  7. fori=1,table.getn(touches)do
  8. locallocation=touches[i]:getLocation()
  9. Sprite1.addNewSpriteWithCoords(Helper.currentLayer,location)
  10. ]]--
  11. returntrue
  12. end
  13. localfunctiononTouchMoved(touch,248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> cclog("onTouchMoved:%0.2f,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> iftouchBeginPointthen
  14. localcx,cy=layerFarm:getPosition()
  15. layerFarm:setPosition(cx+location.x-touchBeginPoint.x,
  16. cy+location.y-touchBeginPoint.y)
  17. localfunctiononTouchEnded(touch,event)
  18. locallocation=touch:getLocation()
  19. cclog("onTouchEnded:%0.2f,location.y)
  20. touchBeginPoint=nil
  21. spriteDog.isPaused=false
  22. locallistener=cc.EventListenerTouchOneByOne:create()
  23. --locallistener=cc.EventListenerTouchAllAtOnce:create()多点
  24. listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN)
  25. listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED)
  26. listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED)
  27. localeventDispatcher=layerFarm:getEventDispatcher()
  28. eventDispatcher:addEventListenerWithSceneGraphPriority(listener,layerFarm)

最基本的音乐
    --localbgMusicPath=CCFileUtils:getInstance():fullPathForFilename("background.ogg")
  1. localbgMusicPath=cc.FileUtils:getInstance():fullPathForFilename("background.mp3")
  2. cc.SimpleAudioEngine:getInstance():playMusic(bgMusicPath,true)
  3. localeffectPath=cc.FileUtils:getInstance():fullPathForFilename("effect1.wav")
  4. cc.SimpleAudioEngine:getInstance():preloadEffect(effectPath)
  5. localfunctionmenuCallbackOpenPopup()
  6. --looptestsoundeffect
  7. effectID=cc.SimpleAudioEngine:getInstance():playEffect(effectPath)
  8. menuPopup:setVisible(true)
  9. 最基本的加载图片
      cc.Director:getInstance():getTextureCache():addImageAsync("DartBlood.png",imageLoaded)
    1. localtexture0=cc.Director:getInstance():getTextureCache():addImage("Images/grossini_dance_atlas.png")
    2. functionLoadingScene.imageLoaded(pObj)
    3. --body
    4. cc.Director:getInstance():getTextureCache():removeTextureForKey("Images/grossinis_sister1-testalpha.png")
    5. cc.Director:getInstance():getTextureCache():removeAllTextures()
    6. cc.Director:getInstance():getTextureCache():removeUnusedTextures()
    7. localcache=cc.SpriteFrameCache:getInstance()
    8. cache:addSpriteFrames("animations/grossini_gray.plist","animations/grossini_gray.png")
    9. SpriteFrameTest.m_pSprite1=cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")

    最基础的动作

      localfunctionCallFucnCallback1()
    1. localaction=cc.Sequence:create(
    2. cc.MoveBy:create(2,cc.p(200,0)),
    3. cc.CallFunc:create(CallFucnCallback1))
    4. grossini:runAction(action)

    最基础的字符格式化

      string.format("grossini_dance_%02d.png",j+1)

    最基础的按钮
      localstart=cc.Sprite:createWithSpriteFrameName("start.png")
    1. localstartItem=cc.MenuItemSprite:create(start,start,start)
    2. localfunctionmenuCallback(sender)
    3. cclog("menuCallback...")
    4. --tolua.cast(ret:getParent(),"cc.LayerMultiplex"):switchTo(1)
    5. startItem:registerScriptTapHandler(menuCallback)
    6. startItem:setPosition(50,50)
    7. localmenu=cc.Menu:create()
    8. menu:addChild(startItem)
    9. menu:setPosition(0,0)
    10. layer:addChild(menu)

    (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读