위챗 애플릿 모듈화 - 가져오기 및 내보내기
1177 단어 wxxm
backgroud.js
export default function(ctx) {
var bg = new Image();
bg.src = "./images/bg.jpg";
bg.width = 512;
bg.height = 512;
var width = window.innerWidth; //
var height = window.innerHeight;
var top = 0;
move();
function move() {
top++;
requestAnimationFrame(function() {
ctx.clearRect(0, 0, width, height);
ctx.drawImage(bg, 0, 0, bg.width, bg.height, 0, top, width, height);
ctx.drawImage(
bg,
0,
0,
bg.width,
bg.height,
0,
-height + top,
width,
height
);
if (top == height) {
top = 0;
}
move();
});
}
}
audio를 내보냅니다.js
export default function() {
var bgm = new Audio();
bgm.volume = 0.02;
bgm.src = "./audio/bgm.mp3";
bgm.play();
}
백그라운드 가져오기.js와 audio.js
import "./js/component/weapp-adapter.js"
import Audio from "./js/component/audio"
import Background from "./js/component/background.js"
var ctx = canvas.getContext("2d");
Background(ctx)
Audio()