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_ ...
随机推荐
- 0x32 约数
bzoj1053: [HAOI2007]反素数ant bzoj1257: [CQOI2007]余数之和sum Hankson的趣味题 暴力枚举..约数 #include<cstdio> # ...
- redis 五大数据类型的常用指令
STRING 192.168.1.66:6379> get k1 "v1" 192.168.1.66:6379> append k1 12345 (integer) 7 ...
- swift-初探webView与JS交互
公司接下来的项目需要用swift内嵌h5来实现, 以前没有做过swift项目, 现在慢慢将所学的一点一滴记录一下 一个是怕自己忘了- =, 再就是希望大家看到能帮助我哈哈哈 前几天想要直接用swift ...
- 【POJ 2828】Buy Tickets
[题目链接] http://poj.org/problem?id=2828 [算法] 离线用线段树维护序列即可 [代码] #include <algorithm> #include < ...
- Laravel-事件简单使用
Laravel-事件简单使用 标签(空格分隔): php, laravel 注册事件和监听器 生成事件和监听器:php artisan event:generate key => 事件 valu ...
- 求包含每个有序数组(共k个)至少一个元素的最小区间
title: 求包含每个有序数组(共k个)至少一个元素的最小区间 toc: false date: 2018-09-22 21:03:22 categories: OJ tags: 归并 给定k个有序 ...
- Flask上下文管理机制
前引 在了解flask上下文管理机制之前,先来一波必知必会的知识点. 面向对象双下方法 首先,先来聊一聊面向对象中的一些特殊的双下划线方法,比如__call__.__getattr__系列.__get ...
- JQuery 登录窗口的布局
<!-- Button trigger modal --><button type="button" class="btn btn-primary bt ...
- C语言“%”运算符
C语言中运算符“%”是取余运算符,而非取模运算符.(运算符“%”在C/C++, JAVA中,为取余运算,而在Python中为取模运算) 对于一个C语言取余表达式a % b,设其值为result,有如下 ...
- Golden Gate 相关组件介绍:
OGG组件: Manager: 启动其它进程 Collector Extract Data Pump:可选进程,建议使用 Replicat Trails: 可以压缩,加密 Checkpoint OGG ...