daz-b-like / ProCam2D_Godot4.x

The ultimate camera for all your 2D needs.
MIT License
53 stars 2 forks source link

ProCam2D - A Custom 2D Camera Node for Godot

procam icon

ko-fi

Overview

ProCam2D Icon ProCam2D is a powerful and feature-rich custom 2D camera node designed for the Godot Engine. It aims to provide developers with a AAA-quality camera system suitable for all types of 2D games. ProCam2D is a standalone camera solution that surpasses the built-in Camera2D node, offering extensive customization and control.

Key Features

Installation

  1. Download or clone the ProCam2D repository.
  2. Copy the ProCam2D folder into your Godot project’s addons directory.
  3. Enable the ProCam2D plugin in your project settings.
  4. Save and Reload your project from the project menu to ensure the plugin is properly loaded.

Usage

Basic Setup

  1. Press CTRL + A or the "+" icon on the scene tab to add a new node.

  2. Type "pcam" in the search box to filter the nodes and show all 7 ProCam2D nodes.

    Adding ProCam nodes

  3. Add a ProCam2D node to your scene.

  4. Add one or more PCamTarget nodes as children of the objects you want the camera to follow.

  5. Configure the camera properties and target properties via the inspector.

Example: Basic Camera Setup

extends Node2D

func _ready():
    procam.set_follow_mode(ProCam2D.FollowMode.SINGLE_TARGET)

Example: Adding Addons

Addons can be easily added to the ProCam2D node by following these steps:

  1. Click on the Addons property on the inspector and increase its Array size:

    Adding addons

  2. Click on any [empty] fields and choose your addon from the list of resources:

    Adding addons

  3. Configure the addons properties:

    Adding addons

If you added an addon through the inspector, you can access it like this:

func _ready():
    var shake_addon = procam.get_addons()[index] # Replace index with the index of the addon on the inspector. 
    shake_addon.shake() #Use this method to start any shake addon
    shake_addon.stop() #Use this method to stop any shake addon

addon index

To add an addon through code, use this method:

func _ready():
    var shake_addon = PCamShake.new()
    shake_addon.apply_preset(shake_addon.Preset.GUNSHOT) # This is a method available to the screenshake addon
    procam.add_addon(shake_addon)
    shake_addon.shake() # This is a method available to the screenshake addon see below for all available addons

Available addons

Addons are processed in order of their priority. from lowest to highest.

PCamShake

This addon is used to add exciting screenshakes to your game.

shake

Enums

PCamGrids

This addon is used to make the camera snap to grid. The snapping will be smooth or instant depending on the camera's smooth_drag property.

grids

PCamMouseFollow

This addon adds pointer influence to the camera. Can be used for side scrollers that use the mouse for aiming or looking around.

mouse folllow

ProCam2D Properties

Enums

Camera Properties

Public Methods

Signals

Additional Nodes

PCamTarget Icon PCamTarget

A node that the camera follows. It can be placed as a child of a player. Multiple targets can be placed.

PCamTarget

Properties

PCamCinematic Icon PCamCinematic

Defines a point in a cinematic sequence. PCamCinematic nodes with the same id form a cinematic sequence which can be played with procam.start_cinematic(id)

PCamCinematic

Properties

PCamMagnet Icon PCamMagnet

Attracts or repels the camera like a magnet.

PCamMagnet

Properties

Signals

PCamZoom Icon PCamZoom

Changes the zoom of the camera within its area of influence.

PCamZoom

Properties

Signals

PCamRoom Icon PCamRoom

Constrains the camera to an area it covers.

PCamRoom

Properties

Signals

PCamPath Icon PCamPath

Constrains the camera to a path on a specified axis.

PCamPath

Properties

Addons

ProCam2D is designed to be extensible. You can create your own addons to add custom functionality to the camera.

Writing Your Own Addon

Creating an addon for the camera system involves extending the PCamAddon class. This class provides a standardized way to modify camera behavior in different stages: pre_process, post_smoothing, and final_adjust. Each stage allows you to adjust the camera's properties at different points in the update cycle.

Addon Structure

An addon inherits from the PCamAddon class and should implement the following methods:

  1. setup(camera): Called when the addon is initialized. Use this method to set the initial state or configurations, such as defining the stage in which the addon operates.
  2. exit(camera): Called when the addon is disabled or removed. Use this to clean up or reset any changes made by the addon.

In addition to these lifecycle methods, an addon should override one of the following methods to define its behavior during a specific stage:

Properties

Sample Addon: Grids

This addon aligns the camera's target position to a grid, ensuring that movement snaps to predefined intervals.

tool
extends PCamAddon
class_name PCamGrids

export var grid_size := Vector2(64, 64)
export var grid_offset := Vector2.ZERO

func setup(camera):
    stage = "pre_process"

func pre_process(camera, delta):
    # Snap the target position to the grid and apply an offset if needed
    var snapped_target = camera._target_position.snapped(grid_size) + grid_offset
    camera._target_position = snapped_target

The addon will now show up on the list of resources. You can then add it to the camera through the inspector or like so:

var grid_addon = PCamGrids.new()
func _ready() -> void:
    procam.add_addon(grid_addon)

Implementing a New Addon

To create your own addon:

  1. Define the Addon: Extend PCamAddon and set up any necessary properties or export variables.
  2. Set Up Stages: Use the setup method to specify the stage in which the addon should operate. Implement the corresponding method (pre_process, post_smoothing, or final_adjust) to define the addon's behavior.
  3. Enable the Addon: Ensure your addon is enabled by setting the enabled property to true.

This framework provides a flexible way to modify camera behavior by compartmentalizing changes into different processing stages.

Support

If you find ProCam2D useful and would like to support its development, consider buying me a coffee:

ko-fi

Contributing

Contributions are welcome! For detailed instructions on how to contribute, please see our Contributing Guide.

Reporting Bugs or Requesting Features

To report a bug or request a feature, please use the Issues section of this repository. Make sure to follow the templates provided for better clarity and organization.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Thank you for using ProCam2D! If you have any questions or need further assistance, feel free to reach out.