Map scrolling and SetOrigin

BlitzMax Forums/BlitzMax Beginners Area/Map scrolling and SetOrigin

blackwater(Posted 2011) [#1]
Hi everyone, I really burned a few brain cells on this one but I just don't get it!

My game screen is 1024x768 with SetOrigin set 0,0

I have a single object at let's say x 300 and y 300

I wrote a tiny bit of code that when the mouse is on the edges of the screen it scrolls the map. So, when I have the mouse on the left hand side, I use the SetOrigin command to subtract a set number from x, so one scroll, X is now at -20 and then the screen gets redrawn. The actual object coordinates aren't changed.

Here is what I don't understand, the object is moving left instead of right! If the x origin is -20, shouldn't the object position move to the right by 20 pixels?

If I keep scrolling, the x origin is -300 but yet the object is drawn right up against the left edge of the screen, which I don't understand because shouldn't it be drawn on the right side of the screen instead?

The point of this is that I only draw what is visible on the screen, based on Origin coordinates relative to object coordinates.

Any anyone shed some light on this for me? Thanks in advance, hopefully I explained it well enough.


Jesse(Posted 2011) [#2]
you need to add 20 so that the the previous origin( 0,0 ) is now at 20,0 and now you can see from -20 to (screeenwidth() -20)

Last edited 2011


Floyd(Posted 2011) [#3]
Here's an earlier discussion: SetOrigin debate, complete with my philosophical ramblings.


Czar Flavius(Posted 2011) [#4]
In this post there is a simple game with scrolling. Press enter to start it.


http://blitzbasic.com/Community/posts.php?topic=90762#1033024


blackwater(Posted 2011) [#5]
Thanks, after reading that thread I have a better understanding of how SetOrigin works. I was convinced I had to be doing something wrong since it was working "backwards"