切换导航
首页
技术问答
编程语言
前端开发
移动开发
开发工具
程序设计
行业应用
CMS系统
服务器
频道导航
▸ PHP
▸ Java
▸ Java SE
▸ Python
▸ C#
▸ C&C++
▸ Ruby
▸ VB
▸ asp.Net
▸ Go
▸ Perl
▸ netty
▸ Django
▸ Delphi
▸ Jsp
▸ .NET Core
▸ Spring
▸ Flask
▸ Springboot
▸ SpringMVC
▸ Lua
▸ Laravel
▸ Mybatis
▸ Asp
▸ Groovy
▸ ThinkPHP
▸ Yii
▸ swoole
▸ HTML
▸ HTML5
▸ JavaScript
▸ CSS
▸ jQuery
▸ Bootstrap
▸ Angularjs
▸ TypeScript
▸ Vue
▸ Dojo
▸ Json
▸ Electron
▸ Node.js
▸ extjs
▸ Express
▸ XML
▸ ES6
▸ Ajax
▸ Flash
▸ Unity
▸ React
▸ Flex
▸ Ant Design
▸ Web前端
▸ 微信小程序
▸ 微信公众号
▸ iOS
▸ Android
▸ Swift
▸ Hybrid
▸ Cocos2d-x
▸ Flutter
▸ Xcode
▸ Silverlight
▸ cocoa
▸ Cordova
前端之家
Cocos2d-x
cocos2dx-lua 一些公共方法
cocos2dx-lua 一些公共方法
2019-05-18
Cocos2d-x
前端之家
前端之家
收集整理的这篇文章主要介绍了
cocos2dx-lua 一些公共方法
,
前端之家
小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_
502
_0@
function getStringTimeForInt(timeInt)
@H_
502
_0@
if(tonumber(timeInt) <= 0)then
@H_
502
_0@
return "00:00:00"
@H_
502
_0@
elseif(timeInt/60 >= 60)then
@H_
502
_0@
return string.format("%.2d:%.2d:%.2d",timeInt/3600,(timeInt/60)%60,timeInt%60)
@H_
502
_0@
elseif(timeInt >= 60)then
@H_
502
_0@
return string.format("00:%.2d:%.2d",timeInt%60)
@H_
502
_0@
else
@H_
502
_0@
return string.format("00:00:%.2d",timeInt%60)
@H_
502
_0@
end
@H_
502
_0@
end
@H_
502
_0@
-- 将一个时间数转换成"00:00:00"格式
@H_
502
_0@
function getTimeString(timeInt)
@H_
502
_0@
if(tonumber(timeInt) <= 0)then
@H_
502
_0@
return "00:00:00"
@H_
502
_0@
else
@H_
502
_0@
return string.format("%02d:%02d:%02d",math.floor(timeInt/(60*60)),math.floor((timeInt/60)%60),timeInt%60)
@H_
502
_0@
end
@H_
502
_0@
end
@H_
502
_0@
-- 将一个时间数转换成"00时00分00秒"格式
@H_
502
_0@
function getTimeStringFont(timeInt)
@H_
502
_0@
if(tonumber(timeInt) <= 0)then
@H_
502
_0@
return "00时00分00秒"
@H_
502
_0@
else
@H_
502
_0@
return string.format("%02d时%02d分%02d秒",timeInt%60)
@H_
502
_0@
end
@H_
502
_0@
end
@H_
502
_0@
-- nGenTime: 产生时间戳(也可以是一个未来的时间,比如CD时间戳)
@H_
502
_0@
-- nDuration: 固定的有效期间,单位秒,计算某个未来时间的剩余时间时不需要指定
@H_
502
_0@
-- 返回3个结果,第一个是剩余到期时间的字符串,"HH:MM:SS",不足2位
自动
补零;第二个是bool,标识nGenTime是否到期;第三个是剩余秒数
@H_
502
_0@
function expireTimeString( nGenTime,nDuration )
@H_
502
_0@
local nNow = BTUtil:getSvrTimeInterval()
@H_
502
_0@
--CCLuaLog("nGenTime = " .. nGenTime .. " nNow = " .. nNow)
@H_
502
_0@
local nViewSec = (nDuration or 0) - (nNow - nGenTime)
@H_
502
_0@
return getTimeString(nViewSec),nViewSec <= 0,nViewSec
@H_
502
_0@
end
@H_
502
_0@
--得到一个时间戳timeInt与当前时间的相隔天数
@H_
502
_0@
--offset是偏移量,例如凌晨4点:4*60*60
@H_
502
_0@
--return type is integer,0--当天,n--不在同一天,相差n天
@H_
502
_0@
function getDifferDay(timeInt,offset)
@H_
502
_0@
timeInt = tonumber(timeInt or 0)
@H_
502
_0@
offset = tonumber(offset or 0)
@H_
502
_0@
local curTime = tonumber(BTUtil:getSvrTimeInterval()) - offset
@H_
502
_0@
if(os.date("%j",curTime) == 1 and os.date("%j",timeInt - offset) ~= 1)then
@H_
502
_0@
return os.date("%j",curTime) - (os.date("%j",timeInt - offset) - os.date("%j",curTime-24*60*60))
@H_
502
_0@
else--if(os.date("%j",curTime) ~= os.date("%j",timeInt - offset))then
@H_
502
_0@
return os.date("%j",curTime) - os.date("%j",timeInt - offset)
@H_
502
_0@
end
@H_
502
_0@
end
@H_
502
_0@
-- 指定一个日期时间字符串,返回与之对应的东八区(服务器时区)时间戳
@H_
502
_0@
-- sTime: 格式 "2013-07-02 20:00:00"
@H_
502
_0@
function getIntervalByTimeString( sTime )
@H_
502
_0@
local t = string.split(sTime," ")
@H_
502
_0@
local tDate = string.split(t[1],"-")
@H_
502
_0@
local tTime = string.split(t[2],":")
@H_
502
_0@
local tt = os.time({year = tDate[1],month = tDate[2],day = tDate[3],hour = tTime[1],min = tTime[2],sec = tTime[3]})
@H_
502
_0@
local ut = os.date("!*t",tt)
@H_
502
_0@
local east8 = os.time(ut) + 8*60*60 -- UTC时间+8小时转为东八区北京时间
@H_
502
_0@
return east8
@H_
502
_0@
end
@H_
502
_0@
--给一个时间如:153000,得到今天15:30:00的时间戳
@H_
502
_0@
function getIntervalByTime( time )
@H_
502
_0@
local curTime = BTUtil:getSvrTimeInterval()
@H_
502
_0@
local temp = os.date("*t",curTime)
@H_
502
_0@
local h,m,s = string.match(time,"(%d%d)(%d%d)(%d%d)" )
@H_
502
_0@
local timeString = temp.year .."-".. temp.month .."-".. temp.day .." ".. h ..":".. m ..":".. s
@H_
502
_0@
local timeInt = TimeUtil.getIntervalByTimeString(timeString)
@H_
502
_0@
return timeInt
@H_
502
_0@
end
上一篇:cocos2dx游戏优化方向
下一篇:Cocos2dx引擎11-OpenGLES渲染之Sha
猜你在找的Cocos2d-x相关文章
创建自定义的Cocos2d-x场景
操作步骤 1、创建cocos2d-x工程 2、新建 Scene1.cpp Scene1.h Scene1.h代码 #ifndef __SCE...
作者:前端之家 时间:2021-01-27
给vs2010安装上cocos2d-x的模版
开发环境:OS(WINDOWS 8.1 X64 企业版) cocos2d-x 2.2.1 vs2010 想给vs安装上cocos的模版,...
作者:前端之家 时间:2021-01-27
Python创建Cocos2d-x 2.2方法
把创建项目做成一个批处理,当创建项目时可以省时省力很多。 操作步骤 1、在 E:cocos2d-x-...
作者:前端之家 时间:2021-01-27
cocos2dx 物理碰撞
https://www.cnblogs.com/JiaoQing/p/3906780.html 四个响应函数 1 EventListenerPhysics...
作者:前端之家 时间:2020-08-06
cocos2d-js 自定义事件监听派发
转载于 http://www.cnblogs.com/kenkofox/p/3926797.html 熟悉js的dom事件或者flash事件的...
作者:前端之家 时间:2020-08-06
cocos常用 实用 公共函数 lua代码
公共资源加载,缓存retain;防止被自动销毁 2. 数字滚动递增;用于得奖后,总金币跳动增加...
作者:前端之家 时间:2020-08-06
cocos creator box2d
title Map 使用box2d var sfloors = this.tiledMap.getObjectGroup(‘Special_Floor‘).g...
作者:前端之家 时间:2020-08-06
(转)让quick-cocos2d-x支持加密的plist文件
前篇:quick-cocos2d-x图片资源加密 在前篇里面,我们实现了图片资源的加密,但还没有实现...
作者:前端之家 时间:2020-08-06
(转)quick-cocos2d-x图片资源加密(续)
摘要: 对在quick-cocos2d-x上实现的资源加密方法的补充 前篇: quick-cocos2d-x图片资源加...
作者:前端之家 时间:2020-08-06
Cocos Creator 动态改变sprite图片
首先将存放图片最外层文件夹命名为resources changeBj: function(){ var url...
作者:前端之家 时间:2020-08-06
编程分类
iOS
Android
Swift
Hybrid
Cocos2d-x
Flutter
Xcode
Silverlight
cocoa
Cordova
最新文章
• 创建自定义的Cocos2d-x场景
• 给vs2010安装上cocos2d-x的
• Python创建Cocos2d-x 2.2方
• cocos2dx 物理碰撞
• cocos2d-js 自定义事件监听
• cocos2dx 分帧加载
• cocos常用 实用 公共函数
• cocos creator box2d
• (转)让quick-cocos2d-x支
• (转)quick-cocos2d-x图片
热门标签
更多 ►
调试桥
筛选栏
假异步
不会丢失
AndPermissio
权限申请
抽屉式
systemUI
信号栏
多行排列
跨多行显示
viewmode
数据共享
录制语音
视频通话
多行显示
Studio3.5
拉伸控件
望远镜
发动态
走势图
点赞控件
显示牌
冷启动
v3签名
v2签名
v1签名
本地html
外接键盘
流式标签