Skip to content

Simple implementation of object pooling for Corona.

License

Notifications You must be signed in to change notification settings

ldurniat/Object-Pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Object-Pool

Object-Pool is simple module for Corona for reusing objects instead of creating new ones. It is inspired by GBC Object Pool module by John Schumacher.

Example

local objectpool = require 'pl.ldurniat.objectpool.objectpool'

local i = 0

-- Create new Text Object 
local function createObject()

	i = i + 1
	return display.newText( i, 0, 0, 40, 20, native.systemFont, 20 )

end		

-- Create pool with Text Objects
local textPool = objectpool.init( createObject, 30 )

local function addTextObject()

	-- Get Text Object from pool
	local text = textPool.get()

	-- We need check get object or nil
	if text then

		transition.to( text, 
			{ 	
				x=math.random( display.contentWidth ), 
				y=math.random( display.contentHeight ), 
				-- We don't need object more
				onComplete=textPool.put
			}
		)

	end	

end	

timer.performWithDelay( 50, addTextObject, 0 )

Also see Simple-Particle-System.

Run

To run code you need install Corona SDK

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

Simple implementation of object pooling for Corona.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages