[Game] How do i make a camera.class?

Started by
3 comments, last by NicholasLopez 9 years, 8 months ago

Hello i am making a game like pokemon and im am stuck on how to scroll the map I have used g.translate(offsetX,offsetY); but if i want to add ai's later on to follow the player it would not work well
can someone help me out?

if you can add me on skype : tommohawkaction

I mean a Player camera here is what my game is so far http://www.mediafire.com/download/js5na4pmy6eb8w5/test.jar I have made the map move by g.translate(xpos,ypos); however the player does not physically move what will make it hard to do ai so can you help me out.

I want to make a nice camera for the player thanks

if this doesnt make sense its because i had to qoute it from another website becuase they couldn't help me

Advertisement

We're going to need more information. What API / Framework / Library are you using? How is your code structured (it's hard to just read through all of your source code and understand it. Furthermore, few of us have the time)?

You're going to need to clarify your question if you want robust answers.

I'm a game programmer and computer science ninja !

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here !

here is my code and its made in the pure java library

http://www.mediafire.com/download/46i80dfhdsnj0k4/TileGame.rar

#1: Do not post personal contact details for private help. This is a public site where answers to question are made public so that they can provide help for others with the same problem (and the rare ability to search before asking).

#2: Don’t code-dump. If you need to post any code, post it in the topic and keep it short and straight-to-the-point regarding the problem you have. superman3275 specifically told you that it is hard enough to read through all of the source code and few (none) of us have the time, and then you respond by posting all of your code? Do you read replies?



The answer to your question is really quite trivial—separate logic and rendering.
The game world has a non-changing coordinate system, so all of your concerns about AI etc. are unwarranted.
If the player is at [23,56] and the AI needs to aim at him from [10,78], the logic is the same no matter where the camera is. The world isn’t moving just because the camera is moving.

So you have a static game world full of non-moving coordinates. This is the logic part.


When you want to render, this is a different and completely unrelated step.
When you render an object, you take its world coordinates, convert them to screen coordinates, move to the next object, and repeat.
The converted coordinates exist only during the render. They don’t overwrite world coordinates etc.


So let’s say you have 3 objects:
Aardvark [12,75]
Bicycle [142,22]
SterilFart [0,13]

And the “camera” is at [33,40].

foreach (Object) {
    tempCoords = Object.Pos - Camera.pos;
    Render(Object, tempCoords);
}
Aardvark gets rendered at [-21,35].
Bicycle gets rendered at [109,-18].
SterilFart gets rendered at [-33,-5].


As you can see, there is absolutely nothing here related to AI or game logic of any kind.
Game world is updated by game logic in a coordinate system that never changes.
Objects are rendered with a translation for presenting them to the screen.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Whatever you use, there is no actual camera, rather things are offset by the cameras coordinates. So you have a CameraX and a CameraY, and when you draw something (that is being scrolled around) you do x - CameraX and y - CameraY.

This topic is closed to new replies.

Advertisement