Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - tobcode

Pages: [1]
1
Graphics / Re: [Solved] Editing multiple Objects with a function
« on: October 16, 2023, 05:06:26 pm »
Additionally, you can wrap everything into a class, so you can share objects within the class scope and don't need to have global objects.

How would such a class look like? Sorry if this is a dumb question, but i have never worked with classes. Up until now i was able to get it working by global variables, however this is not the cleanest approach.

2
Graphics / [Solved] Editing multiple Objects with a function
« on: October 12, 2023, 09:20:52 pm »
Hello everyone,

i want to set Properties of multiple objects in an function outside of main().
The problem is that if the objects are created in main(), then it is not possible to send them to the function as a parameter.

Example:


int main(){
sf::RectangleShape test[50];
initialize(test);
}


void initialize(sf::RectangleShape test[]){
  for(int j = 0; j<50; j++)
  {
    test[j].setOutlineColor(something);
  }
}



my only solution to this Problem is to make the objects global. when they are defined outside of main it works of course, but that is not what i want to do.
It is possible to pass am object by reference into a function.
But how about an array of objects?

i know the example Code doesn't run but how do i pass an array of RectangleShapes into a function?

Pages: [1]
anything