cocos-vuecli-demo/cocosTem/assets/web2gameSDk.ts

89 lines
2.0 KiB
TypeScript
Raw Permalink Normal View History

2021-04-09 06:43:19 +00:00
cc.web2cocosSDK = {
// 根据页码切换游戏
changeGameByPageIndex: (pageIndex, callback) => { },
/**
*
*
* @param {String} sceneName
* @param {*} callFunc
*/
loadScene(sceneName) {
return new Promise((resolve, reject) => {
cc.director.loadScene(sceneName, err => {
if (!err) {
resolve(sceneName)
} else {
reject(err);
}
});
})
},
/**
* prefab
*
* @param {String} name
* @param {Function} callFunc
*/
loadGame: (gameName, callFunc) => { },
// 卸载游戏
unloadGame: () => {
},
/**
*
*
* @param {String} name
* @param {Function} callFunc
*/
loadCustomImage(name, callFunc) {
// cc.loader.load('../cocos-build/web-mobile/custom/' + name, callFunc);
},
//
/**
* game分辨率
*
* @param {cc.Vec2} editorSize {width:2048,height:1152}
* @param {number} ratio
* @param {Function} callFunc
*/
updateResolution(editorSize, ratio, callFunc) {
var gameDiv = document.getElementById('GameDiv');
cc.view.setDesignResolutionSize(
editorSize.width,
editorSize.height,
cc.ResolutionPolicy.FIXED_WIDTH
);
gameDiv.style.width = editorSize.width / ratio + 'px';
gameDiv.style.height = editorSize.height / ratio + 'px';
cc.view.setCanvasSize(editorSize.width / ratio, editorSize.height / ratio);
console.log(editorSize);
callFunc && callFunc();
},
/**
*
*
* @param {*} { node, attribute, value }
* @returns
*/
setNodeAttribute({ node, attribute, value }) {
if (!node) {
console.log('不存在节点');
return;
} else {
node[attribute] = value;
console.log('设置成功:' + attribute);
}
},
/**
* cocos内的事件系统
*
* @param {*} eventName
* @param {*} params
*/
emitGameEvt(eventName, params) {
// EVT.emit(eventName, params);
cc.find('Canvas/start').opacity = 0;
cc.tween(cc.find('Canvas/start')).to(0.5, { opacity: 255 }).start()
}
};