Top cam pan

Blitz3D Forums/Blitz3D Programming/Top cam pan

mintybreath(Posted 2007) [#1]
I was wondering about somthing. I am making a 2d side scroller game, that plays it from the top view. Now i am more used to 3d coding, so i am not so sure about this one. I want to make it so the camera centers on the player, and moves with him, keeping him centered on the screen, but allowing him to move to the areas on the map that arent shown on screen.
I was wondering, since their seems to be no real camera with 2d games, is this possible?

It did occur to me to make it so the player doesnt move, he just moves the background, all the enemies, and all other images. If there is not way, then i will just do this, i guess i am just posting this to see if that would be the most effective way.

If anyone knows a better way, please feel free to post it.

( and on a side note, could chroma please post the bare necesities to that code he gave me in the bullet direction thread, there was an error when i tried to run it.)

Thanks.

-Kevin


Damien Sturdy(Posted 2007) [#2]
have a drawing offset,

camerax=playerx-(screenwidth/2)
cameray=playery-(screenheight/2)

OK, so now with every DRAW command, you remoce CameraX and CameraY from the coordinates,


DrawImage Playerimage,playerx-CameraX,playery-Cameray


And this draws the player centre screen. you can point the camera anywhere by adjusting camerax,cameray :)

Also, as a side note, you should avoid drawing parts of the level that are off the screen.


mintybreath(Posted 2007) [#3]
Well what you said does help, but i am not so sure if i did it right. It centers the image on the screen, but the image doesnt move any way i tried to do it following you directions.
Maybe you could take a look at the section of code where i inputed what you gave me. There could be some small thing wrong that i didnt do or something...

Here it is:

;Controls
Function Controls()

camerax=player\x -(800/2)
cameray=player\y -(600/2)

DrawImage playerimage,player\x-camerax,player\y-cameray
DrawImage aimimage,MouseX(), MouseY()
HidePointer 

If KeyDown(rightkey)
	player\x = player\x - humanspeed
	playerimage=LoadImage("player Right.png")
	MaskImage playerimage,0,255,255
EndIf

If KeyDown(leftkey)
	player\x = player\x - humanspeed
	playerimage=LoadImage("player left.png")
	MaskImage playerimage,0,255,255
EndIf

If KeyDown(downkey)
	player\y = player\y + humanspeed
	playerimage=LoadImage("player down.png")
	MaskImage playerimage,0,255,255
EndIf

If KeyDown(upkey)
	player\y = player\y - humanspeed
	playerimage=LoadImage("player smallest.png")
	MaskImage playerimage,0,255,255
EndIf
	
End Function


And one other thing, as you can see, with each key it changes the whole IMAGE, how do i make an image that has frames. I dont really see how. I would guess it is some sort of file type? or something?
I would want to be able to specify frames in the programming. If anyone knows how to do that that would help. :)


mintybreath(Posted 2007) [#4]
can anyone please help with this?

All i need are the weapons and camera system and then i can continue making my game because i am pretty sure i know how to do the rest.


LarsG(Posted 2007) [#5]
just a hint; you don't have to load the images (or mask them) everytime a keydown is registered...


mintybreath(Posted 2007) [#6]
I think i do, i wouldnt normally, but everytime the left key is pressed, it switches over to the player looking left, and same with all the other directions. I dont think i have to mast though.

I did it that way because i couldnt figure out how to do framed images with Corel Paintshop. If anyone knows how to do that, that would help too.


LarsG(Posted 2007) [#7]
try loading all the player frames into different variables at the start of the program.
You can for example use something like;
Global player_image

Global player_right = LoadImage("right.png")
Maskimage player_right, 0,255,255
Global player_left = LoadImage("left.png")
Maskimage player_left, 0,255,255
Global player_up = LoadImage("up.png")
Maskimage player_up, 0,255,255
Global player_down = LoadImage("down.png")
Maskimage player_down, 0,255,255

then when you want to change the player (anim)frame, you can do something like this;
If KeyDown(rightkey) Then player_image = player_right

DrawImage player_image, x, y


note; code is partially pseudo-code.. :)



..OR.. you can put your images into an array, like;
Global player_image[3]
player_image[0] = LoadImage(up)
player_image[1] = LoadImage(down)
etc...