SetUserData
This command can be used to set a user data value which can be retrieved with the Object::GetUserData command.
Syntax
- void Object::SetUserData(const void* userdata)
Parameters
- userdata: this is a pointer to any data the user wishes to associate with this object.
Example
#include "Leadwerks.h"
using namespace Leadwerks;
Model* model = NULL;
class EntityData
{
public:
int health;
};
int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
World* world = World::Create();
Camera* camera = Camera::Create();
DirectionalLight::Create()->SetRotation(35,45,0);
//Create a model
model = Model::Box();
model->SetPosition(0,0,3);
//Create our own custom object
EntityData* entitydata = new EntityData;
entitydata->health = 100;
//Set the model user data
model->SetUserData(entitydata);
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
Leadwerks::Time::Update();
world->Update();
world->Render();
//Retrieve our custom object
EntityData* entitydata = (EntityData*)model->GetUserData();
//Display the health value
Draw::SetBlendMode(Blend::Alpha);
Draw::Text(String(entitydata->health),0,0);
Draw::SetBlendMode(Blend::Solid);
context->Sync();
}
return 0;
}