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

Author Topic: Change C++ to C# problem  (Read 4155 times)

0 Members and 1 Guest are viewing this topic.

delio

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Change C++ to C# problem
« on: April 02, 2014, 03:42:39 pm »
Code: [Select]
class TileMap : public sf::Drawable, public sf::Transformable
{
public:

bool load(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height)
{

if (!m_tileset.loadFromFile(tileset))
return false;


m_vertices.setPrimitiveType(sf::Quads);
m_vertices.resize(width * height * 4);


for (unsigned int i = 0; i < width; ++i)
for (unsigned int j = 0; j < height; ++j)
{

int tileNumber = tiles[i + j * width];

int tu = tileNumber % (m_tileset.getSize().x / tileSize.x);
int tv = tileNumber / (m_tileset.getSize().x / tileSize.x);


sf::Vertex* quad = &m_vertices[(i + j * width) * 4];

quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);


quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
}

return true;
}

private:

virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
{

states.transform *= getTransform();


states.texture = &m_tileset;


target.draw(m_vertices, states);
}

sf::VertexArray m_vertices;
sf::Texture m_tileset;
};
How can I change it to C# language?
like "sf::RenderWindow" in C++ change to "SFML.Graphics.RenderWindow"
What is a structure? Please guide me.

Thanks
« Last Edit: April 02, 2014, 03:45:37 pm by delio »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Change C++ to C# problem
« Reply #1 on: April 02, 2014, 04:17:45 pm »
Maybe you should learn the C# programming language before porting a project to it ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

delio

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: Change C++ to C# problem
« Reply #2 on: April 02, 2014, 04:30:26 pm »
I'm considering about C++ and C#
C++ -- GUI is too hard for me. but I don't have to change SFML code.
C#   -- GUI is easier but I haven't learn.

Which one is worthy?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Change C++ to C# problem
« Reply #3 on: April 02, 2014, 04:34:48 pm »
If your only argument for C++ is that you can copy&paste code from the tutorials, then... take C#. It's simpler to learn anyway.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

delio

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: Change C++ to C# problem
« Reply #4 on: April 02, 2014, 04:41:01 pm »
OK, Thanks

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: Change C++ to C# problem
« Reply #5 on: April 02, 2014, 08:57:16 pm »
Busy converting some of the C++ examples to C# before I start working on what I'm up to so I might be able to help. :)  Working on the one on the first page after going into the classes list. :)
I have many ideas but need the help of others to find way to make use of them.

delio

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: Change C++ to C# problem
« Reply #6 on: April 03, 2014, 09:11:54 am »
Busy converting some of the C++ examples to C# before I start working on what I'm up to so I might be able to help. :)  Working on the one on the first page after going into the classes list. :)

Thanks but I want to try by myself :)

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: Change C++ to C# problem
« Reply #7 on: April 03, 2014, 08:17:44 pm »
If you haven't found it already here's the Github to the window events.

Very useful.  https://github.com/SFML/SFML.Net/blob/master/src/Window/Window.cs#L554

It should help speed things along. :)
I have many ideas but need the help of others to find way to make use of them.

delio

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: Change C++ to C# problem
« Reply #8 on: April 04, 2014, 08:33:25 am »
If you haven't found it already here's the Github to the window events.

Very useful.  https://github.com/SFML/SFML.Net/blob/master/src/Window/Window.cs#L554

It should help speed things along. :)
Thanks you very much :)