-
-
Notifications
You must be signed in to change notification settings - Fork 908
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
[FR] Camera #1161
Comments
Very interesting thoughts! I think this removes a lot of the nice simplicity of FCS though and the only thing it really gives it the possibility for multiple cameras right?
That part was very unintuitive I think - adding a component to a camera makes it ignore the camera. |
Maybe the names of classes are not very well thought-out. In the diagram
On the contrary! It encodes via the FCS the relationships that are currently stored in flags
There are several benefits of the new system:
|
I agree with that, seems too complicated to have a world and a camera. Especially since FlameGame is a component now and we could have multiple games and alternate between them as needed. |
We already have the notion of the world and the camera. Only they are merged together into a single entity, which limits extendability and the amount of reuse. If you look into the @override
void renderTree(Canvas canvas) {
// Don't call super.renderTree, since the tree is rendered by the camera
_cameraWrapper.render(canvas);
} So,
I cannot say I understand well how game-in-game currently works (for example, what happens to all the machinery of game loops, render boxes, overlays, etc). However, conceptually world-in-game is much simpler than game-in-game. |
This may be an interesting approach for people which wants to have multiple worlds in a game, but for people who don't need that (which by our experience on the community is the majority), we will just add complexity for the simple cases, which IMO is worse. |
I understand the unnecessary complexity angle. But that doesn't seem like an insurmountable obstacle to me. We can have one generic class, and then another designed for ease of use. |
This is a specific proposal for camera design, following the discussion in #931.
Overview
The following top-level classes to be added:
World
: a simple container class which has most other game elements as children. Its main functionality is that it suppresses rendering of its children, however updates are working normally. The elements inside the World can only be viewed via aCamera
.Camera
is a component that carries a reference to the world that it views, and aViewport
instance. Thus, aCamera
works as a component-wrapper for aViewport
class. Camera'srender
method applies the viewport transform before rendering its children. Effects that are applied to theCamera
should affect the viewport.Viewport
describes a "window" through which the game world is observed. This window has a specific size, shape, and a position on the canvas.Viewfinder
is a component that keeps track of the game world's current position, rotation angle, and scale (zoom). Thus, whileViewport
represents a window that can be moved around the screen, the job of theViewfinder
is to move the world within that window. Viewfinder'srender()
method will apply the clip mask from the viewport, its own transform, and then render the game world. Effects that are applied to theViewfinder
will move the current point of view within the world.CameraController
is a component that controls the behavior of the camera (the viewfinder). It can do things like follow a component, restrict camera's movement to within a certain global boundary, etc. There could be multiple controllers attached to a camera, and they can be inter-mixed with effects.Additional notes:
Camera
will be subject to the viewport transform, but not viewport clip mask. Such elements are what we commonly refer to.isHud
(or.ignoreCamera
) components..ignoreViewport
components.Transition
The following is the outline for how to introduce these changes in a non-breaking way:
FlameGame2
which derives fromFlameGame
and overridesadd*()
methods so that the components would be added to an internal.world
instance. Encourage users to try this new class and test how it works.FlameGame2
is working, renameFlameGame
intoFlameGame1
, andFlameGame2
intoFlameGame
.add*()
methods as@deprecated
and instruct the users to add their components togame.world
orgame.camera
directly. Components that need to be added outside of the game world will go through theaddToRoot()
method.add*()
method overrides. At this point whoever ignored warnings at stage 3 will have their game broken. MarkaddToRoot
method deprecated and instruct the users to use regularadd()
method.addToRoot
method, and the originalFlameGame1
class.Special cases
Camera.currentContext
which will be set whenever a camera begins its rendering pipeline, and reset when it finishes.render(canvas, context)
, but this is much more intrusive to current users;currentContext
will also protect us against infinite rendering loops when a camera watches itself.ParallaxLayer
component will be a regular component, belonging to the game world. When rendering, it will look at the camera's context and partially undo the translation that was applied by the camera. It will also need to modify the clip mask in the camera's context so that the children of the parallax layer can render correctly.render
, and have to be treated accordingly. This area needs more exploration, but touch events are not working properly even with the current implementation (in a sense that if a component modifiesrenderTree
, the touch events do not respect this).The text was updated successfully, but these errors were encountered: