0 Members and 1 Guest are viewing this topic.
using System;using System.Collections.Generic;using System.Linq;using System.Text;using SFML.Graphics;namespace ConsoleApplication1{ class Program { static void Main(string[] args) { using (var rw = new RenderWindow( new SFML.Window.VideoMode(800, 600), ":)")) { var a = new Image("a.bmp"); var atlas = new Image(64, 64, new Color(255, 0, 255, 0)); Copy(atlas, a, 0, 0, new IntRect(0, 0, 32, 32)); Copy(atlas, a, 32, 0, new IntRect(0, 0, 32, 32)); Copy(atlas, a, 0, 32, new IntRect(0, 0, 32, 32)); Copy(atlas, a, 32, 32, new IntRect(0, 0, 32, 32)); var s = new Sprite { Position = new Vector2(0, 0), SubRect = new IntRect(0, 0, 64, 64), BlendMode = BlendMode.None, Color = Color.White, Image = atlas }; rw.Show(true); rw.UseVerticalSync(true); while (rw.IsOpened()) { rw.DispatchEvents(); rw.Clear(); rw.Draw(s); rw.Display(); } } } static void Copy(Image dest, Image src, uint dx, uint dy, IntRect srcRect) { const bool useSFMLCopy = true; if (useSFMLCopy) { dest.Copy(src, dx, dy, srcRect); } else { for (uint x = 0; x < srcRect.Width; x++) { for (uint y = 0; y < srcRect.Height; y++) { dest.SetPixel(dx + x, dy + y, src.GetPixel((uint)srcRect.Left + x, (uint)srcRect.Top + y)); } } } } }}
Do you really need a new IntRect for every copy, especially when they are all the same size?
Also one thing I remember about switching to sfml 2 is that I had to change some of my Image constructors to Image.Create, ie if there was a color.
sf::Image m_img00;m_img00.LoadFromFile("fb00.png");sf::Image c_img00; c_img00.Create(w,h,sf::Color(0,0,0,0));sf::IntRect rct(0,0,0,0);c_img00.Copy(m_img00,0,0,rct,false);
I used Image.Copy() in C++/SFML2 and it worked fine:
This was a bug, it's now fixed.It was tricky: in CSFML, the function is called sfImage_CopyImage instead of sfImage_Copy, because the latter is used for implementing a kind of copy constructor. And SFML.Net was calling the wrong one, sfImage_Copy.QuoteI used Image.Copy() in C++/SFML2 and it worked fine: An old revision maybe?
I assumed it was C++ first and then C for porting to .Net, etc?
An unrelated note, but unless you plan to have a variable change it's type using var will only lead to unneeded overhead due to the way m$ wrote it.