MCPcopy Create free account
hub / github.com/melonjs/melonJS / createGame

Function createGame

packages/examples/src/examples/video/ExampleVideo.tsx:10–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8import videoSrc from "./assets/mov_bbb.mp4";
9
10const createGame = () => {
11 if (
12 !video.init(1218, 562, {
13 parent: "screen",
14 scaleMethod: "flex",
15 })
16 ) {
17 alert("Your browser does not support HTML5 canvas.");
18 return;
19 }
20
21 loader.setOptions({ crossOrigin: "anonymous" });
22
23 loader.preload(
24 [
25 {
26 name: "bigbunny",
27 type: "video",
28 src: videoSrc,
29 stream: false,
30 autoplay: false,
31 loop: true,
32 },
33 ],
34 () => {
35 state.change(state.DEFAULT, true);
36
37 const textMsg = new Text(game.viewport.width / 2, 100, {
38 font: "Arial",
39 size: 20,
40 fillStyle: "white",
41 textAlign: "center",
42 text: "click the screen to start the video",
43 });
44 game.world.addChild(textMsg);
45
46 const videoSprite = new Sprite(
47 game.viewport.width / 2,
48 game.viewport.height / 2,
49 {
50 image: loader.getVideo("bigbunny"),
51 anchorPoint: new Vector2d(0.5, 0.5),
52 },
53 );
54 videoSprite.scale(2);
55 videoSprite.onended = () => {
56 console.log("video ended !");
57 };
58 game.world.addChild(videoSprite);
59 videoSprite.play();
60 },
61 );
62};
63
64export const ExampleVideo = createExampleComponent(createGame);

Callers

nothing calls this directly

Calls 4

playMethod · 0.95
addChildMethod · 0.80
initMethod · 0.65
scaleMethod · 0.45

Tested by

no test coverage detected