Skip to main content
gamedev.net
🔒 Locked

Camera issue

Started by n00bz0rd2 Apr 5, 2009 at 12:16 PM 1 replies 600+ views
Original Post
n00bz0rd2
n00bz0rd2
I'm making an RTS game and I have an issue with one part of it. Basically, I have 2 sprites, that when clicked are highlighted. The highlighted sprite can move to any location where the user has right clicked. You can also click and drag to select multiple units. The problem I am having is that when you move the camera, the bounding box for the mouse doesn't move with it. So if I wanted to click and drag, the selection box will start somewhere else other than where I've clicked. I've uploaded the project file. You will need XNA 3 to run it. http://www.mediafire.com/download.php?dym2qzzmwyz
n00bz0rd2
n00bz0rd2
^bump.

I've tried adding in the camera.transform in a number of places but it hasn't helped. I know its a relatively simple issue, but I can't figure it out
Kalten
Kalten
I've had a look at the code you've supplied and i cant see the code to talk about the bounding box...

Regardless, I would expect that the way you are calling the bounding box creation is based on the camera's view point rather than a world location. When you move your camera's viewpoint the screen co-ordinates will move with it, probably leading to your issue.

For example, if I select 100,100 on the screen and i move the screen around the point on the screen or viewport will still be 100,100... so in terms of what i see drawn on the screen there will be a bounding box starting from 100,100 limited to 0,0 -> screenwidth, screenheight.

You will probably want to recode your bounding box to use a world location reference, and to render the box based on the relative world locations...

Again an example, if i select a world point of 100,100, and move the camera 2 screenwidths to the right, then the world point that i'm seeing on the ground would be 100+(2*screenwidth),100 and likely would have a bounding box spanning between those two points.

Consider it to be similar to how you locate your soldiers on the ground... if you move the camera does the soldier stay where it is relative to the ground or does it move with the camera?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.