版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
1、代码文件位置:scratch-gui\src\lib\default-project\index.js
/* eslint-disable import/no-unresolved */
import popWav from '!arraybuffer-loader!./83a9787d4cb6f3b7632b4ddfebf74367.wav';
import meowWav from '!arraybuffer-loader!./83c36d806dc92327b9e7049a565c6bff.wav';// 小猫声音文件
import backdrop from '!raw-loader!./cd21514d0531fdffb22204e0ec5ed84a.svg';//舞台背景图片
import costume1 from '!raw-loader!./b7853f557e4426412e64bb3da6531a99.svg';//小猫造型1 图片
import costume2 from '!raw-loader!./e6ddc55a6ddd9cc9d84fe0b4c21e016f.svg';//小猫造型2 图片
/* eslint-enable import/no-unresolved */
const defaultProject = translator => {
let _TextEncoder;
if (typeof TextEncoder === 'undefined') {
_TextEncoder = require('text-encoding').TextEncoder;
} else {
/* global TextEncoder */
_TextEncoder = TextEncoder;
}
const encoder = new _TextEncoder();
const projectJson = projectData(translator);
return [{
id: 0,
assetType: 'Project',
dataFormat: 'JSON',
data: JSON.stringify(projectJson)
}, {
id: '83a9787d4cb6f3b7632b4ddfebf74367',
assetType: 'Sound',
dataFormat: 'WAV',
data: new Uint8Array(popWav)
}, {
id: '83c36d806dc92327b9e7049a565c6bff',
assetType: 'Sound',
dataFormat: 'WAV',
data: new Uint8Array(meowWav)
}, {
id: 'cd21514d0531fdffb22204e0ec5ed84a',
assetType: 'ImageVector',
dataFormat: 'SVG',
data: encoder.encode(backdrop)
}, {
id: 'b7853f557e4426412e64bb3da6531a99',
assetType: 'ImageVector',
dataFormat: 'SVG',
data: encoder.encode(costume1)
}, {
id: 'e6ddc55a6ddd9cc9d84fe0b4c21e016f',
assetType: 'ImageVector',
dataFormat: 'SVG',
data: encoder.encode(costume2)
}];
};
注意:图片是svg格式的,名称要转成md5的形式,作为id.
2、初始target数据文件:scratch-gui\src\lib\default-project\project-data.js
如图,targets属性里边存放着target的数据,第一个是舞台背景的数据,其余的是小猫的数据,要改变初始target,可以把小猫的数据改下
以下是些属性说明:
{
isStage: false,
name: translator(messages.sprite, {index: 1}),//targer名
variables: {},//target变量
lists: {},
broadcasts: {},
blocks: {},//存储的积木块
currentCostume: 0,//当前造型索引
costumes: [
{
assetId: 'b7853f557e4426412e64bb3da6531a99',
name: translator(messages.costume, {index: 1}),
bitmapResolution: 1,
md5ext: 'b7853f557e4426412e64bb3da6531a99.svg', //造型图片
dataFormat: 'svg',//图片格式
rotationCenterX: 48,
rotationCenterY: 50
},
{
assetId: 'e6ddc55a6ddd9cc9d84fe0b4c21e016f',
name: translator(messages.costume, {index: 2}),
bitmapResolution: 1,
md5ext: 'e6ddc55a6ddd9cc9d84fe0b4c21e016f.svg',
dataFormat: 'svg',
rotationCenterX: 46, //旋转中心的x坐标
rotationCenterY: 53 //旋转中心的y坐标
}
],
sounds: [
{
assetId: '83c36d806dc92327b9e7049a565c6bff',
name: translator(messages.meow),
dataFormat: 'wav',
format: '',
rate: 22050,
sampleCount: 18688,
md5ext: '83c36d806dc92327b9e7049a565c6bff.wav'
}
],
volume: 100,
visible: true, //target是否可见
x: 0,
y: 0,
size: 100,//target大小,百分比
direction: 90,
draggable: false,
rotationStyle: 'all around'
}