zoukankan      html  css  js  c++  java
  • (原创) cocos2d-x 3.0+ lua 学习和工作(4) : 公共函数(1): printf 和math扩展

    星月有一段时间没有写博客了,今天聊下3.0 + lua的一些公共函数,主要参考quick_cocos的代码,不想看星月的文章童鞋可以自己去官网下载quick_cocos,呵呵...

    为了避免文章太长,所以分开写了,^_^~!

    星月倾心贡献~~~

    --[[
    -- 输出格式化字符串
    -- example: printf( "The value is %d", num )
    -- @param string fmt 输出格式
    -- @param ... 多参数
    --]]
    function printf( fmt, ... )
        print( string.format( tostring(fmt), ... ) )
    end
    
    --[[
    -- 对数值四舍五入,如果不是数值则返回 0
    -- @param value 数值
    -- @return number 返回一个数
    --]]
    function math.round( value )
        return math.floor( value + 0.5 )
    end
    
    --[[
    -- 角度转弧度
    -- @param angle 角度
    -- @return number 返回弧度
    --]]
    function math.angle2radian( angle )
        return angle*math.pi/180
    end
    
    --[[
    -- 弧度转角度
    -- @param radian 弧度
    -- @return number 返回角度
    --]]
    function math.radian2angle( radian )
        return radian/math.pi*180
    end
    
    --[[
    -- 根据系统时间初始化随机种子,让后续math.random返回更随机的值
    --]]
    function math.newRandomSeed()
        math.randomseed( os.time() )
        math.random()
        math.random()
        math.random()
        math.random()
    end

    作者使用 cocos2d-x 3.0 + lua学习和工作心得,未经作者允许,请勿转载!在此谢谢各位手下留情~~~

    本文没有获得作者本人同意,不得转载,否则必追究相关责任。转载请注明出处!!~~

    原文地址:http://www.cnblogs.com/wodehao0808/p/4015639.html

  • 相关阅读:
    AJAX基础
    DOM事件机制(事件捕获和事件冒泡和事件委托)
    http协议
    DOM实战-js todo
    python常见面试题
    jQuery快速入门
    三级菜单
    购物车
    员工信息表
    random模块
  • 原文地址:https://www.cnblogs.com/wodehao0808/p/4015639.html
Copyright © 2011-2022 走看看