Comments (6)
@medecau @tedbigham @benhalverson Any ideas on how we could create some sort of generalised UI class that could handle watching for viewport resizes and populate those changes throughout the whole game real-time?
I'm sure at some point we'll be hooking into document.addEventListener('resize', () => { ... });
to watch for the viewport changes... But I'm just thinking about the best approach for architecture.
I just don't want us to end up in a situation where we're juggling 9999999 different functions for resizing each little component of the game.
One thought I had was maybe we could do something along the lines of:
- Resize canvas to viewport
- Call the
create()
function of the current scene again (but somehow prevent duplicate sprites, etc. being added?)
from no-place-like.
Confident Phaser already has the necessary infrastructure to handle viewport resizes.
Could it be that we have a Camera like object? I need to dive into the game code and read the docs a little bit.
from no-place-like.
from no-place-like.
It seems like there's three things we care about here:
- Gameplay objects. These need to be scaled but not moved (their world position is not changing).
- UI objects. This need to be moved to stay in the same relative position on the screen (reactive) and probably scaled
- The camera. This might need to be zoomed to maintain a constant physical side for the MC, and will probably be specific one-time code.
I'm thinking that instead of setting x, y, and displaySize when you add stuff to the scene, you could add new fields that give relative values for x, y, and displaySize. Then add a method to GameObject (polyfill ?) that calculates x, y, and displaySize based on the current canvas size. You'd call this method immediately when creating objects (mostly in create() ). You'd also loop over all living game objects and call it every time the game is resized.
You might end up with 2 or 3 types of that method depending whether the object is gameplay, or UI, or whatever high level type you have (i usually only have 2).
from no-place-like.
some docs for the scaling games from Phaser 3
https://github.com/samme/phaser3-faq/wiki#how-do-i-scaleresize-the-game-canvas
A demo link is here. https://labs.phaser.io/100.html?src=src\scalemanager\fit%20running%20game.js
from no-place-like.
Instead of having a listener on resize()
which will end up affecting you in the long run if you want to resize objects on the fly might be better to add the event listener on screen.orientation
Docs.
As for the resizing @tedbigham solution would work to add on to that you can use CSS to resize the main canvas and build the x and y relative to that.
from no-place-like.
Related Issues (20)
- Make intro animation skipable HOT 1
- Highlight speaking NPC somehow
- Create turrets and other automatic defences at the cave entrance
- Create "Fight" version of each NPC & an in-field follow & behaviour system HOT 1
- Inventory system
- Enemy drop system
- Extendable Item class HOT 1
- Implement weapon engineering system
- Get async/await working in dev env
- Give dialog system a nice box
- Dialog system config `answers` key should take an array
- Double jump HOT 3
- Add Twitch subs to credits automagically HOT 3
- Gameplay Mechanics Overhaul (Kinda) HOT 4
- Create a world "entities" property & utility methods to query
- Prevent shooting through walls
- Investigate Phaser 3 Input Manager (or Create One)
- Auto-running bug
- Flyout Menu
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from no-place-like.