Clackdor Posted March 4, 2012 Share Posted March 4, 2012 And how can they help me? This is a completely foreign concept to me where entities can perform functions. Sorry for the broad question. Quote Link to comment Share on other sites More sharing options...
Rick Posted March 4, 2012 Share Posted March 4, 2012 Callbacks are functions that you define (but the engine tells you the prototype for) and the engine calls. For example, collision. I would have assumed you were using physics collision for picking up coins but maybe not given your question. In LE you can define a collision callback function and when 2 physics bodies collide the function will get called. Note that it'll be a repeated call until they don't collide anymore. The function parameters are filled in by the engine itself so you can work with the data. In the collision method it tells you the 2 entities that collided, and other information about the collision. http://www.leadwerks.com/wiki/index.php?title=Entities#Callback_Functions The crappy part about how LE does it's callbacks is that it's C oriented so if you are using C++ and heavy OO design, you most likely have to do some extra work to make a normal C function work for your design (Unless you are using EntityKeys for everything which I doubt). For the collision callback using C++ I often will use SetEntityUserData() inside the class that stores my object, say a GameObject, and assign the model a 'this' pointer. I then define a OnCollision() member function in my GameObject class. Now inside the global Collision callback I can call GetEntityUserData() on the LE entity, cast it to GameObject, check that the cast worked, and call it's virtual OnCollide. Anyway that might be when you get into it more Quote Link to comment Share on other sites More sharing options...
Clackdor Posted March 4, 2012 Author Share Posted March 4, 2012 For the coins, it is a simple distance calculation, so it is polled every single update. I recognize that callbacks can help my optimization and allow for some other really neat stuff. I totally forgot about looking in the Wiki. I didn't realize there were examples there. I like your method of assigning the this pointer. I'm going to have to play around with that. I'm specifically looking for how to ENTITYCALLBACK_DRAW so I can skip animation if the entity is not on screen. It's one of the things Josh recommended to me in a status last week. Quote Link to comment Share on other sites More sharing options...
paramecij Posted March 4, 2012 Share Posted March 4, 2012 It's not entities themselves performing fuctions, think of it more like: instead of your code calling engine fuctions, the engine code is calling your functions BTW Anyone know what's the story with ENTITYCALLBACK_DRAW today, is it finally working in c too ?. ..and why is there still no documentation on it ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.