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

Author Topic: 2D World Questions  (Read 1826 times)

0 Members and 2 Guests are viewing this topic.

Stock

  • Newbie
  • *
  • Posts: 11
    • View Profile
2D World Questions
« on: June 02, 2014, 04:52:52 pm »
I am a bit confused on how the 2D world loading works...

I have seen a few topics and even some of the documentation kind of points towards the fact that you can load stuff off screen and have the character move around in the world and the view will uncover more of the world; however, when I try to load a sf::Sprite with a map texture, it only covers a corner of the screen.

As I was reading through the Documentation, about views, I noticed it said something about the 2D world, and that the view can move around it, but I don't really understand how to render the "World" do you do that with a texture and sprite or something? Is there a Doc about it someone can point me to?

Additional (Probably useless) info:
    I did create a Tile Map, I get how to do stuff like that, I just don't under stand how I create a Tile Map or something and have it be larger than the screen and the player can move around... I hope any of this makes any sense at all.

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: 2D World Questions
« Reply #1 on: June 02, 2014, 06:13:39 pm »
Well if you made tilemap, just increase its X and Y sizes, meaning you add more tiles per row and column and you get bigger map.
The view is pretty complicated for starters to get i agree, i had problems myself, but if you read the tutorial on how to use it and read thru the documentation you will figure it out easily.

What you probably want to make is a static position tilemap meaning it doesn't actually move. You want to move view around, something you probably know as camera.

To sumarize the game loop:
if User holds D, move units x position 10 pixels to right.
if User holds A...
CameraView.setCenter(Unit);

RenderWindow.setView(CameraView);//After this call, everything will be drawn with offsets of the view, you dont really to know those. meaning view left up corner can be x=213,y=512 that means if unit is at x=300,y=700 it will be on screen shown at x=87,y=188 if drawn with this view set on
Draw map;
Draw Units;
RenderWindow.setView(renderWindow.getDefaultView());//If you want to draw interface, set view to default so left up corner is x=0,y=0
Draw Interface;
//If you draw unit now, and its at x=300,y=700, depending on you screen size it will probably be off screen and not visible
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: 2D World Questions
« Reply #2 on: June 02, 2014, 06:24:12 pm »
Imagine your world is a large drawing. (it is anything you draw. (shapes, sprites, texts, etc.))
Take a piece of paper, cut the inside out so it makes a hollow rectangle. Imagine you can only see what's inside the hollow rectangle. That's your view.
Take that rectangle and put it on your drawing, you'll see only a part of the drawing. But you can move it around to see other part of the drawing.

Basically, that's what a view does.
« Last Edit: June 02, 2014, 06:26:53 pm by G. »

Stock

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: 2D World Questions
« Reply #3 on: June 02, 2014, 11:19:15 pm »
BaneTrapper, Thank you very much, that is almost perfect for an explanation! It makes sense now that if I made more tiles then the map would fill the screen and more, for some reason that never crossed my mind though.

G., Thank you too! That visual is actually really helpful.