Yeah, I would rather make my own tools than use someone elses, I actually have used and bought every single 2d game editor/maker out there and they all do not stack up to what I want so I just decided to build my own. But anyways here's some code
I also attached the tiles i used as well.
#include <SFML/Graphics.hpp>
#include <iostream>
#include <list>
using namespace std;
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Tile Editor");
sf::Event event;
sf::Mouse mouse;
sf::View scrollScreen;
list<sf::Sprite> setTile;
list<sf::Sprite>::iterator iter;
scrollScreen.reset(sf::FloatRect(0, 0, window.getSize().x, window.getSize().y));
scrollScreen.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f));
while(window.isOpen())
{
while(window.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
{
window.close();
}break;
case sf::Event::Resized:
{
sf::FloatRect viewArea(0, 0, event.size.width, event.size.height);
window.setView(sf::View(viewArea));
}
}
}
window.clear(sf::Color::White);
sf::Vector2i pixel_pos = sf::Mouse::getPosition(window);
sf::Vector2f coord_pos = window.mapPixelToCoords(pixel_pos);
sf::Texture blankGridTexture;
sf::Sprite blankGridSprite;
if(!blankGridTexture.loadFromFile("Resources/Tiles/Sign.png"))
{
}
blankGridSprite.setTexture(blankGridTexture);
blankGridSprite.setOrigin(16, 16);
//Load Grass
sf::Texture tileTexture;
sf::Sprite tileSprite;
if(!tileTexture.loadFromFile("Resources/Tiles/Grass.png"))
{
}
tileSprite.setTexture(tileTexture);
tileSprite.setOrigin(16, 16);
sf::Vector2f Grid(30, 30);
Grid.x = 30;
Grid.y = 30;
if(sf::Event::KeyPressed)
{
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))
{
scrollScreen.move(-1, 0);
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))
{
scrollScreen.move(1, 0);
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
{
scrollScreen.move(0, -1);
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
{
scrollScreen.move(0, 1);
}
}
//Draw Grid
for(int i = 0; i < Grid.x; i++)
{
for(int j = 0; j < Grid.y; j++)
{
blankGridSprite.setPosition(j * 32, i * 32); // <- this is causing 1 grass tile and 1 sign tile to appear randomly
window.draw(blankGridSprite);
}
}
//Set tiles on grid - setMapTileSprite
if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
//Get Position of the mouse then divide by 32 and round down to integer, then times it by 32 to set grid.
tileSprite.setPosition(rint(coord_pos.x / 32) * 32, rint(coord_pos.y / 32) * 32);
blankGridSprite.setTexture(tileTexture);
}
setTile.push_back(tileSprite);
iter = setTile.begin();
while(iter != setTile.end())
{
window.draw(*iter);
iter++;
}
window.setView(scrollScreen);
window.draw(tileSprite);
window.display();
}
return 0;
}