Lua下的方法。自己项目经验,个人见解,不能确保正确。

Sprite:

local Light = CCSprite:create("light.png")

            Light:setPosition(ccp(300,300))

            Light:setScale(1)

            Light:setVisible(true)

            self.secondLevelMenuLayer:addChild(Light)

Button:

searchButton = Button:create()

searchButton:setScale(1.2)

    searchButton:setTouchEnabled(true)

    searchButton:loadTextures("button-search1.png","button-search2.png","button-search3.png") -- 3个""不可或缺。可nil。

    searchButton:setPosition(CCPoint(280,400))

    self.superView.secondLevelMenuLayer:addWidget(searchButton)

    searchButton:setEnabled(false)

Button的禁用状态。

在button不可触摸的时候设置图片灰色。

Button:setTouchEnable(false)

同一时候设置Button:setBright(false)

Fade效果

FadeIn->是从暗逐渐变亮

FadeOut->从亮逐渐变消失。

FadeTo->从亮逐渐变暗

local actionTime = 0.2

            local array = CCArray:create()

         

            array:addObject(CCFadeTo:create(0.2, 100))

            local action = CCSequence:create(array)

            self.LayerColor:runAction(action)

当前引擎UI界面不可实现此效果。

Sprite的旋转

local Light = CCSprite:create("light.png")            

            Light:setPosition(ccp(480,510))

            Light:setScale(0.8)

            Light:setVisible(true)

            L = CCRotateBy:create(5,360) --RotateTo角度360就没效果。有网帖

            Light:runAction(CCRepeatForever:create(L))

缩放效果

local ImageView_victory = self.secondLevelMenuLayer:getWidgetByName("ImageView_victory")

            local  array = CCArray:create()

            array:addObject(CCScaleBy:create(0.5,1.5))--參数为time。scale

            array:addObject(CCScaleTo:create(0.5,1))

            local action1 = CCSequence:create(array)

            ImageView_victory:runAction(action1)

UI界面分步载入的实现

local imgs = {} --创建数组

            imgs[1] = ImageView_victory



            local imgs0 = {}

            imgs0[1] = level

            imgs0[2] = shengwang

            imgs0[3] = gold



            local imgs1 = {}

            imgs1[1] = hero0

            imgs1[2] = hero1

            imgs1[3] = hero2

            imgs1[4] = hero3

            imgs1[5] = hero4



            local imgs2 = {}

            imgs2[1] = jingyantiao0

            imgs2[2] = jingyan0

            imgs2[3] = jingyantiao1

            imgs2[4] = jingyan1

            imgs2[5] = jingyantiao2

            imgs2[6] = jingyan2

            imgs2[7] = jingyantiao3

            imgs2[8] = jingyan3

            imgs2[9] = jingyantiao4

            imgs2[10] = jingyan4



            local imgs3 = {}

            imgs3[1] = exp0

            imgs3[2] = exp1

            imgs3[3] = exp2

            imgs3[4] = exp3

            imgs3[5] = exp4



            local imgs4 = {}

            imgs4[1] = ImageView_sun_0

            imgs4[2] = ImageView_sun_1

            imgs4[3] = ImageView_sun_2

            imgs4[4] = ImageView_sun_3

            imgs4[5] = ImageView_sun_4



            local imgs5 = {}

            imgs5[1] = Button_again

            imgs5[2] = Button_share

            imgs5[3] = Button_sure



            local all_imgs = {}

            all_imgs[1] = imgs

            all_imgs[2] = imgs0

            all_imgs[3] = imgs1

            all_imgs[4] = imgs2

            all_imgs[5] = imgs3

            all_imgs[6] = imgs4

            all_imgs[7] = imgs5



            local index = 1

            function callback() --for循环遍历数组



                if all_imgs[index] then

                    for k, v in ipairs(all_imgs[index]) do

                        if v then

                            v:setEnabled(true)

                        end

                end

        end

        index = index +1

        if index >7 then

                self.secondLevelMenuLayer:stopAllActions()

        end

    end



    local array = CCArray:create()

    local callfunc = CCCallFunc:create(callback)

    array:addObject(callfunc)

    local sequence = CCSequence:create(array)

    local forever  = CCRepeatForever:create(sequence)

    self.secondLevelMenuLayer:runAction(forever)

UI上的控件获取须要强转

--战斗结束界面Button实现

    local function back()

        CCDirector:sharedDirector():popScene()

    end



    local Button_close = tolua.cast(self.secondLevelMenuLayer:getWidgetByName("Button_close"),"Button")--lua的强转

    Button_close:setScale(1.3)   

    Button_close:addTouchEventListener(back)



    local Button_sure = self.secondLevelMenuLayer:getWidgetByName("Button_sure")

    Button_sure:addTouchEventListener(back)



    local Button_again = self.secondLevelMenuLayer:getWidgetByName("Button_again")

    local function enterBattle(sender, eventType)

            local pvpScene = PVPScene:new()

            pvpScene:init()

            CCDirector:sharedDirector():pushScene(pvpScene.scene)

    end

    Button_again:addTouchEventListener(enterBattle)

Button直接获取UI

创建UI

FormationUI = class ()



 local ccs = require ("ccs")



 function FormationUI:ctor()



         self.node = GUIReader:shareReader():widgetFromJsonFile("fight-object_1.ExportJson")--当初做的时候json文件出错当时一直崩溃



 end

function FormationUI:init()





end

Button获取UI(不通过scene)

--formationButton

    local function enterFormation(sender,eventType)

            if eventType == ccs.TouchEventType.ended then



                local formationUI = FormationUI.new()

                self.secondLevelMenuLayer:addWidget(formationUI.node)

                formationUI:init()               



            end

    end

    local formationButton = self.menuLayer:getWidgetByName("formationButton")

    formationButton:addTouchEventListener(enterFormation)

获取屏幕尺寸

local visibleSize = CCDirector:sharedDirector():getVisibleSize()

获取json文件

self.node = GUIReader:shareReader():widgetFromJsonFile("battleLose.ExportJson")



加入当前副本指示箭头(跳动效果)



    jiantou = CCSprite:create("image_jiantou.png")

    jiantou:setPosition(ccp(170,460))

    jiantou:setZOrder(1)

    self.superView.secondLevelMenuLayer:addChild(jiantou)



    local actionUp = CCJumpBy:create(20,ccp(0,0),40,20)

    local actionByBack = actionUp:reverse()



    local array = CCArray:create()

    array:addObject(actionUp)

    array:addObject(actionByBack)

    local action = CCSequence:create(array)



    jiantou:runAction(CCRepeatForever:create(action))

显示一精灵的方法。

没有就创建,有就隐藏。sender,eventType调用函数。參数为xy坐标

--显示箭头

function RegionMapUI:showArrow(x, y)

    --假设没有箭头就新建

    if not self.arrow then

        self.arrow = CCSprite:create("image_jiantou.png")

        self.arrow:setZOrder(1000)

        self.arrow:setAnchorPoint(CCPoint(0.52,0.17))

        self.node:addNode(self.arrow)

    end



    --推断是否在运行动画

    if self.arrow:numberOfRunningActions() then

        self.arrow:stopAllActions()

    end



    self.arrow:setVisible(true)

    self.arrow:setPosition(CCPoint(x,y))



    self.arrow:runAction(CCRepeatForever:create(CCJumpBy:create(0.8,ccp(0,0),15,1)))

end



--隐藏箭头

function RegionMapUI:hideArrow()

    --假设有箭头就隐藏

    if self.arrow then

        self.arrow:stopAllActions()

        self.arrow:setVisible(false)

    end

    

end

self:showArrow(sender:getPositionX(), sender:getPositionY())

self.winSize = cc.Director:getInstance():getWinSize()

setPosition(self.winSize.width/2,self.winSize.height/3)

Cocos2d-x-lua学习点滴的更多相关文章

  1. iPhone应用开发 UITableView学习点滴详解

    iPhone应用开发 UITableView学习点滴详解是本文要介绍的内容,内容不多,主要是以代码实现UITableView的学习点滴,我们来看内容. -.建立 UITableView DataTab ...

  2. [转]LUA 学习笔记

    Lua 学习笔记 入门级 一.环境配置 方式一: 1.资源下载http://www.lua.org/download.html 2.用src中的源码创建了一个工程,注释调luac.c中main函数,生 ...

  3. Phonegap学习点滴(2) -- 网络状态检测

    Phonegap学习点滴(2) -- 网络状态检测  http://blog.csdn.net/x251808026/article/details/16992943 方法一:在MainActivit ...

  4. Lua学习笔记(二):基本语法

    Lua学习指南:http://www.lua.org/manual/ 首先我们要明确的一点是:在Lua中,除了关键字外一切都是变量. Lua关键字 可以查看这个地址:http://www.lua.or ...

  5. Lua 学习笔记(一)

    Lua学习笔记 1.lua的优势 a.可扩张性     b.简单     c.高效率     d.和平台无关 2.注释 a.单行注释 --        b.多行注释 --[[  --]] 3.类型和 ...

  6. lua学习:使用Lua处理游戏数据

    在之前lua学习:lua作配置文件里,我们学会了用lua作配置文件. 其实lua在游戏开发中可以作为一个强大的保存.载入游戏数据的工具. 1.载入游戏数据 比如说,现在我有一份表单: data.xls ...

  7. Lua学习笔记6:C++和Lua的相互调用

        曾经一直用C++写代码.话说近期刚换工作.项目组中的是cocos2dx-lua,各种被虐的非常慘啊有木有.     新建cocos2dx-lua项目.打开class能够发现,事实上就是C++项 ...

  8. Lua学习笔记4. coroutine协同程序和文件I/O、错误处理

    Lua学习笔记4. coroutine协同程序和文件I/O.错误处理 coroutine Lua 的协同程序coroutine和线程比较类似,有独立的堆栈.局部变量.独立的指针指令,同时又能共享全局变 ...

  9. nginx+lua学习

    1. nginx+lua学习 1.1. 网关架构 1.2. nginx命令和信号控制 nginx -s stop 快速关闭,不管有没有正在处理的请求 nginx -s quit 优雅关闭方式,推出前完 ...

  10. (转)Lua学习笔记1:Windows7下使用VS2015搭建Lua开发环境

    Lua学习笔记1:Windows7下使用VS2015搭建Lua开发环境(一)注意:工程必须添加两个宏:“配置属性”/“C或C++”/“预处理器”/“预处理器定义”,添加两个宏:_CRT_SECURE_ ...

随机推荐

  1. 初次使用Android Studio时的配置

    一.第一次安装: Android Studio安装完毕后,第一次启动AS前.为了避免又一次下载新版本号的SDK.操作例如以下: AS启动前.请先将bin文件夹的idea.properties文件里添加 ...

  2. 疯狂Java学习笔记(72)-----------大话程序猿面试

    大话程序猿面试 10个我最喜欢问程序猿的面试问题 程序猿面试不全然指南 10个经典的C语言面试基础算法及代码 程序猿的10大成功面试技巧 程序猿选择公司的8个标准 编程开发 8个值得关注的PHP安全函 ...

  3. 升级Xcode8后的相机crash问题-IOS10权限问题

    当我升级到Xcode8后,启动我的相机项目,直接crash,输出的日志如下: '2016-07-08 16:41:11.268943 project-name[362:56625] [MC] Syst ...

  4. USACO 2.2 Runaround Numbers

    Runaround Numbers Runaround numbers are integers with unique digits, none of which is zero (e.g., 81 ...

  5. DB-MySQL:MySQL 索引

    ylbtech-DB-MySQL:MySQL 索引 1.返回顶部 1. MySQL 索引 MySQL索引的建立对于MySQL的高效运行是很重要的,索引可以大大提高MySQL的检索速度. 打个比方,如果 ...

  6. mac下安装postgreSql

    在 mac 下,可以利用 homebrew 直接安装 PostgreSQL: 1 brew install postgresql -v 稍等片刻,PostgreSQL 就安装完成.接下来就是初始数据库 ...

  7. Python学习小计

    1.初学Python最好选择2.7版本,因为大部分Python书籍的示例代码是基于这个版本的 2.Python安装可以参考百度经验完成 如果在电脑上同时安装2个版本,则CMD启动时只需要: py -2 ...

  8. C#中显现串口通信SerialPort类

    SerialPort类的常用属性 名 称 说 明 BaseStream 获取 SerialPort 对象的基础 Stream 对象 BaudRate 获取或设置串行波特率 BreakState 获取或 ...

  9. 使用http-server开启一个本地服务器

    前言 在写前端页面中,经常会在浏览器运行HTML页面,从本地文件夹中直接打开的一般都是file协议,当代码中存在http或https的链接时,HTML页面就无法正常打开,为了解决这种情况,需要在在本地 ...

  10. 深入剖析 iOS 性能优化

    问题种类 时间复杂度 在集合里数据量小的情况下时间复杂度对于性能的影响看起来微乎其微.但如果某个开发的功能是一个公共功能,无法预料调用者传入数据的量时,这个复杂度的优化显得非常重要了.上图列出了各种情 ...