It looks like you're new here. If you want to get involved, click one of these buttons!
ATLAS = RenderTarget.new(2048, 2048)
FONT = Font.new("fonts/Londrina70.fnt", "fonts/Londrina70.png")
AGUI = require("modules/agui")
FILE = File.new()
ACRYPT = SimpleCrypt.new()
PREFS = Prefs.new()
SFX = Sfx.new()
SFX:setMasterVolume((1 / 100) * PREFS.soundVolume)
MUSIC = Music.new()
MUSIC:setVolume((1 / 100) * PREFS.musicVolume)
PLAYER = Player.new()
ENEMYPOOL = EnemyPool.new()
ANIMATOR = Animator.new()
TIMELINE = TimeLine.new()
BUMP = require("modules/bump").newWorld(128)
COLLISIONMAKER = CollisionMaker.new()
PARALLAX = Parallax.new()
LEVELMANAGER = LevelManager.new()
self.value += 1
local function dispatchEvent(e)
for k,f in pairs(EVENTMAP) do
if e.processed then return end
local ok,controller=pcall(function() return require("controller") end)
if ok then
if et==Event.MOUSE_DOWN then
-- Do something
if et==Event.KEY_DOWN then
-- Do something
totebo, Apollo14, antix
self.addEventLinstener(Event.ENTER_FRAME, function (self,
-- code here
if shot:collidesWith(self.ship) then
self.collided = true
self:addEventListener(Event.ENTER_FRAME, self.onDetectCollision, self)
if self.collided then
self.increment += 1
self:removeEventListener(Event.ENTER_FRAME, self.onDetectCollision, self)
self.collided = false
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...
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..
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!
"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: 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