Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
|
1f0a7280f3 | 9 months ago |
|
a2977d615d | 9 months ago |
|
ca7a2ef217 | 9 months ago |
|
3ea07e4173 | 9 months ago |
After Width: | Height: | Size: 422 B |
After Width: | Height: | Size: 378 B |
After Width: | Height: | Size: 391 B |
After Width: | Height: | Size: 302 B |
After Width: | Height: | Size: 414 B |
After Width: | Height: | Size: 332 B |
After Width: | Height: | Size: 402 B |
After Width: | Height: | Size: 399 B |
After Width: | Height: | Size: 566 B |
After Width: | Height: | Size: 459 B |
After Width: | Height: | Size: 511 B |
After Width: | Height: | Size: 404 B |
After Width: | Height: | Size: 530 B |
After Width: | Height: | Size: 424 B |
After Width: | Height: | Size: 562 B |
After Width: | Height: | Size: 483 B |
After Width: | Height: | Size: 338 B |
After Width: | Height: | Size: 412 B |
After Width: | Height: | Size: 383 B |
After Width: | Height: | Size: 373 B |
After Width: | Height: | Size: 642 B |
After Width: | Height: | Size: 411 B |
After Width: | Height: | Size: 315 B |
After Width: | Height: | Size: 306 B |
After Width: | Height: | Size: 590 B |
After Width: | Height: | Size: 338 B |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1023 B |
After Width: | Height: | Size: 958 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 306 B |
After Width: | Height: | Size: 375 B |
After Width: | Height: | Size: 355 B |
After Width: | Height: | Size: 337 B |
After Width: | Height: | Size: 615 B |
After Width: | Height: | Size: 374 B |
After Width: | Height: | Size: 286 B |
After Width: | Height: | Size: 268 B |
After Width: | Height: | Size: 532 B |
After Width: | Height: | Size: 304 B |
After Width: | Height: | Size: 579 B |
After Width: | Height: | Size: 579 B |
After Width: | Height: | Size: 774 B |
After Width: | Height: | Size: 743 B |
After Width: | Height: | Size: 280 B |
After Width: | Height: | Size: 498 B |
After Width: | Height: | Size: 501 B |
After Width: | Height: | Size: 318 B |
After Width: | Height: | Size: 280 B |
After Width: | Height: | Size: 559 B |
After Width: | Height: | Size: 539 B |
After Width: | Height: | Size: 321 B |
After Width: | Height: | Size: 377 B |
After Width: | Height: | Size: 313 B |
After Width: | Height: | Size: 350 B |
After Width: | Height: | Size: 377 B |
After Width: | Height: | Size: 312 B |
After Width: | Height: | Size: 351 B |
After Width: | Height: | Size: 128 B |
After Width: | Height: | Size: 130 B |
After Width: | Height: | Size: 297 B |
After Width: | Height: | Size: 382 B |
After Width: | Height: | Size: 321 B |
After Width: | Height: | Size: 336 B |
After Width: | Height: | Size: 383 B |
After Width: | Height: | Size: 321 B |
After Width: | Height: | Size: 336 B |
After Width: | Height: | Size: 379 B |
After Width: | Height: | Size: 308 B |
After Width: | Height: | Size: 316 B |
After Width: | Height: | Size: 379 B |
After Width: | Height: | Size: 308 B |
After Width: | Height: | Size: 316 B |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 955 B |
After Width: | Height: | Size: 1.1 KiB |
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,26 @@ |
|||||
|
import { gameManager } from "@/Game"; |
||||
|
import { PointData } from "pixi.js"; |
||||
|
|
||||
|
class Position { |
||||
|
static instance: Position = null |
||||
|
private constructor() { } |
||||
|
static getInstance() { |
||||
|
if (Position.instance == null) { |
||||
|
Position.instance = new Position |
||||
|
} |
||||
|
return Position.instance |
||||
|
} |
||||
|
|
||||
|
get(xType: "center", yType: "center", offset?: Partial<PointData>): PointData { |
||||
|
let x, y |
||||
|
if (xType === 'center') { |
||||
|
x = gameManager.getInfo().width / 2 + (offset?.x ?? 0) |
||||
|
} |
||||
|
if (yType === 'center') { |
||||
|
y = gameManager.getInfo().height / 2 + (offset?.y ?? 0) |
||||
|
} |
||||
|
return { x, y } |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export default Position.getInstance() |
@ -1,13 +1,17 @@ |
|||||
import { sound } from "@pixi/sound"; |
import { sound } from "@pixi/sound"; |
||||
import { LoaderResource } from "pixi.js"; |
// import { LoaderResource } from "pixi.js";
|
||||
|
|
||||
|
sound.add('my-sound', { |
||||
export function addSound(e: LoaderResource) { |
url: "/bg.mp3", |
||||
console.log(e); |
singleInstance: true, |
||||
sound.add(e.name, { |
autoPlay: false, |
||||
source: e.data, |
}); |
||||
singleInstance: true, |
// export function addSound(e: LoaderResource) {
|
||||
autoPlay: false, |
// console.log(e);
|
||||
}); |
// sound.add(e.name, {
|
||||
} |
// source: e.data,
|
||||
|
// singleInstance: true,
|
||||
|
// autoPlay: false,
|
||||
|
// });
|
||||
|
// }
|
||||
export default sound; |
export default sound; |
||||
|
@ -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,66 +1,159 @@ |
|||||
import { Text, Graphics, Container, TextStyle } from "pixi.js"; |
import { Text, Graphics, Container, TextStyle, NineSlicePlane, Texture, NineSliceSprite, Ticker } from "pixi.js"; |
||||
|
|
||||
interface IOpts { |
interface IOpts { |
||||
text: string; |
text: string; |
||||
|
autoUpdate: Boolean; |
||||
|
bg: Texture; |
||||
|
pressBg: Texture; |
||||
|
position: null | any; |
||||
click(): void; |
click(): void; |
||||
} |
} |
||||
|
|
||||
const defaultOpts: IOpts = { |
const defaultOpts: IOpts = { |
||||
|
autoUpdate: true, |
||||
text: "", |
text: "", |
||||
click() {}, |
bg: null, |
||||
|
position: null, |
||||
|
pressBg: null, |
||||
|
click() { }, |
||||
}; |
}; |
||||
|
|
||||
export default function Button(opts: Partial<IOpts>) { |
function getConfig() { |
||||
let curOpts: Partial<IOpts> = {}; |
return Object.assign({}, defaultOpts) |
||||
(Object.keys(defaultOpts) as (keyof IOpts)[]).forEach((key) => { |
} |
||||
if (opts[key] != undefined) { |
|
||||
curOpts[key] = opts[key]; |
export class Button { |
||||
|
config: IOpts |
||||
|
_comp: Container |
||||
|
textObj: Text |
||||
|
bgRect: Graphics |
||||
|
bgNine: NineSliceSprite |
||||
|
padding = { x: 60, y: 40 } |
||||
|
getComp(){ |
||||
|
return this._comp |
||||
|
} |
||||
|
constructor(opts: Partial<IOpts>) { |
||||
|
this.config = getConfig(); |
||||
|
; (Object.keys(defaultOpts) as (keyof IOpts)[]).forEach((key) => { |
||||
|
if (opts[key] != undefined) { |
||||
|
this.config[key] = opts[key] as any; |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
this._comp = new Container(); |
||||
|
this._comp.cursor = 'pointer'; |
||||
|
this._comp.interactive = true; |
||||
|
|
||||
|
if (!this.config.bg) { |
||||
|
this.createRect() |
||||
|
this._comp.addChild(this.bgRect) |
||||
} else { |
} else { |
||||
curOpts[key] = defaultOpts[key]; |
this.createNine() |
||||
|
this._comp.addChild(this.bgNine) |
||||
|
} |
||||
|
this.createText() |
||||
|
this._comp.addChild(this.textObj) |
||||
|
if (this.config.autoUpdate) { |
||||
|
const update = () => { |
||||
|
this.updateView() |
||||
|
} |
||||
|
Ticker.shared.add(update) |
||||
|
this._comp.on("destroyed", ()=>{ |
||||
|
console.log("销毁了"); |
||||
|
Ticker.shared.remove(update, this) |
||||
|
}) |
||||
|
} |
||||
|
const downFN = () => { |
||||
|
if (this.config.pressBg && this.bgNine) { |
||||
|
this.bgNine.texture = this.config.pressBg |
||||
|
} else { |
||||
|
this._comp.alpha = 0.8; |
||||
|
this._comp.scale = { x: .8, y: .8 } |
||||
|
} |
||||
|
} |
||||
|
this._comp.on("mousedown", downFN); |
||||
|
this._comp.on("touchstart", downFN); |
||||
|
const upFN = () => { |
||||
|
if (this.config.pressBg && this.bgNine) { |
||||
|
this.bgNine.texture = this.config.bg |
||||
|
} else { |
||||
|
this._comp.alpha = 1; |
||||
|
this._comp.scale = { x: 1, y: 1 } |
||||
|
} |
||||
|
this.config.click(); |
||||
} |
} |
||||
}); |
this._comp.on('mouseup', upFN); |
||||
|
this._comp.on('touchend', upFN); |
||||
|
const upOutsideFN = () => { |
||||
|
if (this.config.pressBg) { |
||||
|
this.bgNine.texture = this.config.bg |
||||
|
} else { |
||||
|
this._comp.alpha = 1; |
||||
|
this._comp.scale = { x: 1, y: 1 } |
||||
|
} |
||||
|
} |
||||
|
this._comp.on("mouseupoutside", upOutsideFN); |
||||
|
this._comp.on("touchendoutside", upOutsideFN); |
||||
|
} |
||||
|
|
||||
let textStyle = new TextStyle({ |
updateView() { |
||||
fontFamily: "Arial", |
if(this._comp.destroyed) return |
||||
fontSize: 50, |
let width = this.textObj.width + this.padding.x; |
||||
fill: 0xffffff, |
let height = this.textObj.height + this.padding.y; |
||||
align: "center", |
this._comp.pivot.set(width / 2, height / 2) |
||||
}); |
this.textObj.x = this.padding.x / 2; |
||||
let textStr = new Text(curOpts.text, textStyle); |
this.textObj.y = this.padding.y / 2 - 2; |
||||
let xPadding = 60; |
|
||||
let yPadding = 40; |
|
||||
|
|
||||
let button = new Container(); |
if (this.bgRect) { |
||||
let width = textStr.width + xPadding; |
this.bgRect.rect(0, 0, width, height); |
||||
let height = textStr.height + yPadding; |
this.bgRect.fill(0xff0000); |
||||
|
} |
||||
textStr.x = xPadding / 2; |
if (this.bgNine) { |
||||
textStr.y = yPadding / 2; |
this.bgNine.width = width |
||||
|
this.bgNine.height = height |
||||
|
} |
||||
|
|
||||
const rect = new Graphics(); |
if (this.config.position) { |
||||
rect.name = "rect"; |
this._comp.position = this.config.position() |
||||
rect.beginFill(0xff0000); |
} |
||||
rect.drawRect(0, 0, width, height); |
} |
||||
rect.endFill(); |
|
||||
rect.interactive = true; |
|
||||
rect.buttonMode = true; |
|
||||
|
|
||||
button.addChild(rect); |
createNine() { |
||||
button.addChild(textStr); |
this.bgNine = new NineSliceSprite({ |
||||
button.x = 100; |
texture: this.config.bg, |
||||
button.y = 50; |
leftWidth: 10, |
||||
button.interactive = true; |
topHeight: 10, |
||||
button.on("touchstart", () => { |
rightWidth: 10, |
||||
button.alpha = 0.8; |
bottomHeight: 10, |
||||
}); |
}); |
||||
button.on("touchend", () => { |
this.bgNine.cursor = 'pointer'; |
||||
// 点击成功
|
this.bgNine.label = "nine-pic" |
||||
console.log("success"); |
this.bgNine.interactive = true; |
||||
curOpts.click(); |
// plane9.buttonMode = true;
|
||||
button.alpha = 1; |
} |
||||
}); |
|
||||
button.on("touchendoutside", () => { |
createRect() { |
||||
button.alpha = 1; |
this.bgRect = new Graphics(); |
||||
}); |
this.bgRect.label = "rect"; |
||||
return button; |
this.bgRect.interactive = true; |
||||
|
this.bgRect.cursor = 'pointer'; |
||||
|
// rect.buttonMode = true;
|
||||
|
} |
||||
|
|
||||
|
createText() { |
||||
|
let textStyle = new TextStyle({ |
||||
|
fontFamily: "Arial", |
||||
|
fontSize: 30, |
||||
|
fill: 0xffffff, |
||||
|
align: "center", |
||||
|
}); |
||||
|
this.textObj = new Text({ |
||||
|
text: this.config.text, |
||||
|
style: textStyle |
||||
|
}); |
||||
|
this.textObj.cursor = 'pointer'; |
||||
|
this.textObj.label = "text" |
||||
|
} |
||||
} |
} |
||||
|
|
||||
|
export default Button |
@ -1,20 +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"; |
||||
|
|
||||
console.log(); |
// gameManager.loader
|
||||
|
// // .add("my-sound", "/bg.mp3", (e) => addSound(e)) // 背景音乐
|
||||
|
// .add("bg", "/bg.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-press", "/assets/images/button_square_depth_gradient.png") // 背景图片
|
||||
|
// .load();
|
||||
|
|
||||
gameManager.loader |
// gameManager.loader.onProgress.add((loader) => {
|
||||
.add("my-sound", "/bg.mp3", (e) => addSound(e)) |
// console.log(loader.progress);
|
||||
.add("bg", "/bg.png") |
// });
|
||||
.load(); |
// gameManager.loader.onComplete.once((loader) => {
|
||||
gameManager.loader.onProgress.add((loader) => { |
// console.log(loader.resources);
|
||||
console.log(loader.progress); |
// initGame();
|
||||
}); |
// gameManager.setDirection(EDirection.Landscape);
|
||||
gameManager.loader.onComplete.once((loader) => { |
// stageManager.initStage("init");
|
||||
console.log(loader.resources); |
// });
|
||||
initGame(); |
|
||||
gameManager.setDirection(EDirection.Portrait); |
|
||||
stageManager.initStage("loading"); |
|
||||
|
|
||||
}); |
setTimeout(() => { |
||||
|
;(async ()=>{ |
||||
|
await initAssets(); |
||||
|
await Game.getInstance().init() |
||||
|
initGame(); |
||||
|
gameManager.setDirection(EDirection.Landscape); |
||||
|
})() |
||||
|
}, 200); |
@ -0,0 +1,44 @@ |
|||||
|
import { Button } from "@/components/Button"; |
||||
|
import { EP } from "@/enmu"; |
||||
|
import { defineWindow } from "@/Game"; |
||||
|
import { loadAsset } from "@/Game/Assets"; |
||||
|
import Position from "@/Game/Position"; |
||||
|
import { PWindow } from "@/Game/type"; |
||||
|
import { Assets, Container } from "pixi.js"; |
||||
|
|
||||
|
export default defineWindow( |
||||
|
class extends PWindow { |
||||
|
btn: Button; |
||||
|
async loadBundle() { |
||||
|
console.log(this.stage); |
||||
|
console.log("加载资源"); |
||||
|
Assets.add({ alias: 'btn-bgaa', src: '/assets/images/button_square_depth_gloss.png' }) |
||||
|
Assets.add({ alias: 'btn-bg-pressaa', src: '/assets/images/button_square_depth_gradient.png' }) |
||||
|
const aa = await Assets.load('btn-bgaa') |
||||
|
console.log(aa); |
||||
|
|
||||
|
} |
||||
|
async layout() { |
||||
|
this.stage.zIndex = 9999 |
||||
|
this.btn = new Button({ |
||||
|
text: "全局", |
||||
|
bg: await Assets.load('btn-bgaa'), |
||||
|
pressBg: await Assets.load("btn-bg-pressaa"), |
||||
|
position: () => Position.get("center", "center", { y: 100, x: 0 }) |
||||
|
}) |
||||
|
this.stage.addChild(this.btn._comp) |
||||
|
} |
||||
|
onLoad() { |
||||
|
console.log("global page loaded"); |
||||
|
} |
||||
|
hide() { |
||||
|
// this.btn._comp.visible = false
|
||||
|
} |
||||
|
show() { |
||||
|
// this.btn._comp.visible = true
|
||||
|
} |
||||
|
onUnLoad() { |
||||
|
} |
||||
|
}, |
||||
|
EP.Resident |
||||
|
); |
@ -1,26 +0,0 @@ |
|||||
import { EP } from "@/enmu"; |
|
||||
import { defineWindow } from "@/Game"; |
|
||||
import { Container, Loader } from "pixi.js"; |
|
||||
import { addSound } from "@/Game/Sound"; |
|
||||
|
|
||||
const loader = new Loader().add("my-sound", "/bg.mp3", (e) => addSound(e)); |
|
||||
|
|
||||
export default defineWindow("control", class { |
|
||||
stage: Container = null; |
|
||||
loader: Loader = loader; |
|
||||
|
|
||||
constructor(stage: Container) { |
|
||||
this.stage = stage; |
|
||||
} |
|
||||
|
|
||||
onLoad() { |
|
||||
console.log("onLoad control"); |
|
||||
} |
|
||||
|
|
||||
onUnLoad() { |
|
||||
console.log("onUnLoad control"); |
|
||||
} |
|
||||
|
|
||||
update() { |
|
||||
} |
|
||||
}, EP.Resident); |
|