Jump to content
  • Advertisement
Sign in to follow this  

Target pointers for off-screen objects

This topic is 1978 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a top down game where things sometimes go off the screen and you want to know where they are to go get them. I want markers on the edge of the screen to show where the target item is. I have tried a couple different strategies and none of them seem to be working. Here is my current one in case that helps.


Vector2 screenRatio = new Vector2(camera.Width, camera.Height);
                        Vector2 distance = snakePellets.worldPosition - snake.Head.worldPosition;
                        if (distance.X / distance.Y > (float)camera.Width / (float)camera.Height)
                            snakePellets.worldPosition.X = distance.X < 0 ? camera.position.X + 20 : camera.position.X + camera.Width - 20;
                            snakePellets.worldPosition.Y = MathHelper.Lerp(camera.Height / 2, camera.position.Y + camera.Height - 20, distance.Y / screenRatio.Y);

                            snakePellets.worldPosition.X = MathHelper.Lerp(camera.Width / 2, camera.position.X + camera.Width - 20, distance.X / screenRatio.X);
                            snakePellets.worldPosition.Y = distance.Y < 0 ? camera.position.Y + 20 : camera.position.Y + camera.Height - 20;

                        camera.draw(spriteBatch, snakePellets);
                        snakePellets.worldPosition = oldPos;

Using c#/xna. The snakePellets is the item I want to make a pointer to. I am currently just moving it to where I want the pointer to be, drawing it, then moving it back. This is all assuming the snake pellet is off the screen.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!