Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert last two examples to AppBase #6038

Merged
merged 1 commit into from
Feb 6, 2024
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
42 changes: 29 additions & 13 deletions examples/src/examples/graphics/particles-anim-index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,40 @@ import * as pc from 'playcanvas';
*/
async function example({ canvas, deviceType, assetPath, glslangPath, twgslPath }) {

// Create the application and start the update loop
const app = new pc.Application(canvas, {});
const assets = {
'particlesNumbers': new pc.Asset('particlesNumbers', 'texture', { url: assetPath + 'textures/particles-numbers.png' })
};

const gfxOptions = {
deviceTypes: [deviceType],
glslangUrl: glslangPath + 'glslang.js',
twgslUrl: twgslPath + 'twgsl.js'
};

const device = await pc.createGraphicsDevice(canvas, gfxOptions);
const createOptions = new pc.AppOptions();
createOptions.graphicsDevice = device;

createOptions.componentSystems = [
pc.RenderComponentSystem,
pc.CameraComponentSystem,
pc.LightComponentSystem,
pc.ParticleSystemComponentSystem,
pc.ScreenComponentSystem,
pc.ElementComponentSystem,
];
createOptions.resourceHandlers = [
// @ts-ignore
pc.TextureHandler,
];

const app = new pc.AppBase(canvas);
app.init(createOptions);

// Set the canvas to fill the window and automatically change resolution to be the same as the canvas size
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
app.setCanvasResolution(pc.RESOLUTION_AUTO);

// Ensure canvas is resized when window changes size
const resize = () => app.resizeCanvas();
window.addEventListener('resize', resize);
app.on('destroy', () => {
window.removeEventListener('resize', resize);
});

const assets = {
'particlesNumbers': new pc.Asset('particlesNumbers', 'texture', { url: assetPath + 'textures/particles-numbers.png' })
};

const assetListLoader = new pc.AssetListLoader(Object.values(assets), app.assets);
assetListLoader.load(() => {

Expand Down
45 changes: 34 additions & 11 deletions examples/src/examples/graphics/particles-random-sprites.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,41 @@ import * as pc from 'playcanvas';
* @param {import('../../options.mjs').ExampleOptions} options - The example options.
* @returns {Promise<pc.AppBase>} The example application.
*/
async function example({ canvas, assetPath }) {
async function example({ canvas, assetPath, deviceType, glslangPath, twgslPath }) {

const app = new pc.Application(canvas, {
mouse: new pc.Mouse(document.body),
touch: new pc.TouchDevice(document.body),
elementInput: new pc.ElementInput(canvas)
});
const assets = {
'particlesCoinsTexture': new pc.Asset('particlesCoinsTexture', 'texture', { url: assetPath + 'textures/particles-coins.png' }),
'particlesBonusTexture': new pc.Asset('particlesBonusTexture', 'texture', { url: assetPath + 'textures/particles-bonus.png' })
};

const gfxOptions = {
deviceTypes: [deviceType],
glslangUrl: glslangPath + 'glslang.js',
twgslUrl: twgslPath + 'twgsl.js'
};

const device = await pc.createGraphicsDevice(canvas, gfxOptions);
const createOptions = new pc.AppOptions();
createOptions.graphicsDevice = device;
createOptions.mouse = new pc.Mouse(document.body);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd remove mouse / touch / element input, it does not seem the example needs any input.

createOptions.touch = new pc.TouchDevice(document.body);
createOptions.elementInput = new pc.ElementInput(canvas);

createOptions.componentSystems = [
pc.RenderComponentSystem,
pc.CameraComponentSystem,
pc.LightComponentSystem,
pc.ParticleSystemComponentSystem,
pc.ScreenComponentSystem,
pc.ElementComponentSystem,
];
createOptions.resourceHandlers = [
// @ts-ignore
pc.TextureHandler,
];

const app = new pc.AppBase(canvas);
app.init(createOptions);

// Set the canvas to fill the window and automatically change resolution to be the same as the canvas size
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
Expand All @@ -23,11 +51,6 @@ async function example({ canvas, assetPath }) {
window.removeEventListener('resize', resize);
});

const assets = {
'particlesCoinsTexture': new pc.Asset('particlesCoinsTexture', 'texture', { url: assetPath + 'textures/particles-coins.png' }),
'particlesBonusTexture': new pc.Asset('particlesBonusTexture', 'texture', { url: assetPath + 'textures/particles-bonus.png' })
};

const assetListLoader = new pc.AssetListLoader(Object.values(assets), app.assets);
assetListLoader.load(() => {
// Create an Entity with a camera component
Expand Down
29 changes: 25 additions & 4 deletions examples/src/examples/graphics/particles-snow.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,36 @@ import * as pc from 'playcanvas';
* @param {import('../../options.mjs').ExampleOptions} options - The example options.
* @returns {Promise<pc.AppBase>} The example application.
*/
async function example({ canvas, assetPath }) {

// Create the application and start the update loop
const app = new pc.Application(canvas, {});
async function example({ canvas, assetPath, deviceType, glslangPath, twgslPath }) {

const assets = {
'snowflake': new pc.Asset('snowflake', 'texture', { url: assetPath + 'textures/snowflake.png' })
};

const gfxOptions = {
deviceTypes: [deviceType],
glslangUrl: glslangPath + 'glslang.js',
twgslUrl: twgslPath + 'twgsl.js'
};

const device = await pc.createGraphicsDevice(canvas, gfxOptions);
const createOptions = new pc.AppOptions();
createOptions.graphicsDevice = device;

createOptions.componentSystems = [
pc.RenderComponentSystem,
pc.CameraComponentSystem,
pc.LightComponentSystem,
pc.ParticleSystemComponentSystem
];
createOptions.resourceHandlers = [
// @ts-ignore
pc.TextureHandler,
];

const app = new pc.AppBase(canvas);
app.init(createOptions);

const assetListLoader = new pc.AssetListLoader(Object.values(assets), app.assets);
assetListLoader.load(() => {
app.start();
Expand Down