How can I give this vector's members unique values each time?

closed account (E8A4Nwbp)
I made a vector to store multiple values like so:

1
2
3
4
5
6
7
8

	for (int i = 0;i< 5;i++)
	{
		X= MenuItemImage::create//...

		XVector.push_back(X);
//...
};

the vector as well as "X" is public.

Now, elsewhere, I want to run another loop, where I give all the values in the X vector a unique position.
I tried this
1
2
3
4
5
6
7
8
9
10
11
12
13
	std::vector<Vec2> X;

	X.push_back(Vec2(visibleSize.width / 3.55 + origin.x, visibleSize.height / -0.67 + origin.y));
	X.push_back(Vec2(visibleSize.width / 4.43 + origin.x, visibleSize.height / -0.68 + origin.y));
	X.push_back(Vec2(visibleSize.width / 4.54 + origin.x, visibleSize.height / -0.66 + origin.y));
	X.push_back(Vec2(visibleSize.width / 3.56 + origin.x, visibleSize.height / -0.654 + origin.y));
//so on

	
	for (int i = 0; i < 5; i++) {
		Vec2 position = X[i];
		XVector[i]->runAction(MoveTo::create(0.9, Vec2(position)));
	}

but to no avail
What am I doing incorrectly? I have not manipulated the vector anywhere
additionally, is there anyway I can use a for loop like this to achieve the positioning?
1
2
for (MenuItemImage *X: XVector) {
	}
Last edited on
What does "but to no avail" mean?

You've been here long enough, under your various different accounts, to know very well that you should give a clear, complete, and precise description of the problem you're seeing.

You've also been here long enough to know very well that you should post a minimal, compilable codeset that reproduces the problem.

It's hard not to conclude that this is just another of your desperate, attention-seeking trolling attempts.
closed account (E8A4Nwbp)
What does "but to no avail" mean?
Mike, why would I want to waste your time? this is delaying my project. By this I mean it does not work.
Sorry if the original post seems rushed, too. the initial was 404d
You can't compile this, because it's for a framework...

But otherwise, I will elucidate like you asked:

The first code snippet is a for loop, in which I make 5 "menuitemimages" and each each of those indivual menuitemimages to a public vector

the second code snippet, is where I try to individually run a unique action to each member of the vector.
THE ISSUE IS
The action doesn't work. Nothing happens. Which is odd, what am I missing?

Last edited on
How do you know that these
1
2
Vec2(visibleSize.width / 3.55 + origin.x, visibleSize.height / -0.67 + origin.y));
Vec2(visibleSize.width / 4.43 + origin.x, visibleSize.height / -0.68 + origin.y));

would create two different objects?

You're passing different values to the constructor, but what does the constructor do with those values?

Additional question; how do you know they're coming out the same?

the second code snippet, is where I try to individually run a unique action to each member of the vector.
THE ISSUE IS
The action doesn't work.

What does that have to do with
How can I give this vector's members unique values each time
? Your question is very unclear.
Last edited on
closed account (E8A4Nwbp)
Ok, @Repeater taking into account your confusion, I will make a pseudo C++ example.

Somewhere in the header (written from memory, expect code typos)
1
2
Gameworks::Sprite H;
std::vector<Gameworks::Sprite*> VectH;


function A:
1
2
3
4
5
6
for (int i = 0;i< 5;i++)
	{
	
            H = Sprite::create([***unique position], [imagefile]);
	    VectH.push_back(H);
}


***the for loop repeats five times, so each H copy goes to a unique position

Ok, the code ABOVE works FINE. It creates FIVE sprites, and they are positioned uniquely. Now a function is called, and this function's purpose is to MOVE all the FIVE SPRITES to another position.

I tried this:

Function B
1
2
3
4
5
6
7
8
9
10
11
12
13
std::vector<Vec2> X;

	X.push_back(Vec2(visibleSize.width / 3.55 + origin.x, visibleSize.height / -0.67 + origin.y));
	X.push_back(Vec2(visibleSize.width / 4.43 + origin.x, visibleSize.height / -0.68 + origin.y));
	X.push_back(Vec2(visibleSize.width / 4.54 + origin.x, visibleSize.height / -0.66 + origin.y));
	X.push_back(Vec2(visibleSize.width / 3.56 + origin.x, visibleSize.height / -0.654 + origin.y));
//so on

	
	for (int i = 0; i < 5; i++) {
		Vec2 position = X[i];
		VectH[i]->runAction(MoveTo::create(0.9, Vec2(position)));
	}

But when this is called, they do not move.
Can you see why, because I unfortunately cannot.

I hope this elucidates things
Last edited on
How do you know that each Vec2 is different?
closed account (E8A4Nwbp)
I used the very same vector of Vec2s before, to position them elsewhere, and it worked

p.s, why do you suspect they wouldn't be?
Last edited on
closed account (E8A4Nwbp)
Here's something, I CAN change their position, If I run a loop like this
But all 5 Hs are affected by the same action, of course, as there is no i++
1
2
3
	for (MenuItemImage *H: VectH) {
		H->//some action
	}

But I can't give each H a unique action, as there isn't a constantly incremented value
Last edited on
closed account (E8A4Nwbp)
Solved. Sorry, the code is fine, It was an error within the code itself elsewhere. I was not trolling, I just forgot something
Last edited on
Topic archived. No new replies allowed.