Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.4.0] - TBD

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we are going to bump this and all the other ones to 2.0.0 since we have some potentially breaking changes here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a PR to update the package version and changelog in the 2.0.0 release branch: #111

I noticed there was a slight difference between the changelog on main and the one in the templates. This change will keep it all consistent, and it just needs to be pulled into the template branches.


### Changed

- Updated pixi.js to 8.1.0
- Updated @pixi/sound to 6.0.0

## [1.3.1] - 2023-03-28

### Fixed
Expand Down
870 changes: 259 additions & 611 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"springroll": "^2.4.4"
},
"dependencies": {
"@pixi/sound": "^5.0.0",
"pixi.js": "^7.0.4",
"@pixi/sound": "^6.0.0",
"pixi.js": "^8.1.0",
"springroll": "^2.4.4"
}
}
151 changes: 82 additions & 69 deletions src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,77 +9,90 @@ export class Game
{
constructor(width, height)
{
this.emitter = new PIXI.EventEmitter();
this.width = width;
this.height = height;
this.app = new Application(
{
// This feature list matches the Springroll states subscribed to below
// Note: features will only work if the Container environment also supports controls for that feature.
features:

this.pixi = new PIXI.Application();
(async () => {
await this.pixi.init({
width,
height,
autoResize: true
});

document.getElementById('content').appendChild(this.pixi.canvas);

this.app = new Application(
{
// This feature list matches the Springroll states subscribed to below
// Note: features will only work if the Container environment also supports controls for that feature.
features:
{
sfx: true,
sound: true,
music: true,
vo: true,
sfxVolume: true,
soundVolume: true,
musicVolume: true,
voVolume: true,
captionsMuted: true,
}
});

this.resize = this.resize.bind(this);
this.scaleManager = new SafeScaleManager({width, height, safeWidth: 1024, safeHeight: 660, callback: this.resize});

// Subscribe to required springroll States.
this.app.state.pause.subscribe((value) =>
{
sfx: true,
sound: true,
music: true,
vo: true,
sfxVolume: true,
soundVolume: true,
musicVolume: true,
voVolume: true,
captionsMuted: true,
}
});

this.pixi = new PIXI.Application({ width, height, autoResize: true });
document.getElementById('content').appendChild(this.pixi.view);

this.resize = this.resize.bind(this);
this.scaleManager = new SafeScaleManager({width, height, safeWidth: 1024, safeHeight: 660, callback: this.resize});

// Subscribe to required springroll States.
this.app.state.pause.subscribe((value) =>
{
this.isPaused = value;
});

this.app.state.soundVolume.subscribe((value) =>
{
sound.volumeAll = value;
});

this.app.state.sfxVolume.subscribe((value) =>
{
// this will break if done before sounds are loaded.
// in a full game this should be handled gracefully.
PIXI.Assets.get('bounce').sound.volume = value;
});

this.app.state.musicVolume.subscribe(result =>
{
console.log('musicVolume: ', result);
});

this.app.state.voVolume.subscribe(result =>
{
console.log('voVolume: ', result);
});

this.app.state.captionsMuted.subscribe(result =>
{
console.log('captionsMuted: ', result);
});

// add a extra state property for storying the current scene. Whenever the scene is changed, this class
// will swap out the container attached to the stage
this.app.state.scene = new Property(null);
this.app.state.scene.subscribe(this.onChangeScene.bind(this));

// wait for the app to be ready, then set the new scene
this.app.state.ready.subscribe(() =>
{
this.app.state.scene.value = new TitleScene(this);

});
this.isPaused = value;
});

this.app.state.soundVolume.subscribe((value) =>
{
sound.volumeAll = value;
});

this.app.state.sfxVolume.subscribe((value) =>
{
//Check to see if sound exists in the cache before changing its volume
if(PIXI.Assets.cache.has('bounce')){
PIXI.Assets.get('bounce').sound.volume = value;
}

});

this.app.state.musicVolume.subscribe(result =>
{
console.log('musicVolume: ', result);
});

this.app.state.voVolume.subscribe(result =>
{
console.log('voVolume: ', result);
});

this.app.state.captionsMuted.subscribe(result =>
{
console.log('captionsMuted: ', result);
});

// add a extra state property for storying the current scene. Whenever the scene is changed, this class
// will swap out the container attached to the stage
this.app.state.scene = new Property(null);
this.app.state.scene.subscribe(this.onChangeScene.bind(this));

// wait for the app to be ready, then set the new scene
this.app.state.ready.subscribe(() =>
{
this.app.state.scene.value = new TitleScene(this);
});

// Dispatch a ready event after initializing the app
this.emitter.emit('ready');
})();
}

run()
Expand Down Expand Up @@ -123,7 +136,7 @@ export class Game
// -- PIXI -- //
const renderer = this.pixi.renderer;

renderer.view.style.width = `${GAMEPLAY.WIDTH * scaleRatio}px`;
renderer.view.style.height = `${GAMEPLAY.HEIGHT * scaleRatio}px`;
renderer.view.canvas.style.width = `${GAMEPLAY.WIDTH * scaleRatio}px`;
renderer.view.canvas.style.height = `${GAMEPLAY.HEIGHT * scaleRatio}px`;
}
}
9 changes: 5 additions & 4 deletions src/gameobjects/ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ export class Ball extends PIXI.Sprite
this.hitSound = PIXI.Assets.get('bounce');
}

update(deltaTime)
update(ticker)
{
this.velocity.y += GAMEPLAY.GRAVITY * deltaTime;
this.position.y += this.velocity.y * deltaTime;


this.velocity.y += GAMEPLAY.GRAVITY * ticker.deltaTime;
this.position.y += this.velocity.y * ticker.deltaTime;

if(this.position.y > 680)
{
this.position.y = 679;
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ import './styles.css';
import { Game } from './game';
import { GAMEPLAY } from './constants';

// eslint-disable-next-line no-unused-vars
const template = new Game(GAMEPLAY.WIDTH, GAMEPLAY.HEIGHT);
template.run();
template.emitter.once('ready', () =>
{
template.run();
});
10 changes: 5 additions & 5 deletions src/scenes/gameScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export class GameScene extends PIXI.Container

async preload()
{
PIXI.Assets.add('ball', './assets/Ball.png');
PIXI.Assets.add('bounce', './assets/bounce.mp3');
PIXI.Assets.add({alias: 'ball', src: './assets/Ball.png'});
PIXI.Assets.add({alias: 'bounce', src: './assets/bounce.mp3'});

await PIXI.Assets.load(['ball', 'bounce']);
}
Expand All @@ -31,10 +31,10 @@ export class GameScene extends PIXI.Container
this.addChild(this.ball2);
}

update(deltaTime)
update(ticker)
{
// bounce the balls
this.ball.update(deltaTime);
this.ball2.update(deltaTime);
this.ball.update(ticker);
this.ball2.update(ticker);
}
}
11 changes: 6 additions & 5 deletions src/scenes/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class TitleScene extends PIXI.Container

async preload()
{
PIXI.Assets.add('testBG', './assets/BG1320x780-2.png');
PIXI.Assets.add({alias: 'testBG', src: './assets/BG1320x780-2.png'});

this.backgroundTexture = await Assets.load('testBG');
}
Expand All @@ -24,9 +24,11 @@ export class TitleScene extends PIXI.Container
this.addChild(scalerBackground);

// a clickable label to cause a scene change
const text = new PIXI.Text('Click me!',
{
fill: 0xffffff
const text = new PIXI.Text({
text:'Click me!',
style:{
fill: 0xffffff
}
});
text.interactive = true;
text.anchor.set(0.5, 0.5);
Expand All @@ -36,7 +38,6 @@ export class TitleScene extends PIXI.Container
// when the label is clicked, preload the game scene and then tell the app to switch scenes
const nextScene = new GameScene(this.game);
this.game.app.state.scene.value = nextScene;

});

this.game.scaleManager.addEntity(new Anchor(
Expand Down