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 { LoaderResource } from "pixi.js"; |
|||
// import { LoaderResource } from "pixi.js";
|
|||
|
|||
|
|||
export function addSound(e: LoaderResource) { |
|||
console.log(e); |
|||
sound.add(e.name, { |
|||
source: e.data, |
|||
singleInstance: true, |
|||
autoPlay: false, |
|||
}); |
|||
} |
|||
sound.add('my-sound', { |
|||
url: "/bg.mp3", |
|||
singleInstance: true, |
|||
autoPlay: false, |
|||
}); |
|||
// export function addSound(e: LoaderResource) {
|
|||
// console.log(e);
|
|||
// sound.add(e.name, {
|
|||
// source: e.data,
|
|||
// singleInstance: true,
|
|||
// autoPlay: false,
|
|||
// });
|
|||
// }
|
|||
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 { |
|||
text: string; |
|||
autoUpdate: Boolean; |
|||
bg: Texture; |
|||
pressBg: Texture; |
|||
position: null | any; |
|||
click(): void; |
|||
} |
|||
|
|||
const defaultOpts: IOpts = { |
|||
autoUpdate: true, |
|||
text: "", |
|||
click() {}, |
|||
bg: null, |
|||
position: null, |
|||
pressBg: null, |
|||
click() { }, |
|||
}; |
|||
|
|||
export default function Button(opts: Partial<IOpts>) { |
|||
let curOpts: Partial<IOpts> = {}; |
|||
(Object.keys(defaultOpts) as (keyof IOpts)[]).forEach((key) => { |
|||
if (opts[key] != undefined) { |
|||
curOpts[key] = opts[key]; |
|||
function getConfig() { |
|||
return Object.assign({}, defaultOpts) |
|||
} |
|||
|
|||
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 { |
|||
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({ |
|||
fontFamily: "Arial", |
|||
fontSize: 50, |
|||
fill: 0xffffff, |
|||
align: "center", |
|||
}); |
|||
let textStr = new Text(curOpts.text, textStyle); |
|||
let xPadding = 60; |
|||
let yPadding = 40; |
|||
updateView() { |
|||
if(this._comp.destroyed) return |
|||
let width = this.textObj.width + this.padding.x; |
|||
let height = this.textObj.height + this.padding.y; |
|||
this._comp.pivot.set(width / 2, height / 2) |
|||
this.textObj.x = this.padding.x / 2; |
|||
this.textObj.y = this.padding.y / 2 - 2; |
|||
|
|||
let button = new Container(); |
|||
let width = textStr.width + xPadding; |
|||
let height = textStr.height + yPadding; |
|||
|
|||
textStr.x = xPadding / 2; |
|||
textStr.y = yPadding / 2; |
|||
if (this.bgRect) { |
|||
this.bgRect.rect(0, 0, width, height); |
|||
this.bgRect.fill(0xff0000); |
|||
} |
|||
if (this.bgNine) { |
|||
this.bgNine.width = width |
|||
this.bgNine.height = height |
|||
} |
|||
|
|||
const rect = new Graphics(); |
|||
rect.name = "rect"; |
|||
rect.beginFill(0xff0000); |
|||
rect.drawRect(0, 0, width, height); |
|||
rect.endFill(); |
|||
rect.interactive = true; |
|||
rect.buttonMode = true; |
|||
if (this.config.position) { |
|||
this._comp.position = this.config.position() |
|||
} |
|||
} |
|||
|
|||
button.addChild(rect); |
|||
button.addChild(textStr); |
|||
button.x = 100; |
|||
button.y = 50; |
|||
button.interactive = true; |
|||
button.on("touchstart", () => { |
|||
button.alpha = 0.8; |
|||
}); |
|||
button.on("touchend", () => { |
|||
// 点击成功
|
|||
console.log("success"); |
|||
curOpts.click(); |
|||
button.alpha = 1; |
|||
}); |
|||
button.on("touchendoutside", () => { |
|||
button.alpha = 1; |
|||
}); |
|||
return button; |
|||
createNine() { |
|||
this.bgNine = new NineSliceSprite({ |
|||
texture: this.config.bg, |
|||
leftWidth: 10, |
|||
topHeight: 10, |
|||
rightWidth: 10, |
|||
bottomHeight: 10, |
|||
}); |
|||
this.bgNine.cursor = 'pointer'; |
|||
this.bgNine.label = "nine-pic" |
|||
this.bgNine.interactive = true; |
|||
// plane9.buttonMode = true;
|
|||
} |
|||
|
|||
createRect() { |
|||
this.bgRect = new Graphics(); |
|||
this.bgRect.label = "rect"; |
|||
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 { gameManager, initGame, stageManager, windows } from "./Game"; |
|||
import { addSound } from "./Game/Sound"; |
|||
import { gameManager, initGame, stageManager } from "./Game"; |
|||
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 |
|||
.add("my-sound", "/bg.mp3", (e) => addSound(e)) |
|||
.add("bg", "/bg.png") |
|||
.load(); |
|||
gameManager.loader.onProgress.add((loader) => { |
|||
console.log(loader.progress); |
|||
}); |
|||
gameManager.loader.onComplete.once((loader) => { |
|||
console.log(loader.resources); |
|||
initGame(); |
|||
gameManager.setDirection(EDirection.Portrait); |
|||
stageManager.initStage("loading"); |
|||
// gameManager.loader.onProgress.add((loader) => {
|
|||
// console.log(loader.progress);
|
|||
// });
|
|||
// gameManager.loader.onComplete.once((loader) => {
|
|||
// console.log(loader.resources);
|
|||
// initGame();
|
|||
// gameManager.setDirection(EDirection.Landscape);
|
|||
// stageManager.initStage("init");
|
|||
// });
|
|||
|
|||
}); |
|||
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); |