Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Target pointers for off-screen objects

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
No replies to this topic

#1 viper110110   Members   

1111
Like
0Likes
Like

Posted 26 April 2013 - 11:22 AM

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);
                        screenRatio.Normalize();
                        Vector2 distance = snakePellets[i].worldPosition - snake.Head.worldPosition;
                        distance.Normalize();
                        if (distance.X / distance.Y > (float)camera.Width / (float)camera.Height)
                        {
                            snakePellets[i].worldPosition.X = distance.X < 0 ? camera.position.X + 20 : camera.position.X + camera.Width - 20;
                            snakePellets[i].worldPosition.Y = MathHelper.Lerp(camera.Height / 2, camera.position.Y + camera.Height - 20, distance.Y / screenRatio.Y);
                        }
                        else
                        {

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

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

Using c#/xna. The snakePellets[i] 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.






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.