1
Graphics / Layers and camera
« on: January 19, 2016, 10:29:16 am »
Hello.
I'm using .Net version of SFML, but it doesnt matter, right?)
So, here is what i did:
And usage:
Sorry for lot of code, but its not hard to understand whats going on here.
I want to scroll a specific layers, but others should stay at (0, 0). I also want to emlement paralax effect to some layers, but first of all i need to know: is this method OK or is it realy bad and there is a better way to do all that stuff?
P.S. Sorry for bad english.
I'm using .Net version of SFML, but it doesnt matter, right?)
So, here is what i did:
(click to show/hide)
(click to show/hide)
(click to show/hide)
And usage:
//creating window, sprites and etc.
layers = new LayersHandler(window.GetView());
// creating 2 layers
layers.AddLayers("bottom", "mid", "UI");
// adding drawable objects
layers.AddToLayer("bottom", sprite);
layers.AddToLayer("bottom", shape);
layers.AddToLayer("mid", shape2);
layers.AddToLayer("UI", TextField);
cam = new Camera();
// Camera will scroll layer "bottom" and "mid"
cam.Bind(layers.GetLayer("bottom"));
cam.Bind(layers.GetLayer("mid"));
cam.Follow(shape);
cam.SetBounds(new FloatRect(0, 0, 1920, 1080));
//Game loop
while (window.IsOpen)
{
cam.Update();
window.Clear(Color.White);
window.Draw(layers);
window.Display();
}
layers = new LayersHandler(window.GetView());
// creating 2 layers
layers.AddLayers("bottom", "mid", "UI");
// adding drawable objects
layers.AddToLayer("bottom", sprite);
layers.AddToLayer("bottom", shape);
layers.AddToLayer("mid", shape2);
layers.AddToLayer("UI", TextField);
cam = new Camera();
// Camera will scroll layer "bottom" and "mid"
cam.Bind(layers.GetLayer("bottom"));
cam.Bind(layers.GetLayer("mid"));
cam.Follow(shape);
cam.SetBounds(new FloatRect(0, 0, 1920, 1080));
//Game loop
while (window.IsOpen)
{
cam.Update();
window.Clear(Color.White);
window.Draw(layers);
window.Display();
}
Sorry for lot of code, but its not hard to understand whats going on here.
I want to scroll a specific layers, but others should stay at (0, 0). I also want to emlement paralax effect to some layers, but first of all i need to know: is this method OK or is it realy bad and there is a better way to do all that stuff?
P.S. Sorry for bad english.