XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

[SOLVED] [Thank you!! n_n] Getting (1,2) of a Vector2 (noob question) 0.0

Last post 01/05/2009 19:15 by Daniel Hanson. 3 replies.
  • 01/05/2009 18:44

    [SOLVED] [Thank you!! n_n] Getting (1,2) of a Vector2 (noob question) 0.0

    How do I get values 1 and 2 of a Vector2
    and use them as follows
     this is my my_pos Vector (64,64)

    how do i do this?
    my_x = my_pos.value1;
    my_y = my_pos.value2;

    Hope u understand my question any help would be great n_n
  • 01/05/2009 18:53 In reply to

    Re: Getting (1,2) of a Vector2 (noob question) 0.0

    vector2 my_pos = new vector2(64,93)

    means

    my_pos.X is equal to 64

    and

    my_pos.Y is equal to 93


    if it were a vector3, the third would be the "X, Y, & Z" value,
    and a vector 4 would be the "X, Y, Z, & W"


    Quando Omni Flunkus Moritati
    _________________________
    When all else fails, play dead
  • 01/05/2009 19:06 In reply to

    Re: Getting (1,2) of a Vector2 (noob question) 0.0

    Hi, Thanks for replying, I'm not very good at explaining code yet, But I guess I mean.
    I need to be able to write a Vector2 like this:

    u see I've save a velocity like this
    spr.velocity = new Vector2((float)Math.Cos(spr.rotation), (float)Math.Sin(spr.rotation)) * 2; 
    I move my_player like this "spr.my_pos += spr.velocity;" using Vectors
    But i need to read it like this
    spr.destinationRect = new Rectangle(spr.my_x, spr.my_y, spr.spriteWidth, spr.spriteHeight); 
    Without using vectors
    Id rather replace "spr.my_x, spr.my_y" with the my_pos vecotor but I dont know how to do that.
    so atm I'm tring to save the first value of my_pos vector to my_x and the second valuse to my_y.

    Or did I just make my problem even more confusing? 0.o
  • 01/05/2009 19:15 In reply to

    Re: Getting (1,2) of a Vector2 (noob question) 0.0

    Just as you can access the "velocity" member of your sprite using the member-of operator '.', you can use it to access the X and Y coordinate values of your Vector2. spr.velocity.X will give you the X coordinate, and spr.velocity.Y will give you the Y coordinate.

    spr.destinationRect = new Rectangle(spr.velocity.X, spr.velocity.Y, spr.spriteWidth, spr.spriteHeight);
    Previously known as "Rainault".
    Twitter - me, Jade Vault Games
    Announcing ASCII Quest, a Roguelike under development for Xbox LIVE Indie Games
Page 1 of 1 (4 items) Previous Next