3 Replies - 2353 Views - Last Post: 29 September 2012 - 08:30 AM Rate Topic: -----

#1 LacksdaSkillz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 27-September 12

2D Camera with Panel and GDI+

Posted 27 September 2012 - 10:11 PM

OK here is every detail.

You have a form. Its lets say 600 pixels long.

You want the player to only see 200 pixels long of it. So thats what my panel is. Its the bounds in which the player can see. The form is resized to be around the panel. Now. When the player moves to the right the panel moves to the right and vice versa. So its like a camera in a way. For example. If I have a large scene. I dont want the player to see everything. I want when they move right the camera moves with them so they can see whats off the screen. So heres some more pictorial examples:

I just photoshopped this so I am trying to get the same effect in program that wherever the panel is I only see whats in those bounds.

Posted Image

Is This A Good Question/Topic? 0
  • +

Replies To: 2D Camera with Panel and GDI+

#2 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: 2D Camera with Panel and GDI+

Posted 28 September 2012 - 03:41 PM

Not sure about GDI. I've never done anything with it. However, if you can use panels and PictureBoxes, here's some code for you.

First, place a Panel on a form. Make it the size you want the user to see.
Place a PictureBox into the frame, lining it up with the top-left of the panel. Set SizeMode to AutoSize. Place your Image into the PictureBox.

Place the following into the form code:
    Dim MoveIncrement As Integer = 10

    Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        Select Case e.KeyCode
            Case Keys.Right
                If PictureBox1.Right > Panel1.Right + MoveIncrement Then
                    PictureBox1.Left = PictureBox1.Left - MoveIncrement
                End If
            Case Keys.Left
                If PictureBox1.Left < Panel1.Left - MoveIncrement Then
                    PictureBox1.Left = PictureBox1.Left + MoveIncrement
                End If
            Case Keys.Up
                If PictureBox1.Top < Panel1.Top - MoveIncrement Then
                    PictureBox1.Top = PictureBox1.Top + MoveIncrement
                End If
            Case Keys.Down
                If PictureBox1.Bottom > Panel1.Bottom + MoveIncrement Then
                    PictureBox1.Top = PictureBox1.Top - MoveIncrement
                End If
        End Select
    End Sub



Use the cursor keys to navigate around the picture. The reasom this works is that the PictureBox is in a panel, any any pat of it that is outside the bounds of the panel is not visible.
Was This Post Helpful? 0
  • +
  • -

#3 LacksdaSkillz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 27-September 12

Re: 2D Camera with Panel and GDI+

Posted 29 September 2012 - 02:31 AM

I don't think you understood what I wanted. I understand what you were saying but look. I want the panel to be a viewport. I found out a way to do it with hidden scrollbars so as your player moves forward the form moves to the right and when it goes back it moves to the left. I don't want to control my character I want the panel to be a viewport so I can see whats within it only and when i move my player the world moves with it.
Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: 2D Camera with Panel and GDI+

Posted 29 September 2012 - 08:30 AM

View PostLacksdaSkillz, on 29 September 2012 - 02:31 AM, said:

I don't think you understood what I wanted. I understand what you were saying but look. I want the panel to be a viewport. I found out a way to do it with hidden scrollbars so as your player moves forward the form moves to the right and when it goes back it moves to the left. I don't want to control my character I want the panel to be a viewport so I can see whats within it only and when i move my player the world moves with it.

The example I posted was not intended to be anything other than a technique to look at part of an image, capable of being moved around so you could navigate to different parts of the larger picture. The way I caused it to happen was with the cursor controls, but that was only so you could see the result. There are manyways to do it.

I am certainly not going to write your program for you, and I'm sorry if you felt this was not helpful.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1