mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-03 01:12:42 +08:00
1b2edaec93
* audio adapt * compile shaders as early as possible
96 lines
2.7 KiB
HTML
96 lines
2.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<title>audio</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
|
<style>
|
|
body {
|
|
background-color: #333;
|
|
margin: 0px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.fit {
|
|
position: absolute;
|
|
top: 0;
|
|
bottom: 0;
|
|
left: 0;
|
|
right: 0;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body class="fit">
|
|
<canvas id="canvas" tabindex="-1" class="fit"></canvas>
|
|
<script src="../bin/cocos-3d.dev.js"></script>
|
|
<script src="./camera.js"></script>
|
|
<script>
|
|
const $body = document.body;
|
|
const bcr = $body.getBoundingClientRect();
|
|
const canv = document.getElementById('canvas');
|
|
canv.width = bcr.width;
|
|
canv.height = bcr.height;
|
|
|
|
window.addEventListener('resize', () => {
|
|
const bcr = $body.getBoundingClientRect();
|
|
cc.director.root.resize(bcr.width, bcr.height);
|
|
});
|
|
|
|
const imgs = canv.getElementsByTagName('img');
|
|
function createTexture(idx) {
|
|
const textureAsset = new cc.Texture2D();
|
|
textureAsset.image = new cc.ImageAsset(imgs[idx]);
|
|
return textureAsset;
|
|
}
|
|
|
|
const geomList = ['box', 'sphere', 'cylinder', 'cone', 'torus', 'capsule'];
|
|
function onStart() {
|
|
const root = cc.director.root;
|
|
const scene = new cc.Scene();
|
|
|
|
const cameraNode = new cc.Node('Camera');
|
|
cameraNode.parent = scene;
|
|
cameraNode.setPosition(20, 0, 115);
|
|
cameraNode.setRotationFromEuler(0, 30, 0);
|
|
cameraNode.addComponent(cc.CameraComponent);
|
|
cameraNode.addComponent(FirstPersonCamera);
|
|
|
|
const n1 = new cc.Node('Audio Source 1');
|
|
n1.parent = scene;
|
|
const s1 = n1.addComponent(cc.AudioSourceComponent);
|
|
const n2 = new cc.Node('Audio Source 2');
|
|
n2.parent = scene;
|
|
const s2 = n2.addComponent(cc.AudioSourceComponent);
|
|
s2.loop = true;
|
|
s2.volume = 0.5;
|
|
s2.playOnAwake = false;
|
|
|
|
cc.AssetLibrary.init({
|
|
libraryPath: 'resources',
|
|
rawAssetsBase: 'resources',
|
|
rawAssets: {
|
|
assets: {
|
|
"bf43d245-3a77-4b55-bc7f-9a3bb09544d0": ["morceaux", "cc.AudioClip"],
|
|
"da0936bf-2873-4bc0-ab91-7aa11a6b7d23": ["nocturne", "cc.AudioClip"]
|
|
}
|
|
}
|
|
});
|
|
|
|
let jobsRemaining = 2;
|
|
cc.loader.loadRes('morceaux', cc.AudioClip, (err, asset) => {
|
|
s1.clip = asset;
|
|
if (!--jobsRemaining) cc.director.runSceneImmediate(scene);
|
|
});
|
|
cc.loader.loadRes('nocturne', cc.AudioClip, (err, asset) => {
|
|
s2.clip = asset;
|
|
if (!--jobsRemaining) cc.director.runSceneImmediate(scene);
|
|
});
|
|
}
|
|
cc.game.run({ id: 'canvas' }, onStart);
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|