Camera movement

Started by
7 comments, last by quentin21 22 years, 10 months ago
Right,i have worked out what my problem is, I can do the coding if I can think of the solution! Woah! But, I am having troubles with the solution. Heres what I am having troubles with.... I have a 300 * 300 2d tiled world. I have a character that can move about in that world, when the character moves the camera moves, if at the side of the screen the camera will no longer move, and obviously neither does the player. What I want is for the player to be able to move around without the camera scrolling, unless the player moves into the two tiles at the side of the screen in which case the camera position on the world will move.. If the player moves back into the central area they can walk about as normal. Now I have tried to think about how to manage this, but it is avoiding me, in pseudo code, can someone explain to me how I go about this. PS I am using DirectX with visual C++.. SORRY FOR BEING STUPID THANKS-YOU VERY MUCH FOR ANY HELP!!!!!!! Q
Advertisement
I'll help you out if I can. Can you clarify how the character and camera should move?

"when the character moves the camera moves"

"What I want is for the player to be able to move around without the camera scrolling"

A contradiction?

Do you mean the player will normally move from tile to tile on the screen (while the camera remains in a fixed position - I'll assume top-down), but when the player reaches the edge of the screen the camera should then move so that the player can see which tiles he is occupying (those previously outside the camera's field of view)?

Paulcoz.

Edited by - paulcoz on June 13, 2001 12:29:08 AM
I want the camera to move only when the player is to the edge of the screen. If the player moves back into the centre area the screen should stop moving and the player should be able to wander around in this area. Sorry for the confusion!
This is still very unclear. Generally, on these types of games, the camera is centered on the character. Whenever the character move, the camera moves with him. When the player reaches one edge of the map, the camera should -stop- moving, otherwise there would be plenty of blank pixels on the border of the screen.
Now, when not near the edge, if the character moves, and the camera stands still, he will go past the screen, and you''ll not be able to see him anymore. Weird.

Please, clarify what you said.

Gaiomard Dragon
-===(UDIC)===-
Gaiomard Dragon-===(UDIC)===-
Again I apologise, i am unsure really how to approach this, so anyone who can tell me the best way of doing this, I am going to listen to. I suppose a fixed camera on the players head would work fine, could you describe to me how I go about this? Thank-you for your help and your time.

Q
It seems that you are using the same variable for camera location and player location. quite simply - don't. A seperate set of x,y variables for player location and camera location will help immensely - if that's not what your doing already. Ex: - Say your camera only displays ten tiles to the right and left of your character. (Clarification - there are 10 tiles being diplayed to the right of the character.) When he gets to tile 290 (300-10) a simple if statement should check and stop moving the camera with the character about that axis. when he crosses back across the 290 threshold start moving the camera again.

It's a sounds more complicated than it really is, but it is essentially an easy problem (I dealt with it years ago too)

Use the WriteCoolGame() function
Works every time

Edited by - Agincourt on June 14, 2001 8:02:47 PM
Use the WriteCoolGame() functionWorks every time
so i postition my player in the centre of the screen at the beginning of the program, if I start in the top left corner of the map and then choose to move left, what do I check? I currently have camera defined as:

typedef struct tcamera
{
int x;
int y;
}tcamera;

the x,y relate to tiles rather than screen coords, and the camera is relative to top left hand corner, am i approaching this the correct way?

Q
quentin21,

If you want to have the UI the way you say, then you need to keep track of two things:

(1) which tiles (in the 300*300 grid) are on the screen at the current time. This could be accomplished by checking which tile or intersection of four tiles in the 300*300 grid the camera is above (assuming top-down) and calculating those surrounding the camera. eg. you need a variable for the tile no. the camera is looking at, or the tile intersection it is looking at. (I mention the tile intersection because that makes for an even number of tiles on screen in each direction from the screen centre)

(2) By checking the player's position on the screen grid only (what the camera can see) you could easily determine when the player is at the edge of the screen, and thus when you need to shift the camera's location to the left, right, up or down, depending on the edge of the screen you are on. Of course, you need to check that the camera's field of view would not go outside the 300*300 grid, but that's fairly simple - you could always have a variable for the no. of tiles that the camera can see on the screen at one time (that would also allow you to scale the size of the graphics on screen to your liking).

Do you understand? You could do it the other way as well so that the player is always in the centre of the screen. That's actually simpler, but could do it either way.

Paulcoz.



Edited by - paulcoz on June 14, 2001 8:24:34 PM
Thank-you all for your replies, PaulCoz, your reply is more helpful, you understood what I meant. I think I do want to acheive the scrolling when at the edge of the screen and think I know exactly what you mean.. Anyway, I will have to try it, see how far I get. If i didn''t fully understand I can always come back in here and find helpful people such as yourselves.

Cheers for the assistance people, much appreciated!

Q

This topic is closed to new replies.

Advertisement