I've started making a DragSelect class (similar to AceSlide but more minimalist). I'm going to use my new, and favourite, CallbackBroadcaster class to trigger callbacks.
To keep things neat DragSelect inherits from Sprite. A class can't inherit from two classes (I think), so what is the best way to have DragSelect use CallbackBroadcaster? I can think of three options:
1. Create an instance of CallbackBroadcaster and use that. 2. Inject methods into Sprite to send the events, as if Sprite inherited from CallbackBroadcaster. 3. Inherit from CallbackBroadcaster instead of Sprite and manually add the required Sprite functions in DragSelect.
Is there a fourth option? Not keen on the ones above.
5. When you create CallbackBroadcaster, also create a global var called CALLBACKBROADCASTER. When you init DragSelect just cache that with self.CallbackBroadcaster = CALLBACKBROADCASTER.
I assign global vars to pretty much all of my classes. It's so easy to use them in other classes if you stick to a naming system. This is my goto init.lua file..
This way, when called, it increments forever... I'm wondering if there is a way to do this... 'Cause I've tried everything and I am convinced that it is not possible and That I'll have to find another way out
wow this old topic is extremely interesting, thx @Paulo777
Guys, can somebody please share simple example of code with&without callbacks? I just don't understand - what the "callback" actually is? Thanks a lot, guys!
> Newcomers roadmap: from where to start learning Gideros "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
An event is a created object that is passed via the EventDispatcher.
A callback is a pointer to a function. Calling a function directly, rather than doing it via EventDispatcher, is much faster.
In my experience you should only use EventDispatcher if you're not calling it very often. If you need to create an EventDispatcher every frame, for instance, it will slow your game down.
All I needed was to create a function that has the ENTER_FRAME event and call it in the trigger function. Inside the function with ENTER_FRAME event, set boolean to true if collided, down in the if condition that verifies if collided, increment, remove the event listener and set collided to false.
Comments
I've started making a DragSelect class (similar to AceSlide but more minimalist). I'm going to use my new, and favourite, CallbackBroadcaster class to trigger callbacks.
To keep things neat DragSelect inherits from Sprite. A class can't inherit from two classes (I think), so what is the best way to have DragSelect use CallbackBroadcaster? I can think of three options:
1. Create an instance of CallbackBroadcaster and use that.
2. Inject methods into Sprite to send the events, as if Sprite inherited from CallbackBroadcaster.
3. Inherit from CallbackBroadcaster instead of Sprite and manually add the required Sprite functions in DragSelect.
Is there a fourth option? Not keen on the ones above.
But obivously this would waste resources...
Likes: totebo
I assign global vars to pretty much all of my classes. It's so easy to use them in other classes if you stick to a naming system. This is my goto init.lua file..
Likes: totebo
Likes: antix
Is there a way to call
This way, when called, it increments forever... I'm wondering if there is a way to do this... 'Cause I've tried everything and I am convinced that it is not possible and That I'll have to find another way out
Guys, can somebody please share simple example of code with&without callbacks?
I just don't understand - what the "callback" actually is? Thanks a lot, guys!
Likes: Paulo777
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
A callback is a pointer to a function. Calling a function directly, rather than doing it via EventDispatcher, is much faster.
In my experience you should only use EventDispatcher if you're not calling it very often. If you need to create an EventDispatcher every frame, for instance, it will slow your game down.
Likes: Apollo14
Likes: totebo, Apollo14, antix
What I need is to call a function only once, but I have to call it inside a function that works only in an ENTER_FRAME event
What I need is simple, just increment a value ONCE every time a collision happens
What actually goes on is that every collision happens, it starts to increment forever... I just want to STOP IT and increment only once.
Can anybody give some light over it?
Initially my collision condition was inside a eventListener explicit
Inside the function with ENTER_FRAME event, set boolean to true if collided, down in the if condition that verifies if collided, increment, remove the event listener and set collided to false.
Likes: antix, Apollo14