TransWikia.com

How to register SFML Vector2 operators with AngelScript?

Stack Overflow Asked by veridis_quo_t on November 24, 2021

I’m working on a game engine that uses SFML. I’m currently working on adding scripting with AngelScript, however, I’m having trouble registering sf::Vector2 with AngelScript. I have the basic constructor set up, I can use sf::Vector in AngelScript, but I need to add operators, since Vector2 foo = Vector2(10.0f, 5.0f); cannot be called from AngelScript without the = operator being defined for the type. Problem is: sf::Vector2 doesn’t actually have an = operator defined… Is there workaround, or do I either have to create my own vector2 class or rebuild SFML with the required operators added?

2 Answers

SFML DOES allow you to use the "=" operator for Vectors. The problem is you're using Vector2 which is just a template class and it's missing the arguments (e.g. Vector2, Vector2). You cannot perform operations on a template class by just skipping on the arguments. You can of course use the typedefs in SFML as pointed by @IRevenant, like:

Vector2f foo = Vector2f(10.0f, 5.0f);

OR

Vector2f C = A + B; //A and B are Vector2f

Answered by Himan2104 on November 24, 2021

sf::Vector2 is a template class, SFML contains a typedef for a Vector2 that uses floats called Vector2f https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Vector2.php

Answered by IRevenant on November 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP