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

#include <physics.hpp>

Inheritance diagram for StaticBody:
PhysicsBody Component

Public Member Functions

 StaticBody ()
 
 StaticBody (const std::shared_ptr< Shape > &shape)
 
void physicsUpdate () override
 
void initCompute () override
 
void setPosition (Vector2 pos) const
 
void setAngle (float angle) const
 
template<class Archive >
void save (Archive &ar) const
 
template<class Archive >
void load (Archive &ar)
 
- Public Member Functions inherited from PhysicsBody
void exit () override
 
void initialize () override
 
template<class Archive >
void save (Archive &ar) const
 
template<class Archive >
void load (Archive &ar)
 
b2BodyId getBodyId ()
 
b2ShapeId getShapeId ()
 
- Public Member Functions inherited from Component
virtual ~Component ()=default
 
virtual void update (float deltaTime)
 
virtual void render (std::shared_ptr< Window > window)
 
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)
 

Additional Inherited Members

- Public Attributes inherited from PhysicsBody
Signal< PhysicsBody * > collisionEnter
 
Signal< PhysicsBody * > collisionExit
 
Signal< PhysicsBody * > collisionHit
 
Signal mouseEntered
 
Signal mouseExited
 
std::shared_ptr< Shapeshape
 
- Protected Attributes inherited from PhysicsBody
bool sensor
 
b2BodyDef bodyDef
 
b2BodyId bodyId
 
b2ShapeId shapeId
 
Transform storedTransform
 

Detailed Description

StaticBody

The StaticBody component is a type of PhysicsBody. The main difference between StaticBody and any other physics bodies is that it does not move, at all, unless it is moved by the user.

Like any other physics body, once it is attached to a node, you must not move the node through its transform property but through the setPosition() and setAngle() functions of the physics body.

Example usage:

std::shared_ptr<Node> myNode = std::make_shared<Node>();
std::shared_ptr<Shape> myShape = std::make_shared<CircleShape>(20.0f); // Create a circle with a 20 pixel radius
std::shared_ptr<StaticBody> staticBody = std::make_shared<StaticBody>(myShape);
myNode->addComponent(staticBody);
myNode->addComponent(std::make_shared<ShapeSprite>(myShape)); // also add a ShapeSprite for rendering!
// later on, after the node is initialized, you can move the static body:
staticBody->setPosition(Vector2{100.0f, 100.0f});
Definition definitions.hpp:77

For more insight regarding anything physics related, the physics example and node tree example also utilize staticbodies!

Constructor & Destructor Documentation

◆ StaticBody() [1/2]

StaticBody::StaticBody ( )

◆ StaticBody() [2/2]

StaticBody::StaticBody ( const std::shared_ptr< Shape > &  shape)

Member Function Documentation

◆ initCompute()

void StaticBody::initCompute ( )
overridevirtual

Reimplemented from PhysicsBody.

◆ load()

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

◆ physicsUpdate()

void StaticBody::physicsUpdate ( )
overridevirtual

Implements PhysicsBody.

◆ save()

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

◆ setAngle()

void StaticBody::setAngle ( float  angle) const

◆ setPosition()

void StaticBody::setPosition ( Vector2  pos) const

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