Cocos2d-x-lua学习点滴
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学习点滴的更多相关文章
- iPhone应用开发 UITableView学习点滴详解
iPhone应用开发 UITableView学习点滴详解是本文要介绍的内容,内容不多,主要是以代码实现UITableView的学习点滴,我们来看内容. -.建立 UITableView DataTab ...
- [转]LUA 学习笔记
Lua 学习笔记 入门级 一.环境配置 方式一: 1.资源下载http://www.lua.org/download.html 2.用src中的源码创建了一个工程,注释调luac.c中main函数,生 ...
- Phonegap学习点滴(2) -- 网络状态检测
Phonegap学习点滴(2) -- 网络状态检测 http://blog.csdn.net/x251808026/article/details/16992943 方法一:在MainActivit ...
- Lua学习笔记(二):基本语法
Lua学习指南:http://www.lua.org/manual/ 首先我们要明确的一点是:在Lua中,除了关键字外一切都是变量. Lua关键字 可以查看这个地址:http://www.lua.or ...
- Lua 学习笔记(一)
Lua学习笔记 1.lua的优势 a.可扩张性 b.简单 c.高效率 d.和平台无关 2.注释 a.单行注释 -- b.多行注释 --[[ --]] 3.类型和 ...
- lua学习:使用Lua处理游戏数据
在之前lua学习:lua作配置文件里,我们学会了用lua作配置文件. 其实lua在游戏开发中可以作为一个强大的保存.载入游戏数据的工具. 1.载入游戏数据 比如说,现在我有一份表单: data.xls ...
- Lua学习笔记6:C++和Lua的相互调用
曾经一直用C++写代码.话说近期刚换工作.项目组中的是cocos2dx-lua,各种被虐的非常慘啊有木有. 新建cocos2dx-lua项目.打开class能够发现,事实上就是C++项 ...
- Lua学习笔记4. coroutine协同程序和文件I/O、错误处理
Lua学习笔记4. coroutine协同程序和文件I/O.错误处理 coroutine Lua 的协同程序coroutine和线程比较类似,有独立的堆栈.局部变量.独立的指针指令,同时又能共享全局变 ...
- nginx+lua学习
1. nginx+lua学习 1.1. 网关架构 1.2. nginx命令和信号控制 nginx -s stop 快速关闭,不管有没有正在处理的请求 nginx -s quit 优雅关闭方式,推出前完 ...
- (转)Lua学习笔记1:Windows7下使用VS2015搭建Lua开发环境
Lua学习笔记1:Windows7下使用VS2015搭建Lua开发环境(一)注意:工程必须添加两个宏:“配置属性”/“C或C++”/“预处理器”/“预处理器定义”,添加两个宏:_CRT_SECURE_ ...
随机推荐
- JPEG压缩图像超分辨率重建算法
压缩图像超分辨率重建算法学习 超分辨率重建是由一幅或多幅的低分辨率图像重构高分辨率图像,如由4幅1m分辨率的遥感图像重构分辨率0.25m分辨率图像.在军用/民用上都有非常大应用. 眼下的超分辨率重建方 ...
- MFC exe使用C++ dll中的std::string 崩溃
VC6中 MFC exe中 new 纯C++ dll dll 崩溃 我把纯C++的 dll,用/MTd 换成/MDd.就能够了
- 【DataStructure】The difference among methods addAll(),retainAll() and removeAll()
In the Java collection framework, there are three similar methods, addAll(),retainAll() and removeAl ...
- Android: HowTo设置app不被系统kill掉
有一种方法可以设置app永远不会被kill,AndroidManifest.xml 中添加: android:persistent="true" 适用于放在/system/app下 ...
- SQL Server 内存使用情况
• 查看设置的最大与最小内存: exec sp_configure 'max server memory (MB)' exec sp_configure 'min server memory (MB) ...
- TFS源代码管理工具:
源代码管理: 先获取最新版本,再签入.如发现错误,可以点击--源代码管理--获取特定版本撤回修改 1.签入:(要备注,测试通过后签入) 敏捷开发:(小步快跑):小部分功能开发完成测试通过后就签入 全部 ...
- 关于idlf无法输入中文的解决办法
最近在学习python 但是刚开始写程序的时候发现无法输入中文 上网查发现有不少mac端的IDLF也存在这个问题 导致这个问题的原因可能不唯一 但是大多数原因应该是Mac 系统自带的 Tcl/Tk ...
- SQL的where执行顺序
SQL的where执行顺序 1 mysql 从左到右. 一个原则,排除越多的条件放到第一个 例子:抄的. SELECT … WHERE p.languages_id = 1 AND m.languag ...
- 利用PBFunc在Powerbuilder中进行FTP操作
PBFunc.dll包含了FTP的操作,使用FTP时主要需要以下步骤: 1.调用of_Login函数登录Ftp服务器 2.调用FTP的各种方法 3.Ftp操作完毕后调用of_LoginOut方法进行注 ...
- innerHTML 与 outerHTML区别
示例代码: <div id="test"> <p>这是innerHTML</p> <p>这是innerHTML</p> ...