1
Graphics / How can i propper rezise my Background Image
« on: July 15, 2014, 07:47:51 am »
Good Morning Guy's,
i have a Problem i try to set my Background Image exactly too my Window Resolultion.
My Image Size is 1920,1080:
If i run the Game with a Desktop Resolution 1920,1080 everything is perfectly centered.
If i run now the Game with a Desktop Resolution 1600,900 the Image is always off and not centered i did try Transform, Scale everything i dont get centered im sure i do something wrong but it would be nice if you could give me a hint. (BTW. I use SFML.NET)
Thanks in Advance
Dolphin
i have a Problem i try to set my Background Image exactly too my Window Resolultion.
My Image Size is 1920,1080:
If i run the Game with a Desktop Resolution 1920,1080 everything is perfectly centered.
If i run now the Game with a Desktop Resolution 1600,900 the Image is always off and not centered i did try Transform, Scale everything i dont get centered im sure i do something wrong but it would be nice if you could give me a hint. (BTW. I use SFML.NET)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using SFML.Window;
using SFML.Graphics;
using SFML.Audio;
namespace BushRaider64
{
class BushRaider
{
//ScreenManager und Render Window
private ScreenManager screenManager;
public RenderWindow renderWindow;
private Sprite background;
private SpriteFactory spriteFactory;
//Camera
View view;
//GameTime
private const double frames = 60;
private const double timeStep = 1 / frames;
private double timeBank;
private Stopwatch timer;
private TimeSpan deltaTime;
public BushRaider()
{
//Window Initialisieren
VideoMode video = new VideoMode();
video = VideoMode.DesktopMode;
//Debug Code
foreach(VideoMode item in VideoMode.FullscreenModes)
{
Console.WriteLine(item.Width + " + " + item.Height + " + " + item.BitsPerPixel);
}
Console.WriteLine(VideoMode.DesktopMode.Width + " + " + VideoMode.DesktopMode.Height );
renderWindow = new RenderWindow(video, "BushRaider",Styles.Default);
renderWindow.SetVisible(true);
renderWindow.SetVerticalSyncEnabled(true);
renderWindow.Closed += new EventHandler(onClosed);
//Test Sprite
spriteFactory = new SpriteFactory();
background = spriteFactory.createSprite(new IntRect(0, 0, (int)video.Width, (int)video.Height), "GameAssets/logo.png");
//GameTime Initialisieren
timer = new Stopwatch();
deltaTime = new TimeSpan();
timer.Start();
//Camera
view = new View(new FloatRect(0, 0, VideoMode.DesktopMode.Width, VideoMode.DesktopMode.Height));
renderWindow.SetView(view);
this.Update();
}
public void Update()
{
while(renderWindow.IsOpen())
{
timeBank += deltaTime.TotalSeconds;
if (timeBank >= timeStep)
{
timeBank -= timeStep;
}
renderWindow.DispatchEvents();
this.Draw();
renderWindow.Display();
deltaTime = timer.Elapsed;
timer.Restart();
}
}
public void Draw()
{
renderWindow.Clear(Color.Blue);
renderWindow.Draw(background);
}
public void onClosed(Object sender, EventArgs e)
{
renderWindow.Close();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using SFML.Window;
using SFML.Graphics;
using SFML.Audio;
namespace BushRaider64
{
class BushRaider
{
//ScreenManager und Render Window
private ScreenManager screenManager;
public RenderWindow renderWindow;
private Sprite background;
private SpriteFactory spriteFactory;
//Camera
View view;
//GameTime
private const double frames = 60;
private const double timeStep = 1 / frames;
private double timeBank;
private Stopwatch timer;
private TimeSpan deltaTime;
public BushRaider()
{
//Window Initialisieren
VideoMode video = new VideoMode();
video = VideoMode.DesktopMode;
//Debug Code
foreach(VideoMode item in VideoMode.FullscreenModes)
{
Console.WriteLine(item.Width + " + " + item.Height + " + " + item.BitsPerPixel);
}
Console.WriteLine(VideoMode.DesktopMode.Width + " + " + VideoMode.DesktopMode.Height );
renderWindow = new RenderWindow(video, "BushRaider",Styles.Default);
renderWindow.SetVisible(true);
renderWindow.SetVerticalSyncEnabled(true);
renderWindow.Closed += new EventHandler(onClosed);
//Test Sprite
spriteFactory = new SpriteFactory();
background = spriteFactory.createSprite(new IntRect(0, 0, (int)video.Width, (int)video.Height), "GameAssets/logo.png");
//GameTime Initialisieren
timer = new Stopwatch();
deltaTime = new TimeSpan();
timer.Start();
//Camera
view = new View(new FloatRect(0, 0, VideoMode.DesktopMode.Width, VideoMode.DesktopMode.Height));
renderWindow.SetView(view);
this.Update();
}
public void Update()
{
while(renderWindow.IsOpen())
{
timeBank += deltaTime.TotalSeconds;
if (timeBank >= timeStep)
{
timeBank -= timeStep;
}
renderWindow.DispatchEvents();
this.Draw();
renderWindow.Display();
deltaTime = timer.Elapsed;
timer.Restart();
}
}
public void Draw()
{
renderWindow.Clear(Color.Blue);
renderWindow.Draw(background);
}
public void onClosed(Object sender, EventArgs e)
{
renderWindow.Close();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SFML.Window;
using SFML.Graphics;
using SFML.Audio;
namespace BushRaider64
{
class SpriteFactory
{
public Sprite createSprite(IntRect rectangle, string fileName)
{
Texture texture = new Texture(fileName, rectangle);
return new Sprite(texture, rectangle);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SFML.Window;
using SFML.Graphics;
using SFML.Audio;
namespace BushRaider64
{
class SpriteFactory
{
public Sprite createSprite(IntRect rectangle, string fileName)
{
Texture texture = new Texture(fileName, rectangle);
return new Sprite(texture, rectangle);
}
}
}
Thanks in Advance
Dolphin