Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: The Concept of Screen moving [2d camera]  (Read 5437 times)

0 Members and 1 Guest are viewing this topic.

grandmasterhack

  • Newbie
  • *
  • Posts: 14
    • View Profile
The Concept of Screen moving [2d camera]
« on: June 10, 2011, 05:46:27 pm »
Hello, i've been wondering this but i can seem to get a hold of the concept of programming a 2d platformer. jumping and maps dont seem to be the problem its just the screen( or camera) moving i dont understand. can someone break down the theory of this. do i need an offset, becasue i heard one way of doing it is basically the character doesnt move at all but you essentially moving the map itself.
"In Miyamoto We Trust"

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6276
  • Thor Developer
    • View Profile
    • Bromeon
The Concept of Screen moving [2d camera]
« Reply #1 on: June 10, 2011, 05:54:08 pm »
Actually, sf::View does everything you need for a 2D camera. How it works is explained in the tutorials and in the documentation.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

grandmasterhack

  • Newbie
  • *
  • Posts: 14
    • View Profile
The Concept of Screen moving [2d camera]
« Reply #2 on: June 10, 2011, 06:08:08 pm »
Quote from: "Nexus"
Actually, sf::View does everything you need for a 2D camera. How it works is explained in the tutorials and in the documentation.


i've read that but when i do use that how do i detect collision since every thing is off? does it matter? when i wrote my editor i had an offset value that moved the tiles over instead of view.

Code: [Select]
[pseudo code]

if(key_press.RIGHT)
offset_x++;

tile.setpostion(x + offset_x);
"In Miyamoto We Trust"

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6276
  • Thor Developer
    • View Profile
    • Bromeon
The Concept of Screen moving [2d camera]
« Reply #3 on: June 10, 2011, 07:12:30 pm »
Quote from: "grandmasterhack"
i've read that but when i do use that how do i detect collision since every thing is off?
Game logics like collision detection and response are normally independent of the graphical representation (i.e. also of the sf::View).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

grandmasterhack

  • Newbie
  • *
  • Posts: 14
    • View Profile
The Concept of Screen moving [2d camera]
« Reply #4 on: June 10, 2011, 07:45:08 pm »
Quote from: "Nexus"
Quote from: "grandmasterhack"
i've read that but when i do use that how do i detect collision since every thing is off?
Game logics like collision detection and response are normally independent of the graphical representation (i.e. also of the sf::View).


what about zooming in? i know that affected it(but that was in 1.5).
"In Miyamoto We Trust"

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6276
  • Thor Developer
    • View Profile
    • Bromeon
The Concept of Screen moving [2d camera]
« Reply #5 on: June 10, 2011, 07:49:11 pm »
Quote from: "grandmasterhack"
what about zooming in? i know that affected it
Why should zooming in behave different? What does it affect?

I think you haven't understood what I wanted to tell you. I meant that game logics like collision are handled on your own side, while SFML is primarily used to draw the scene. So sf::View just cannot affect the collision detection in any way, because it is computed completely separate from any SFML stuff.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

shiroaisu

  • Newbie
  • *
  • Posts: 28
    • View Profile
The Concept of Screen moving [2d camera]
« Reply #6 on: June 13, 2011, 02:51:09 pm »
Normaly what we do is, dont move the camera nor the player ( in some cases ), move the world instead.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6276
  • Thor Developer
    • View Profile
    • Bromeon
The Concept of Screen moving [2d camera]
« Reply #7 on: June 13, 2011, 03:10:39 pm »
Quote from: "shiroaisu"
Normaly what we do is, dont move the camera nor the player ( in some cases ), move the world instead.
And the advantage over moving the camera is where?

People, don't make stuff more complicated than necessary. sf::View is designed as a 2D camera, so use it ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

shiroaisu

  • Newbie
  • *
  • Posts: 28
    • View Profile
The Concept of Screen moving [2d camera]
« Reply #8 on: June 13, 2011, 03:44:19 pm »
Quote from: "Nexus"
Quote from: "shiroaisu"
Normaly what we do is, dont move the camera nor the player ( in some cases ), move the world instead.
And the advantage over moving the camera is where?

People, don't make stuff more complicated than necessary. sf::View is designed as a 2D camera, so use it ;)


well, yes, if there is a class that makes everything easier go ahead :D, i just said this to sugest other ways of doing it :),

besides i never really messed arround with views much so thats how i do it for now.

Fouf

  • Newbie
  • *
  • Posts: 23
    • View Profile
The Concept of Screen moving [2d camera]
« Reply #9 on: June 16, 2011, 03:38:02 pm »
For my 2d top down tile based game I take the players position, and the camera's center then I subtract the two and I do camera.move * difference * delta time

gives a nice effect and works well!
- Fouf

 

anything