现在在写coco2dx c++版本中使用js脚本,不知道js部分该怎么写,求大佬指条路…
目前bool result = sc->runScript(“test.js”); 能够返回true, 不过js代码中不能写cocos引擎中的部分(比如Sprite)
求教程,或者demo
感谢
现在在写coco2dx c++版本中使用js脚本,不知道js部分该怎么写,求大佬指条路…
目前bool result = sc->runScript(“test.js”); 能够返回true, 不过js代码中不能写cocos引擎中的部分(比如Sprite)
求教程,或者demo
感谢
官方文档 https://docs.cocos.com/cocos2d-x/manual/zh/scripting/
中的
更详细用法,请参考 Cocos2d-x 引擎的测试项目:tests/lua-tests/src/ComponentTest and tests/js-tests/src/ComponentTest。
没有看懂
var funTest = function(){
console.log("------------ test js");
console.log("------cc:",JSON.stringify(cc));
var rect = new cc.Rect(0,0,4,5);
return 1;
}
funTest();
比如执行这段代码会报错:TypeError: cc.Rect is not a constructor
请问是需要require 那些文件吗?
这个c c.Rect是个函数吧,不是类名,你直接var rect = cc.rect(0,0,4,5)试试