Jump to content

View more

Image of the Day

#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

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

4: Adsense

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
4 replies to this topic

#1 tommohawkaction   Members   


Posted 26 July 2014 - 05:52 PM

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

#2 superman3275   Members   


Posted 26 July 2014 - 06:31 PM

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 ph34r.png!

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:


or Personal-Message me on here smile.png!

#3 tommohawkaction   Members   


Posted 26 July 2014 - 06:44 PM

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


Edited by tommohawkaction, 26 July 2014 - 06:46 PM.

#4 L. Spiro   Members   


Posted 26 July 2014 - 08:49 PM

#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

#5 DrNicholas   Members   


Posted 26 July 2014 - 11:01 PM

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.

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.