Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Movementcat

Member Since 26 May 2013
Offline Last Active Jul 07 2013 07:04 AM

Topics I've Started

Problem with Camera and Mousepos XNA

06 July 2013 - 04:55 PM

Dear Guys,

 

I use a Camera in my 2D XNA Game, and have really Problems to get the right Position of my Mouse Cursor you have maybe a Solution?

        //Klassen Variablen

        public Matrix transform;
        Viewport view;
        public Vector2 center;

        //Eigenschaften

        float _width { get; set; }
        float _height { get; set; }
        float _rotation { get; set; }
        float _zoom { get; set; }
        float _camSpeed { get; set; }
        bool _follow { get; set; }

        //Konstruktor
        
        public Camera(Viewport newView)
        {
            view = newView;
            _zoom = 1f;
            _rotation = 0f;
            center = new Vector2(0, 0);
            _camSpeed = 5f;
            _follow = true;
        }

        #region Kamera Kontrolle


        //Camera Position Updaten

        public void Update(IFocus focus)
        {
 
            if(_follow == true)
            center = focus.getFocus();
            _width = focus.getWidth() / 2;
            _height = focus.getHeight() / 2;

            transform = Matrix.CreateTranslation(new Vector3(-center.X - _width, -center.Y - _height, 0)) *
                Matrix.CreateRotationZ(_rotation) *
                Matrix.CreateScale(_zoom) *
                Matrix.CreateTranslation(new Vector3(view.Width / 2, view.Height / 2, 0));
        }
    }
}

If i try to transform the MousePosition aswell, the Mouse is still a bit off the Center if im in negativ Values of the Screen.

 

mousePos = Vector2.Transform(mousePos, Matrix.Invert(cam.transform));

 

I cant do any precise shooting or anything else.

 

maybe you know a answer.

 

Greetings Move

 

 

 


Problem with Camera and Mousepos

25 June 2013 - 09:14 AM

Dear Guys,

 

i have a understanding Question it work now for me but i dont know why maybe you can help or why even the Problem occur's.

 

I have a TileMap with 32, 32 Tiles and a normal Camera Class that follows my Player and for the Editor it follow the Mouse, but there i had a Probleme the Mouse Position was incorrect so i did Invert the Matrix for my Mouse Position.

 

It worked fine, exept in the Display Region under 0,0 so -32,0 etc etc or -32,-32, or every negativ value. Hope you understand me since my English arent the best.

 

It was not much difference but the Cursor was just a bit off. So i will show you some Code maybe you know why this happens.

 

 

Camera.cs

 public void Update(IFocus focus)
        {
 
            if(_follow == true)
            center = focus.getFocus();
            _width = focus.getWidth() / 2;
            _height = focus.getHeight() / 2;

            transform = Matrix.CreateTranslation(new Vector3(-center.X, -center.Y, 0)) *
                Matrix.CreateRotationZ(_rotation) *
                Matrix.CreateScale(_zoom) *
                Matrix.CreateTranslation(new Vector3(view.Width / 2, view.Height / 2, 0));
        }
    }
}


my Input Manager 

mousePos.X = mouseState.X;
            mousePos.Y = mouseState.Y;
            mousePos = Vector2.Transform(mousePos, Matrix.Invert(cam.transform));

            if (mousePos.Y < 0)
            {
                mousePos.Y = mousePos.Y - 32;
            }

            if (mousePos.X < 0)
            {
                mousePos.X = mousePos.X - 32;
            }

            return mousePos;
        }

So here is a intresting Point, if i have this 2 If cases, everything ist fine but if i delete them my Cursor is off in negativ Display Values. But still fine in normal Display Regions.

 

And maybe its Interesting aswell here i "snap" the current Tile so that my Cursor is always Perfectly over a Tile its in my Editor.cs

 _cursorLocX = (int)(mousePos.X / _tileWidth) * _tileWidth;
 _cursorLocY = (int)(mousePos.Y / _tileHeight) * _tileHeight;

Thanks for reading, if you need any more Informations please let me know.

 

greetings Move


Im new and looking for Language + Framework to start with.

26 May 2013 - 06:21 PM

Dear,

 

im from Germany and 25 Year's old, so far i have nearly 0 Experience with programming and it will be just a Hobby. I want create small 2D Games so im looking for an easy Language + Framework.

 

My Toughts so far C# + XNA, Pyhton with Pygame or C++ with SFML 2.0.

 

I really like C# + XNA + VS but i did hear XNA is dying so what would you advice me?

 

Greetings Move


PARTNERS