Cocos2d-Lua-Community 4.0.1 Beta

测试稳定后发布到http://www.cocos2d-lua.org

总揽

在4.0.0发布以来,进过了大量的改进。FairyGUI的支持上踩了大量的坑:绑定补全、hitTest、富文本的支持、window的事件封装等等。Spine的3.8运行时也有大量的改进,进行了同步。新加了Linux的支持个测试,修正了一些问题,但还遗留了EditBox这个已知坑点。加入了AsyncTCP,文档后补吧。TiledMap继续进行功能支持改进。

阅读全文»

cocos2d-x 从离散图片创建帧

local sharedTextureCache = cc.Director:getInstance():getTextureCache()
local sharedSpriteFrameCache = cc.SpriteFrameCache:getInstance()

local imgs = {'14392.PNG', '14393.PNG', '14394.PNG', '14395.PNG'}
for _, img in ipairs(imgs) do
    local tx = sharedTextureCache:addImage(img)
    local rect = tx:getContentSize()
    rect.x = 0
    rect.y = 0
    local frame = cc.SpriteFrame:createWithTexture(tx, rect)
    sharedSpriteFrameCache:addSpriteFrame(frame, img)
end

local frames = display.newFrames("%d.PNG", 14392, 4)
dump(frames)

cocos2d-x lua中使用协程的坑

coroutine.resume 会使用coroutine.create创建的lua_state进行执行,导致to_lua的绑定代码的L会混乱。一些回调函数的执行会破坏参数。

要使用协程,建议coroutine.create中的逻辑无任何to_lua的绑定代码执行。

TexturePacker 命令行自动打包

需求:自动打包文件夹下的所有图片,如果超单纹理大小,自动拆分为多个文件。

TexturePacker  --multipack --texture-format png --format cocos2d --max-width 2048 --max-height 2048 --data {n}.plist --sheet {n}.png /target/rootDirOfPng

注意:rootDirOfPng不会被加入帧名,旗下的二级目录会加入。

计算点到直线的距离

2D 中 (C)
参考:https://www.cnblogs.com/yushuo/p/9304218.html

//点PCx,PCy到线段PAx,PAy,PBx,PBy的距离
double GetNearestDistance(double PAx, double PAy,double PBx, double PBy,double PCx, double PCy)
{     
    double a,b,c;  
    a=getDistanceBtwP(PAy,PAx,PBy,PBx);//经纬坐标系中求两点的距离公式
    b=getDistanceBtwP(PBy,PBx,PCy,PCx);//经纬坐标系中求两点的距离公式
    c=getDistanceBtwP(PAy,PAx,PCy,PCx);//经纬坐标系中求两点的距离公式
    if(b*b>=c*c+a*a)return c;   
    if(c*c>=b*b+a*a)return b;  
    double l=(a+b+c)/2;     //周长的一半   
    double s=sqrt(l*(l-a)*(l-b)*(l-c));  //海伦公式求面积 
    return 2*s/a;   
}

3D 中(C#)
参考:https://www.jianshu.com/p/8ba826e6208a

public static float distancePoint2Line(Vector3 point, Vector3 linePoint1, Vector3 linePoint2)
{
    float fProj = Vector3.Dot(point - linePoint1, (linePoint1 - linePoint2).normalized);
    return Mathf.Sqrt((point - linePoint1).sqrMagnitude - fProj * fProj);
}

ubuntu 18.04中netplan配置pre-up和post-down

  1. netplan 自身配置文件/etc/netplan/50-cloud-init.yaml
network:
    version: 2
    renderer: networkd
    ethernets:
        ens3:
            addresses:
            - 154.204.42.134/24
            gateway4: 154.204.42.254
            match:
                macaddress: fa:16:3e:b9:65:3b
            nameservers:
                addresses:
                - 8.8.8.8
                - 8.8.4.4
            set-name: ens3

应用修改

sudo netplan apply

阅读全文»