18 changed files with 610 additions and 300 deletions
Binary file not shown.
After Width: | Height: | Size: 317 KiB |
@ -0,0 +1,29 @@ |
|||||
|
{ |
||||
|
"bundles":[ |
||||
|
{ |
||||
|
"name":"load-screen", |
||||
|
"assets":[ |
||||
|
{ |
||||
|
"alias":"cbg", |
||||
|
"src":"/controller_prompt_bg.png" |
||||
|
}, |
||||
|
{ |
||||
|
"alias":"bg", |
||||
|
"src":"/bg.png" |
||||
|
}, |
||||
|
{ |
||||
|
"alias":"dnf", |
||||
|
"src":"https://www.kkkk1000.com/images/learnPixiJS-AnimatedSprite/dnf.png" |
||||
|
}, |
||||
|
{ |
||||
|
"alias":"btn-bg", |
||||
|
"src":"/assets/images/button_square_depth_gloss.png" |
||||
|
}, |
||||
|
{ |
||||
|
"alias":"btn-bg-press", |
||||
|
"src":"/assets/images/button_square_depth_gradient.png" |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
] |
||||
|
} |
@ -0,0 +1,45 @@ |
|||||
|
import { Assets } from "pixi.js"; |
||||
|
|
||||
|
|
||||
|
export async function initAssets() { |
||||
|
await Assets.init({ manifest: "/manifest.json" }) |
||||
|
} |
||||
|
|
||||
|
const catchMap = new Map() |
||||
|
|
||||
|
export async function loadAsset(name: string, cb?: (progress: number) => void) { |
||||
|
const check = () => { |
||||
|
if (catchMap.has(name)) { |
||||
|
const rr = catchMap.get(name) |
||||
|
rr.count++ |
||||
|
console.log(2211); |
||||
|
catchMap.set(name, rr) |
||||
|
cb?.(1) |
||||
|
return rr.data |
||||
|
} |
||||
|
} |
||||
|
check() |
||||
|
const res = await Assets.loadBundle(name, (progress: number) => { |
||||
|
cb?.(progress) |
||||
|
}) |
||||
|
let r = check() |
||||
|
if (r) return r |
||||
|
catchMap.set(name, { |
||||
|
data: res, |
||||
|
count: 1 |
||||
|
}) |
||||
|
return res |
||||
|
} |
||||
|
/** |
||||
|
* 没有场景加载时方会卸载 |
||||
|
*/ |
||||
|
export async function unLoadAsset(name: string) { |
||||
|
if (catchMap.has(name)) { |
||||
|
const rr = catchMap.get(name) |
||||
|
rr.count-- |
||||
|
if (rr.count == 0) { |
||||
|
await Assets.unloadBundle(name) |
||||
|
catchMap.delete(name) |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
import { EP } from "@/enmu"; |
||||
|
import { IWindow } from "."; |
||||
|
import { Container, Ticker } from "pixi.js"; |
||||
|
|
||||
|
export abstract class PWindow implements IWindow { |
||||
|
components: Record<string, any>; |
||||
|
_type?: EP; |
||||
|
_initLayout?: Boolean; |
||||
|
_initAssets?: Boolean; |
||||
|
_layoutChild?: void | any[]; |
||||
|
stage: Container; |
||||
|
loader?: Loader; |
||||
|
changeStage?(name: string, opts?: {isHolderLast?: boolean}): void; |
||||
|
loadBundle?(): void; |
||||
|
unLoadBundle?(): void; |
||||
|
layout?(): void; |
||||
|
onLoad?(): void; |
||||
|
onUnLoad?(): void; |
||||
|
lateUpdate?(dt: number, name: string, ticker: Ticker): void; |
||||
|
update?(dt: number, name: string, ticker: Ticker): void; |
||||
|
} |
@ -1,21 +1,32 @@ |
|||||
|
import { Assets } from "pixi.js"; |
||||
import { EDirection } from "./enmu"; |
import { EDirection } from "./enmu"; |
||||
import { gameManager, initGame, stageManager, windows } from "./Game"; |
import { gameManager, initGame, stageManager } from "./Game"; |
||||
import { addSound } from "./Game/Sound"; |
import Game from "./Game/Game"; |
||||
|
import { initAssets } from "./Game/Assets"; |
||||
|
|
||||
gameManager.loader |
// gameManager.loader
|
||||
// .add("my-sound", "/bg.mp3", (e) => addSound(e)) // 背景音乐
|
// // .add("my-sound", "/bg.mp3", (e) => addSound(e)) // 背景音乐
|
||||
.add("bg", "/bg.png") // 背景图片
|
// .add("bg", "/bg.png") // 背景图片
|
||||
.add("dnf", "https://www.kkkk1000.com/images/learnPixiJS-AnimatedSprite/dnf.png") // 背景图片
|
// .add("dnf", "https://www.kkkk1000.com/images/learnPixiJS-AnimatedSprite/dnf.png") // 背景图片
|
||||
.add("btn-bg", "/assets/images/button_square_depth_gloss.png") // 背景图片
|
// .add("btn-bg", "/assets/images/button_square_depth_gloss.png") // 背景图片
|
||||
.add("btn-bg-press", "/assets/images/button_square_depth_gradient.png") // 背景图片
|
// .add("btn-bg-press", "/assets/images/button_square_depth_gradient.png") // 背景图片
|
||||
.load(); |
// .load();
|
||||
|
|
||||
gameManager.loader.onProgress.add((loader) => { |
// gameManager.loader.onProgress.add((loader) => {
|
||||
console.log(loader.progress); |
// console.log(loader.progress);
|
||||
}); |
// });
|
||||
gameManager.loader.onComplete.once((loader) => { |
// gameManager.loader.onComplete.once((loader) => {
|
||||
console.log(loader.resources); |
// console.log(loader.resources);
|
||||
|
// initGame();
|
||||
|
// gameManager.setDirection(EDirection.Landscape);
|
||||
|
// stageManager.initStage("init");
|
||||
|
// });
|
||||
|
|
||||
|
setTimeout(() => { |
||||
|
;(async ()=>{ |
||||
|
await initAssets(); |
||||
|
await Game.getInstance().init() |
||||
initGame(); |
initGame(); |
||||
gameManager.setDirection(EDirection.Landscape); |
gameManager.setDirection(EDirection.Landscape); |
||||
stageManager.initStage("init"); |
})() |
||||
}); |
}, 200); |
@ -1,44 +1,45 @@ |
|||||
import Button from "@/components/Button"; |
import Button from "@/components/Button"; |
||||
import { gameManager,defineWindow, stageManager } from "@/Game"; |
import { gameManager, defineWindow, stageManager } from "@/Game"; |
||||
import Sound from "@/Game/Sound"; |
import Sound from "@/Game/Sound"; |
||||
import { Container, Graphics, Text } from "pixi.js"; |
import { Container, Graphics, Text } from "pixi.js"; |
||||
|
|
||||
import Circle from "./circle" |
import Circle from "./circle" |
||||
|
import { PWindow } from "@/Game/type"; |
||||
|
import Position from "@/Game/Position"; |
||||
|
|
||||
|
|
||||
export default defineWindow("welcome", class{ |
export default defineWindow("welcome", class extends PWindow { |
||||
stage:Container = null |
stage: Container = null |
||||
elements: Record<string, Graphics> = {} |
|
||||
text: any |
text: any |
||||
bindStage(stage: Container){ |
layout() { |
||||
this.stage = stage; |
|
||||
} |
|
||||
layout(){ |
|
||||
const circle = Circle.render() |
const circle = Circle.render() |
||||
this.stage.addChild(circle) |
this.stage.addChild(circle) |
||||
circle.on("touchend", ()=>{ |
circle.on("touchend", () => { |
||||
stageManager.changeStage("welcome2") |
this.changeStage("welcome2") |
||||
|
}) |
||||
|
circle.on("mousedown", () => { |
||||
|
this.changeStage("welcome2") |
||||
}) |
}) |
||||
this.text = new Text("修仙人生日常") |
// this.text = new Text({text: "修仙人生日常"})
|
||||
|
|
||||
this.stage.addChild(this.text) |
// this.stage.addChild(this.text)
|
||||
const btn = Button({text: "修仙人生日常"}) |
const btn = new Button({ |
||||
btn.on("touchend", ()=>{ |
text: "修仙人生日常", position: () => Position.get("center", "center"), click: () => { |
||||
// Sound.play('my-sound');
|
this.changeStage("init") |
||||
stageManager.changeStage("init") |
} |
||||
}) |
}) |
||||
this.stage.addChild(btn) |
this.stage.addChild(btn._comp) |
||||
} |
} |
||||
onLoad(){ |
onLoad() { |
||||
console.log("onLoad 1"); |
console.log("onLoad 1"); |
||||
} |
} |
||||
onUnLoad(){ |
onUnLoad() { |
||||
Sound.stop("my-sound") |
Sound.stop("my-sound") |
||||
console.log("onUnLoad 1"); |
console.log("onUnLoad 1"); |
||||
} |
} |
||||
update(){ |
update() { |
||||
this.text.x = gameManager.getInfo().width-this.text.width |
// this.text.x = gameManager.getInfo().width-this.text.width
|
||||
this.text.y = gameManager.getInfo().height-this.text.height |
// this.text.y = gameManager.getInfo().height-this.text.height
|
||||
// console.log(22);
|
// console.log(22);
|
||||
} |
} |
||||
}) |
}) |
Loading…
Reference in new issue