Jump to content

  • Log In with Google      Sign In   
  • Create Account

Camera/screen moving


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Slider_SLO   Members   -  Reputation: 136

Like
0Likes
Like

Posted 25 February 2013 - 08:15 AM

I am having some issues with camera or screen and background animations...

All of the examples i can find are kinda focused that your screen and character is still while the background is actually moving and that gives you impression that you are the one moving.

I would like to script that your background is still and that your screen would be the one moving, like lets say you have dimension of the ''map''

1920 × 1080 and your screen would be 800 x 640.

If you would move the character, camera would be centered on it and he would be constantly changing coordinates while the background coordinates would be always the same...

Is that even possible to do something like that or is it always that your background is moving instead of you?

Tnx for any info if you can help me :P



Sponsor:

#2 Nercury   Crossbones+   -  Reputation: 774

Like
3Likes
Like

Posted 25 February 2013 - 08:29 AM

Your camera is always still: it is your screen. However, nothing prevents you to store camera position however you like. 

 

For example, if your camera's X is 18, just move world into opposite direction: -18.



#3 NightCreature83   Crossbones+   -  Reputation: 3031

Like
2Likes
Like

Posted 25 February 2013 - 09:37 AM

A screen( menu) doesn't need to be attached to a camera and only be rendered in camera space, you can just as well use a 3D screen asset that is positioned in your game world and then use a freefly camera to focus on the object. See the DiRT and GRID series as examples of this type of UI.

 

If you wobble this camera you get the impression the world is moving while in actuality it is the camera that is moving and not the world.

If you aren't tied to any particular tech framework for UI you can write your own one that allows you to do this. There is nothing stopping you from realising this except your time and imagination.


Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, Mad Max

#4 BornToCode   Members   -  Reputation: 948

Like
1Likes
Like

Posted 25 February 2013 - 11:38 AM

If this is for a 2d game, what you can do is attached the camera to the player. As long the player is not in the center of the screen and the level can scrool you move the player. Once you hit the center of the screen you still move the player but also move the camera, but subtracting the camera from the player position so in reality your player is not moving and will remain in the center of the screen while the camera increments. Then what you need to do is subtract from the position of every object by the camera that will simulate the level scrolling while keeping the player in the center. Once you get to the end of level where it can no longer scrool, then you stop incrementing the camera and keep moving the player which will simulate the player moving to the far edge of the screen which means you reach the end of the level.



#5 Slider_SLO   Members   -  Reputation: 136

Like
0Likes
Like

Posted 25 February 2013 - 12:05 PM

But why does images that I blit on the surface lets say an image of another object/player etc... they move with my camera/screen the same way as my player,

 like they are locked on the surface on those coordinates that i blit them? It would be fun if I would be making the HUD, but I dont want that for my objects should I decrement

them in the opposite direction when my player moves?

And yes it is for 2d game,

thanks for all the help


Edited by Slider_SLO, 25 February 2013 - 12:06 PM.


#6 CC Ricers   Members   -  Reputation: 732

Like
2Likes
Like

Posted 25 February 2013 - 12:23 PM

For most 2D games you position all your sprites in screen space. If you want to translate the camera's position to different coordinates, that's fine, but in the end you will have to apply your camera's new position in calculating the final sprite coordinates anyways, because that is how SDL determines where to blit objects onto the screen.

 

Your map may load sprites with storing positions in negative coordinates (if you choose to), but they will be off the screen and not be drawn unless you make the coordinates positive during the rendering step.


Edited by CC Ricers, 25 February 2013 - 01:59 PM.

My development blog: Electronic Meteor

#7 stannic   Members   -  Reputation: 173

Like
2Likes
Like

Posted 25 February 2013 - 01:48 PM

Shouldn't you just displace everything by where you want to look at.

 

So if you want to look at the player just displace everything by the players position.

 

If you are at 200,300

then move the everything by -200,-300

 

So you draw yourself at 0,0

 

If you want 0,0 to be the center then add screenWidth/2 and screenHeight/2



#8 Slider_SLO   Members   -  Reputation: 136

Like
0Likes
Like

Posted 25 February 2013 - 02:20 PM

If I understand you then if I would want to move by one pix like lets say 201,301 then i would need to move all the others objects by one pix and leave my character on 200, 300?

If so then isnt that really inefficient to move the world and all its objects instead of the character?



#9 stannic   Members   -  Reputation: 173

Like
0Likes
Like

Posted 25 February 2013 - 02:41 PM

What I meant by move was that when drawing you displace the objects when drawing.

 

for eg


displace. = playerpos

for all obs

  draw obj at  objpos - displace


Edited by stannic, 25 February 2013 - 02:43 PM.


#10 Dan Mayor   Crossbones+   -  Reputation: 1714

Like
1Likes
Like

Posted 25 February 2013 - 05:04 PM

I believe what everyone is getting at here is that your screen is a little more than a canvas.  It is 0,0 - width,height period.  That never changes, the idea of a camera is completely conceptual and offers a means to calculate the offset of sprites, backgrounds and any other images that you are rendering.  To "move" the camera you have to offset graphics based on the dimensions of the screen.  Eg the screen ALWAYS shows 0,0 - width,height.  Your camera's position can be used to calculate where to render the graphics to make it appear that you are looking at a different part of the scene.


Digivance Game Studios Founder:

Dan Mayor - Dan@Digivance.com
 www.Digivance.com





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS