Panning your view

BlitzMax Forums/BlitzMax Programming/Panning your view

Cruis.In(Posted 2012) [#1]
Hey guys I am working on a 2d top down space game for fun.

My view is centered on the player ship. Drawn at the centre of your resolution.

Using mouseX and MouseY and setorigin, I want to add a panable viewspace.




this works 'okish' Problem is. Just pan your mouse around. FIRST: Pan your mouse arrow to the bottom RIGHT HAND corner. You will notice your 'entity' move to the top left corner.

Now pan your mouse arrow to the top LEFT corner. You will notice the entity stays in the middle and does not move to the bottom right corner, like when you did the above first example.

Since the setorigin is drawing based on the mousex & y. The mouse x and y are at 0 when you are in the top left corner...

So it won't 'draw' your entity any further than the starting middle position (centre of screen)

So you see the issue it creates? I can move the mouse to the bottom of the screen or move the mouse to the right of the screen and get the appropriate movement out of the entity. But moving the cursor to the left of the screen or top of the screen won't work as intended.

Any ideas?

Last edited 2012


Cruis.In(Posted 2012) [#2]
double post

Last edited 2012


Midimaster(Posted 2012) [#3]
You did things twice, but more than this is not necessary:
Strict

Graphics 800,600

Global StarsX%[500], StarsY%[500]

For Local i%=0 To 499
	StarsX[i]=Rand(-1000,1000)
	StarsY[i]=Rand(-1000,1000)
Next

Global newplayer:tplayer = New tplayer


Type TPlayer

	Field X:Float
	Field Y:Float

	
	
	Method Render()
		SetColor(235,110,214)
		SetRotation (0)
		SetAlpha 1.0
		
		
		Local PanX:Float = -MouseX()
		Local panY:Float = -MouseY()
	
		'setting the origin
		SetOrigin GraphicsWidth()/2+PanX,GraphicsHeight()/2+PanY

		For Local i%=0 To 499
			DrawOval StarsX[i],StarsY[i],3,3
		Next
		'the rect
		DrawRect MouseX(),MouseY(), 20,20
	End Method


Last edited 2012


Cruis.In(Posted 2012) [#4]


thanks for the input midimaster. It wasn't quite right, but I had figured it out soon after.

Don't want the player kept in the centre. So when you move the mouse in yours it seems to move the background which is a cool effect. In my case it carries the view towards the mouse pointer.

And it does so equally now without issues for all sides, above and below.


UnderwoodNullium(Posted 2012) [#5]
Here's a 'cam-look' I made from a long time ago. It keeps the camera at a place between the mouse and the cursor, allowing you to look everywhere around you. Its pretty cool.

http://blitzmax.com/codearcs/codearcs.php?code=2382