STB libraries » Forums » stb_tilemap_editor.h
nlives
4 posts
#12870 stb_tilemap_editor.h
1 month, 1 week ago

I am trying to use stb_tilemap_editor.h with sfml, And I have a few doubts

1.
1
2
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
     stbte_mouse_button(tilemap, mousePos.x, mousePos.y, 0, 1, 0, 0);

I am using this piece of code for clicking should I write a else condition for unclicking?

2.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
while(window.pollEvent(event)) 
{
  if (event.type == sf::Event::MouseMoved)
  {
	mousePos = sf::Vector2i(event.mouseMove.x, event.mouseMove.y);
	mousePos.x = mousePos.x * (640.0f / window.getSize().x);
	mousePos.y = mousePos.y * (480.0f / window.getSize().y);
	stbte_mouse_move(tilemap, mousePos.x, mousePos.y, 0, 0);
  }
}


because of the while loop the above code becomes laggy, how do i handle this?


If anyone else have integrated this with sfml, please help me figure this out
Thanks.
mmozeiko
Mārtiņš Možeiko
1477 posts
1 project
#12873 stb_tilemap_editor.h
1 month, 1 week ago Edited by Mārtiņš Možeiko on Aug. 15, 2017, 5:23 p.m.

1) Yes, you need to call stbte_mouse_button with 5th argument set to 0 ("false") when mouse button is released.
This is easy to see from SDL example function stb_tilemap_editor have in source code: https://github.com/nothings/stb/b...master/stb_tilemap_editor.h#L4099

2) What is this while loop? Aren't you handling all other events also in this loop? In what place have you put this loop?
nlives
4 posts
#12886 stb_tilemap_editor.h
1 month, 1 week ago

yes, I got it to work, but have to run in release mode. for it to fast, in debug its very slow, I dont know why..
mmozeiko
Mārtiņš Možeiko
1477 posts
1 project
#12887 stb_tilemap_editor.h
1 month, 1 week ago

That's because in "debug" mode typically build system doesn't turn on compiler optimizations to make debugging easier. Without optimizations generated code is slow. That's expected behavior.