Advertisement Jump to content
Sign in to follow this  

Help with draw loop and Lua (Luabridge)

This topic is 921 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey :)

I'm currently stuck on some issue and don't know how to fix it.

I started working on a simple 2D engine using SFML for rendering stuff and Lua as my scripting language.
The engine starts with a splash screen first before Lua code is loaded ...

My problem is I don't know how to write a "good" draw loop for my Lua objects.
Maybe you'll understand when we take a look on my code:



int draw_stuff()
	sf::RenderWindow window(sf::VideoMode(640, 480), TITLE);

	while (window.isOpen()) {

		sf::Event event;
		while (window.pollEvent(event))
			if (event.type == sf::Event::Closed)

	        window.draw(splash_screen); // splash screen before Lua script is loaded

		for (sf::CircleShape obj : CircleDrawList) {



	return 0;

My CircleShape wrapper class for Lua:


extern std::list<sf::CircleShape> CircleDrawList;

class Circle



	void draw();

	sf::CircleShape circleShape;



std::list<sf::CircleShape> CircleDrawList;


void Circle::draw()
	//std::cout << "DRAW IN LIST" << std::endl;

	//if (drawableList.size() == 4)


int luaopen_shapes(lua_State *L)
		.addConstructor <void(*) (void)>()
                 ... "other stuff to register" ...

		.addFunction("draw", &Circle::draw)

	return 1;

and finally (if needed) my lua script:

local ball = Circle()

while true do



Result when the Lua Circle is moving by increasing one of the Vector2 values:


Hope you can help and I described it good :x

Thanks :)


Share this post

Link to post
Share on other sites

for (sf::CircleShape obj : CircleDrawList) { window.draw(CircleDrawList.front()); }
Can't say I understand what you're trying to do, but why do you iterate over the circle list, and constantly draw the first circle?

Share this post

Link to post
Share on other sites

As I tried to explain. I can't find a better solution for my drawing loop. That's the reason why I made this topic ;) 

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!