Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using SFML.System;
- using SFML.Window;
- using SFML.Graphics;
- namespace sfml_dummy
- {
- internal class Program
- {
- private static Image[] images = new Image[6];
- private static int delta_frames = 0;
- private static int current_image;
- private static RenderWindow rw;
- static void Main(string[] args)
- {
- rw = new RenderWindow(new VideoMode(800, 600), "SFML Loading Screen");
- images[0] = new Image("1.png");
- images[1] = new Image("2.png");
- images[2] = new Image("3.png");
- images[3] = new Image("4.png");
- images[4] = new Image("5.png");
- images[5] = new Image("6.png");
- rw.Closed += (e, a) => rw.Close();
- rw.SetFramerateLimit(60);
- rw.Resized += Rw_Resized;
- while (rw.IsOpen)
- {
- delta_frames++;
- if (delta_frames == 60) delta_frames = 0;
- if (delta_frames == 0) current_image = new Random().Next(5);
- rw.DispatchEvents();
- rw.Clear();
- //rw.Draw(new Sprite(new Texture(images[current_image])));
- rw.Draw(new RectangleShape(new Vector2f(100, 100)) { Position = new Vector2f(800/2-50, 600/2-50)});
- rw.Display();
- }
- }
- private static void Rw_Resized(object o, SizeEventArgs a)
- {
- View v = rw.GetView();
- rw.SetView(GetLetterboxView(v, 800, 600));
- }
- public static View GetLetterboxView(View view, int windowWidth, int windowHeight)
- {
- // Compares the aspect ratio of the window to the aspect ratio of the view,
- // and sets the view's viewport accordingly in order to achieve a letterbox effect.
- // A new view (with a new viewport set) is returned.
- float windowRatio = (float)windowWidth / windowHeight;
- float viewRatio = view.Size.X / view.Size.Y;
- float sizeX = 1;
- float sizeY = 1;
- float posX = 0;
- float posY = 0;
- bool horizontalSpacing = true;
- if (windowRatio < viewRatio)
- horizontalSpacing = false;
- // If horizontalSpacing is true, the black bars will appear on the left and right side.
- // Otherwise, the black bars will appear on the top and bottom.
- if (horizontalSpacing)
- {
- sizeX = viewRatio / windowRatio;
- posX = (1 - sizeX) / 2f;
- }
- else
- {
- sizeY = windowRatio / viewRatio;
- posY = (1 - sizeY) / 2f;
- }
- view.Viewport = new FloatRect(posX, posY, sizeX, sizeY);
- return view;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement