Calamity Engine 1.0.0
A cross-platform 2D game engine written in C++ and SDL3.
Loading...
Searching...
No Matches
Script Class Reference

#include <components.hpp>

Inheritance diagram for Script:
Component

Public Member Functions

virtual void update (float deltaTime)
 
virtual void initialize ()
 
virtual void physicsUpdate ()
 
virtual void render (std::shared_ptr< Window > window)
 
virtual void exit ()
 
template<class Archive >
void save (Archive &ar) const
 
template<class Archive >
void load (Archive &ar)
 
- Public Member Functions inherited from Component
virtual ~Component ()=default
 
virtual void input (InputEvent &event)
 
virtual void postLoad ()
 
NodegetNode () const
 
void setNode (Node *n)
 
template<class Archive >
void save (Archive &ar) const
 
template<class Archive >
void load (Archive &ar)
 

Detailed Description

Script component

A base class for all scripts attached to nodes. It exposes the Components lifetime functions, which the user can override and change.

To create a script and attach it to a node, create a header file somewhere like scripts/ExampleScript.hpp:

#pragma once
// include everything you want here
#include <cereal/types/polymorphic.hpp>
#include <cereal/archives/json.hpp>
class ExampleScript : public Script
{
public:
// serialization functions to make cereal happy.
// you can leave these empty if you don't need to serialize any data in your script, but they need to be here for cereal to work.
// to serialize something, call ``ar(variable1, variable2, variable3)`` in both functions, but make sure to call it in the same order in both functions.
template <class Archive>
void save(Archive &ar) const {};
template <class Archive>
void load(Archive &ar) {};
void initialize()
{
// initialize logic here
}
void update(float deltaTime)
{
// update logic here
}
};
// you also have to do this for your game to compile
CEREAL_REGISTER_TYPE(ExampleScript);
Definition components.hpp:387
CEREAL_REGISTER_TYPE(Label)
CEREAL_REGISTER_POLYMORPHIC_RELATION(Component, Label)

And do this to add your script to a node:

// You must include the script before hand:
#include "scripts/ExampleScript.hpp"
std::shared_ptr<Node> exampleNode = std::make_shared<Node>();
exampleNode->addComponent(std::make_shared<ExampleScript>());

Member Function Documentation

◆ exit()

virtual void Script::exit ( )
inlinevirtual

Reimplemented from Component.

◆ initialize()

virtual void Script::initialize ( )
inlinevirtual

Reimplemented from Component.

◆ load()

template<class Archive >
void Script::load ( Archive &  ar)
inline

◆ physicsUpdate()

virtual void Script::physicsUpdate ( )
inlinevirtual

Reimplemented from Component.

◆ render()

virtual void Script::render ( std::shared_ptr< Window window)
inlinevirtual

Reimplemented from Component.

◆ save()

template<class Archive >
void Script::save ( Archive &  ar) const
inline

◆ update()

virtual void Script::update ( float  deltaTime)
inlinevirtual

Reimplemented from Component.


The documentation for this class was generated from the following file: