0
\$\begingroup\$

In the first code I get a Vector2 random position and create an object with that, but in the second code I want to use the same constructor to create an object, but I want to pass a X and Y value to the constructor, that expects a Vector2 value.

Vector2 newPosition = NewRandomPosition;    
listTools.Add(new Tool(content, tools[i], newPosition));

I thought I could do something like this, but it didn't work!

int x = 30, y = 22;
listJunk.Add(new Junk(content, "junk", (x,y)));

Is there another way to do this? Thanks!

\$\endgroup\$
3
\$\begingroup\$

You need to create a Vector2 from the x and y values before using it. For example:

listJunk.Add(new Junk(content, "junk", new Vector2(x,y)));
\$\endgroup\$
  • \$\begingroup\$ Beat me to it by a few seconds. \$\endgroup\$ – Fibericon Aug 4 '12 at 8:52
  • \$\begingroup\$ Indeed, it was a matter of seconds lol :P \$\endgroup\$ – David Gouveia Aug 4 '12 at 8:53
3
\$\begingroup\$

Use a Vector2 object like this:

listJunk.Add(new Junk(content, "junk", new Vector2(x,y)));
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.