初学cocos2dx lua 最基本的知识

初学cocos2dx lua 最基本的知识,第1张

概述尊重版权,仅为个人使用,转载自:http://blog.csdn.net/w18767104183/article/details/21177589 最基本的层 [plain]  view plain copy function createInGameLayer()            local inGameLayer = cc.Layer:create()           return

尊重版权,仅为个人使用,转载自:http://blog.csdn.net/w18767104183/article/details/21177589

最基本的层

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

最基本的场景

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

最基本的精灵

localbg=cc.Sprite:create("farm.jpg") bg:setAnchorPoint(0,0) inGameLayer:addChild(bg) returninGameLayer end
最基本的定时器
localfunctiontick() end cc.Director:getInstance():getScheduler():scheduleScriptFunc(tick,false)


最基本的触摸事件

localtouchBeginPoint=nil localfunctionontouchBegan(touch,event) locallocation=touch:getLocation() cclog("ontouchBegan:%0.2f,%0.2f",location.x,location.y) touchBeginPoint={x=location.x,y=location.y} --CCtouchBEGANeventmustreturntrue --[[多点 fori=1,table.getn(touches)do locallocation=touches[i]:getLocation() Sprite1.addNewSpriteWithCoords(Helper.currentLayer,location) ]]-- returntrue end localfunctionontouchmoved(touch,248)"> 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 localcx,cy=layerFarm:getposition() layerFarm:setposition(cx+location.x-touchBeginPoint.x, cy+location.y-touchBeginPoint.y) localfunctionontouchended(touch,event) locallocation=touch:getLocation() cclog("ontouchended:%0.2f,location.y) touchBeginPoint=nil spriteDog.isPaused=false localListener=cc.EventListenertouchOneByOne:create() --localListener=cc.EventListenertouchAllAtOnce:create()多点 Listener:registerScriptHandler(ontouchBegan,cc.Handler.EVENT_touch_BEGAN) Listener:registerScriptHandler(ontouchmoved,cc.Handler.EVENT_touch_MOVED) Listener:registerScriptHandler(ontouchended,cc.Handler.EVENT_touch_ENDED) localeventdispatcher=layerFarm:getEventdispatcher() eventdispatcher:addEventListenerWithSceneGraPHPriority(Listener,layerFarm)
最基本的音乐
--localbgMusicPath=CCfileUtils:getInstance():fullPathForfilename("background.ogg") localbgMusicPath=cc.fileUtils:getInstance():fullPathForfilename("background.mp3") cc.SimpleAudioEngine:getInstance():playMusic(bgMusicPath,true) localeffectPath=cc.fileUtils:getInstance():fullPathForfilename("effect1.wav") cc.SimpleAudioEngine:getInstance():preloadEffect(effectPath) localfunctionmenuCallbackOpenPopup() --looptestsoundeffect effectID=cc.SimpleAudioEngine:getInstance():playEffect(effectPath) menuPopup:setVisible(true) 最基本的加载图片
cc.Director:getInstance():getTextureCache():addImageAsync("DartBlood.png",imageLoaded) localtexture0=cc.Director:getInstance():getTextureCache():addImage("Images/grossini_dance_atlas.png") functionLoadingScene.imageLoaded(pObj) --body cc.Director:getInstance():getTextureCache():removeTextureForKey("Images/grossinis_sister1-testAlpha.png") cc.Director:getInstance():getTextureCache():removeAllTextures() cc.Director:getInstance():getTextureCache():removeUnusedTextures() localcache=cc.SpriteFrameCache:getInstance() cache:addSpriteFrames("animations/grossini_gray.pList","animations/grossini_gray.png") SpriteFrameTest.m_pSprite1=cc.Sprite:createWithSpriteFramename("grossini_dance_01.png")
最基础的动作

localfunctionCallFucnCallback1() localaction=cc.Sequence:create( cc.MoveBy:create(2,cc.p(200,0)), cc.CallFunc:create(CallFucnCallback1)) grossini:runAction(action)
最基础的字符格式化

string.format("grossini_dance_%02d.png",j+1)
最基础的按钮
localstart=cc.Sprite:createWithSpriteFramename("start.png") localstartItem=cc.MenuItemSprite:create(start,start,start) localfunctionmenuCallback(sender) cclog("menuCallback...") --tolua.cast(ret:getParent(),"cc.LayerMultiplex"):switchTo(1) startItem:registerScriptTapHandler(menuCallback) startItem:setposition(50,50) localmenu=cc.Menu:create() menu:addChild(startItem) menu:setposition(0,0) layer:addChild(menu) 总结

以上是内存溢出为你收集整理的初学cocos2dx lua 最基本的知识全部内容,希望文章能够帮你解决初学cocos2dx lua 最基本的知识所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1072490.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存