469,167 Members | 1,234 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,167 developers. It's quick & easy.

when scrolling a form vertically the "y" coords of a picturebox are reset!

Hi,

I am writing a small game that is using a form 800 * 600. The form
can be scrolled vertically up to a height of 1200 (basically the form
can be scrolled down one screen vertically).

The user controls a picturebox (my sprite) with the cursor keys

When the sprite hits the y value of 600 the screen scrolls down to
display the bottom part of the screen (by focusing on a hidden
picturebox at (0,1200).

This works fine and the sprite is displayed at the top the scrolled
down form.

However the "y" coordinate of the picturebox is now 1 instead of 601.
It appears as soon as the form is scrolled the x,y cordinates become
relative rather than absolute. So that even though we are at position
y=601 because we are at the top of the (scrolled down) form it think
we are at position 1.

Of course this is causing havoc with my collision routine as the
sprite keeps bumping into objects from the top part of the form even
though it is on the bottom part of the form!!!

Does anyone have a solution for this?

p.s. I've tried adding 600 to the "y" value when we first scroll the
form, but this just then moves the sprite to the bottom of the
scrolled down form. I also noticed if you don't scroll the form but
continue to move the sprite down the way then the "y" value keeps it's
absolute value.

Regards,

Scott M.
Jul 17 '05 #1
1 2283
The 'trick' is to use two picture boxes. One acts as the 'viewport', and
its maximum size is the size of the form. The other is contained inside the
'viewport' pixbox and is how ever large you want - it can be thousands of
pixels. Then, you 'move' the inner picturebox inside the 'viewport' opening
to reveal the various portions of your larger canvas. Go to
search.microsoft.com and search the vb knowledge base for the term
"scrollable viewport".

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Scott M" <sc**********@tiscali.co.uk> wrote in message
news:ea**************************@posting.google.c om...
: Hi,
:
: I am writing a small game that is using a form 800 * 600. The form
: can be scrolled vertically up to a height of 1200 (basically the form
: can be scrolled down one screen vertically).
:
: The user controls a picturebox (my sprite) with the cursor keys
:
: When the sprite hits the y value of 600 the screen scrolls down to
: display the bottom part of the screen (by focusing on a hidden
: picturebox at (0,1200).
:
: This works fine and the sprite is displayed at the top the scrolled
: down form.
:
: However the "y" coordinate of the picturebox is now 1 instead of 601.
: It appears as soon as the form is scrolled the x,y cordinates become
: relative rather than absolute. So that even though we are at position
: y=601 because we are at the top of the (scrolled down) form it think
: we are at position 1.
:
: Of course this is causing havoc with my collision routine as the
: sprite keeps bumping into objects from the top part of the form even
: though it is on the bottom part of the form!!!
:
: Does anyone have a solution for this?
:
: p.s. I've tried adding 600 to the "y" value when we first scroll the
: form, but this just then moves the sprite to the bottom of the
: scrolled down form. I also noticed if you don't scroll the form but
: continue to move the sprite down the way then the "y" value keeps it's
: absolute value.
:
: Regards,
:
: Scott M.

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by Mr.Clean | last post: by
1 post views Thread by Kenneth Keeley | last post: by
9 posts views Thread by Dan | last post: by
2 posts views Thread by Jerry Spence1 | last post: by
2 posts views Thread by Roger Withnell | last post: by
38 posts views Thread by Sanders Kaufman | last post: by
1 post views Thread by apking | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.