How to initiate enterFrame?

I’m looking at the API reference, and it only shows you being able to add the enterFrame event listener to the Runtime object.

Can someone please just clarify for me: Is Runtime the only object that sends enterFrame callbacks?

Are there any others that send enterFrame callback, such as display.newGroup or some such?

The reason I ask, is because I can do this with tap and touch eventListeners on a display.newGroup object.

I have a premade group object created via a group.new function and pass parameters to set it up. So you’d have a group.enterFrame (or group:enterFrame?) that can have it’s function set externally via parameters, and then it adds an eventListener to itself if it detects the enterFrame function is not nil.

Am I supposed to have the object add it’s enterFrame function to the Runtime event listeners?

Here is an example of what I would like to have.

function group.new(options) local grp = display.newGroup() grp.enterFrame = options.enterFrame if(grp.enterFrame) then grp:addEventListener("enterFrame", grp) -- Do other things to set up the group return grp end

Hi @danielr0,

The time to use an “enterFrame” Runtime listener is for when, as the name suggests, you need to perform/check some action on every frame of the app’s Runtime.

Can you describe more specifically what your intention is with the “group” example? Do you want to perform some action on the group on each Runtime frame?

Best regards,

Brent

I’m working on a bullet-hell game as a test, and have a scene that contains these groups.

I want certain groups (aka bullets) to have different movement patterns, therefore the need to have custom enterFrame functions defined somewhere, which i’m currently doing in a json file that I can modify post build with different algorithms/formula.

Anyway, I’ve sort of figured it out, and this is what I have working so far.

function group.new(options) local grp = display.newGroup() grp.setEnterFrame(func) grp.enterFrame = func if(grp.enterFrame) then Runtime:addEventListener("enterFrame", grp.enterFrame) end end grp.destroy() if(grp.enterFrame) then Runtime:removeEventListener("enterFrame", grp.enterFrame) end grp.enterFrame = nil end -- Do other things to set up the group return grp end

Now I just have to store a local reference to the bullet after creating it, set the function, and then I can discard the reference and be done with it. The “player” will handle all collision checks by checking the position of these groups that have been inserted into the scene hierarchy, and reference then call their destroy function as appropriate.

Thanks for the reply anyway though.

Hi @danielr0,

The time to use an “enterFrame” Runtime listener is for when, as the name suggests, you need to perform/check some action on every frame of the app’s Runtime.

Can you describe more specifically what your intention is with the “group” example? Do you want to perform some action on the group on each Runtime frame?

Best regards,

Brent

I’m working on a bullet-hell game as a test, and have a scene that contains these groups.

I want certain groups (aka bullets) to have different movement patterns, therefore the need to have custom enterFrame functions defined somewhere, which i’m currently doing in a json file that I can modify post build with different algorithms/formula.

Anyway, I’ve sort of figured it out, and this is what I have working so far.

function group.new(options) local grp = display.newGroup() grp.setEnterFrame(func) grp.enterFrame = func if(grp.enterFrame) then Runtime:addEventListener("enterFrame", grp.enterFrame) end end grp.destroy() if(grp.enterFrame) then Runtime:removeEventListener("enterFrame", grp.enterFrame) end grp.enterFrame = nil end -- Do other things to set up the group return grp end

Now I just have to store a local reference to the bullet after creating it, set the function, and then I can discard the reference and be done with it. The “player” will handle all collision checks by checking the position of these groups that have been inserted into the scene hierarchy, and reference then call their destroy function as appropriate.

Thanks for the reply anyway though.