Difference between revisions of "Camera"

From Castle Wiki
(Clarify camera behavior)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
The Camera, or most generally known as the Camera Viewport, is the part of a card's workspace that will be displayed on gameplay. It is located at the coordinates (0,0) by default and is represented by the black rounded rectangle. A camera viewport has a size of 10x14 units, which is the same for all devices.
The '''Camera''' represents the position in a [[Card]]'s space which is visible to the player.
 
== Moving through large worlds ==
Moving the camera is a mechanism for showing more of the world than will fit on screen at once. All Castle cards have a 10x14 viewport which is centered on the camera, which sits at (0, 0) by default. If a card needs more space that doesn't fit within that viewport, the solution is to move the camera.
 
To move the camera, first assign the camera to follow an [[Actor]]. The most common pattern is to do this inside a [[Rule]] when the actor is created: '''When this is created: Follow this with the camera'''.
 
Next, [[Motion|move]] the actor, either by assigning the actor some controls, or by giving it a velocity. As the actor moves, the camera will move with it, and you'll see more of the world space.
 
The camera can only follow one actor at a time.
 
== Scaling and rotating the camera ==
Once the camera is following an actor, it will respect the '''Camera Zoom''' and '''Camera Rotation''' properties of that actor. To change the initial values for those properties, open the [[Inspector]] for that actor and scroll to the bottom of the '''General''' tab.
 
Camera is a [[Behavior]] that each blueprint can configure. To change the camera zoom and rotation for a particular actor at playtime, use the rule [[Response]] for '''Modify a behavior property''' and choose '''Camera Zoom''' or '''Camera Rotation'''. These values can also be read using the [[Expression]] for the '''Value of a behavior property'''.
 
== Detecting when something is inside or outside the viewport ==
It can be useful to know when something enters or leaves the visible space in the card. You can detect this with the [[Trigger|Triggers]] '''When this enters the camera viewport''' and '''When this exits the camera viewport'''. There is also a [[Condition]] for '''If this is in the camera viewport'''.
 
== Positioning an actor relative to the camera ==
By default, all actors are positioned in card space. However, it can be useful to pin something to a particular part of the screen, even when moving through the world. For example, when building a health bar or displaying the score of a game, you might want that information to remain at the top of the screen. (Sometimes these elements are referred to as a HUD / Heads Up Display.)
 
To position an actor relative to the camera, edit its blueprint in the [[Inspector]], navigate to the '''General''' tab, and toggle '''Relative to camera'''.
 
Relative-to-camera actors will not [[Collision|collide]] with card space actors. You can think of them as existing in a separate layer.

Latest revision as of 18:36, 27 January 2023

The Camera represents the position in a Card's space which is visible to the player.

Moving through large worlds

Moving the camera is a mechanism for showing more of the world than will fit on screen at once. All Castle cards have a 10x14 viewport which is centered on the camera, which sits at (0, 0) by default. If a card needs more space that doesn't fit within that viewport, the solution is to move the camera.

To move the camera, first assign the camera to follow an Actor. The most common pattern is to do this inside a Rule when the actor is created: When this is created: Follow this with the camera.

Next, move the actor, either by assigning the actor some controls, or by giving it a velocity. As the actor moves, the camera will move with it, and you'll see more of the world space.

The camera can only follow one actor at a time.

Scaling and rotating the camera

Once the camera is following an actor, it will respect the Camera Zoom and Camera Rotation properties of that actor. To change the initial values for those properties, open the Inspector for that actor and scroll to the bottom of the General tab.

Camera is a Behavior that each blueprint can configure. To change the camera zoom and rotation for a particular actor at playtime, use the rule Response for Modify a behavior property and choose Camera Zoom or Camera Rotation. These values can also be read using the Expression for the Value of a behavior property.

Detecting when something is inside or outside the viewport

It can be useful to know when something enters or leaves the visible space in the card. You can detect this with the Triggers When this enters the camera viewport and When this exits the camera viewport. There is also a Condition for If this is in the camera viewport.

Positioning an actor relative to the camera

By default, all actors are positioned in card space. However, it can be useful to pin something to a particular part of the screen, even when moving through the world. For example, when building a health bar or displaying the score of a game, you might want that information to remain at the top of the screen. (Sometimes these elements are referred to as a HUD / Heads Up Display.)

To position an actor relative to the camera, edit its blueprint in the Inspector, navigate to the General tab, and toggle Relative to camera.

Relative-to-camera actors will not collide with card space actors. You can think of them as existing in a separate layer.