Share Your Code

Data

Sort by: Latest Additions | Most Viewed | Recently Updated | Top Rated

The latest additions of sample code and code libraries shared by developers for Corona SDK.

1 vote
Invert, Horizontal Flip and Vertical Flip Physics Shapes

I recently discovered that is was very easy way to invert images, e.g: myObject.xScale = -1, will horizontally flip a display object. This works well but it will not flip any custom physics shapes assigned to the object so in order for the objects to have the correct physics the shapes need to be flipped also. Here is a function I created which will output a new list of flipped or inverted shapes coordinates from... More...

Posted by Beloudest, Posted on 7 May 2012, Last updated 7 May 2012 | 0 comments

0 votes
Simple Polygon Triangulation

I've been looking for a way to break a simple polygon into component polygons for a while. I won't tell you why because I'm using it in a game, but I just had to share this solution. It takes any clockwise winding polygon (entered by tapping the screen in sequence) and breaks it into it's interior triangles - literally "triangulation." I can't take credit for the math, which was the only complete and understandable... More...

Posted by horacebury, Posted on 4 May 2012, Last updated 4 May 2012 | 1 comments

1 vote
URL safe Base64 Encoding in Lua

https://gist.github.com/2563975 A simple Base64 encoder/decoder that uses a URL safe variant of the standard. This implementation encodes character 62 as '-' (instead of '+') and character 63 as '_' (instead of '/'). In addition, padding is not used by default. A full description of the specification can be found here: http://tools.ietf.org/html/rfc4648 To encode, use: 1 base64.encode(input) where input is a... More...

Posted by Varen, Posted on 1 May 2012, Last updated 2 May 2012 | 0 comments

2 votes
Shortest Path Through A Concave Polygon With Holes

This program draws the shortest path between two points inside any polygon (with or without holes). The source for this program is C code by Darel Finley found at http://alienryderflex.com/shortest_path/ and translated into Lua by horacebury and me. The program lets you draw a bounding polygon that is either a convex polygon or a concave polygon. Other polygons can be drawn within the bounding polygon to create “... More...

Posted by brucemartin, Posted on 19 Apr 2012, Last updated 20 Apr 2012 | 8 comments

0 votes
Line intersection

Another little demo with sample code to calculate the intersection point between two lines. As always from me, you'll need the mathlib.lua here (because it has the key function): https://developer.anscamobile.com/code/maths-library main.lua: 1 2 3 4 5 6 7 8 9 10 11 12 -- line intersection require("mathlib")   -- http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/   -- turn off... More...

Posted by horacebury, Posted on 8 Apr 2012, Last updated 8 Apr 2012 | 0 comments

1 vote
Basic Grid / Table Renderer

Very rudimentary function to render tabular or grid data in exactly that fashion, ie. a table or grid. createGrid function requires two variables: design/layout settings and data to populate the table. Please see comments in grid.lua for implementation. Readme.txt on github will be updated if need be. Right, that explanation more than aptly explains it I believe. Now, how to get to this 50 word limit. Enough yet? More...

Posted by raurir, Posted on 5 Apr 2012, Last updated 5 Apr 2012 | 1 comments

0 votes
Polygon fill and Point in Polygon detection

Source of my inspiration: http://alienryderflex.com/tutorials.shtml local widthheight, isclosed, isperpixel = 1, false, false local widthheight, isclosed, isperpixel = 10, true, true NOTE: The functions in this demo are provided in the mathlib.lua found here: More...

Posted by horacebury, Posted on 5 Apr 2012, Last updated 5 Apr 2012 | 2 comments

1 vote
Simple Lua Table Save & Load

Hi, I'm not sure if anyone is going to use it, but I wanted to share this little piece of code. Currently it is designed to work with Corona XML Parser. What this code does is simply store lua table into an xml file and load it afterwards. More...

Posted by krystian6, Posted on 4 Apr 2012, Last updated 4 Apr 2012 | 0 comments

0 votes
bitmap font

I needed a bitmap font library that could individually adjust the spacing of letters. TextCandy is cool and has load of features but I didnt need them - so I wrote one from scratch. to use this 1) use texturepacker or bitmapfontgenerator to generate a spritefile and definition lua 1 2 3 4 5 local oSpriteData= require("texturepakerluafile") local aSpriteMap = require("myfontmap")... More...

Posted by open768, Posted on 29 Mar 2012, Last updated 29 Mar 2012 | 0 comments

2 votes
Save data to Files ( tables/numbers/strings/boolean )

This small useful module can be used to store and retrieve values across different app sessions. You can save TABLES, NUMBERS, STRINGS or BOOLEANS. FUNCTIONS 1 2 3 4 5 preference.save preference.getValue preference.getAllValues preference.print preference.printAll USAGE AND EXAMPLES 1 2 3 4 5 6 7 8 9 10 11 12 preference = require "save_and_load_library_from_satheesh"   preference.save{a=1}... More...

Posted by Satheesh, Posted on 26 Mar 2012, Last updated 26 Mar 2012 | 1 comments

0 votes
transition class library

--====================================================================-- -- TRANSITION CLASS --====================================================================-- --[[ - Version: 1.0 - Made by Krishna Raj Salim @ 2012 - linkedin profile : in.linkedin.com/in/krishnarajsalim - facebook profile : www.facebook.com/krishnarajsalim - Mail: krishnarajsalim@gmail.com ****************** - INFORMATION... More...

Posted by krishnarajsalim., Posted on 23 Mar 2012, Last updated 1 Apr 2012 | 0 comments

0 votes
Display Extensions

With so many regular operations being performed by code I thought it was time I wrote a library which helps with all this. Operations provided are: - Making a shorter global reference to the stage object - An 'indexOf' function for finding the index of a display object within a display group As with my other libraries, this will grow with time. You may notice that there are some functions designed to extend the '... More...

Posted by horacebury, Posted on 21 Mar 2012, Last updated 5 Apr 2012 | 1 comments

4 votes
Tar Extraction Module

Hey guys, I am aware that loads of you have been looking for a way to extract archives with Corona for a long time now. I am planning on implementing more archive support for corona in C/objective c but more info on that later. So for now, here is a solution done in pure lua. From benchmarking it took 1.3 seconds to extract a 10mb tar archive. I created the test tar archive using a mac app named "betterZip" however... More...

Posted by Danny, Posted on 13 Mar 2012, Last updated 13 Mar 2012 | 0 comments

5 votes
Streaming "News Ticker" (Twitter Feed or Online Text File)

I wrote the following bit of code for an app I'm working on where I wanted to have a "news ticker" scroll along the bottom of the home screen that I could change remotely. I also briefly considered streaming the most recent tweets from a Twitter account - so I'm including that code as well. See the commented-out text below for notes on how to change the ticker text or Twitter feed that displays. If you copy this... More...

Posted by jasonschroeder, Posted on 6 Mar 2012, Last updated 6 Mar 2012 | 24 comments

1 vote
Super simple Lua Table Save and Load from file functions

This is about as simple as it gets for reading and writing your game data files in Corona SDK/Lua. It uses the JSON library to do the magical data parsing so you don't have to worry about it. Start with a table. End up with the identical table. USAGE: myTable = {} myTable.musicOn = false myTable.soundOn = true saveTable(myTable, "myTable.json") Then to read it back in: myTable = loadTable("myTable.json") This... More...

Posted by robmiracle, Posted on 23 Feb 2012, Last updated 23 Feb 2012 | 9 comments

0 votes
Super Simple IAP in 1 Line

I use this in pretty much all my projects, and it works perfectly. I stripped out some of my own custom code, and left it with all the essentials that you need. Please let me know if it works for you. When you try to fetch the price of an item, it seems to be a hit or miss for me. I've tried multiple devices, and I'm not sure why it only works sometimes. Apples IAP servers are pretty bad, and there's lots of small... More...

Posted by 003naveen, Posted on 23 Feb 2012, Last updated 23 Feb 2012 | 16 comments

1 vote
GUID Creation Module

I needed a way to generate unique IDs for something I was working on, and since Corona doesn't have built in support for guids, and since the only other thing out there had dependencies, I wrote my own. I can't say that they adhere entirely to the spec., but they look right, and they're guaranteed to be unique, so it was good enough for me. They looks like this: DA3C1235-EAE1-2524-7798-63D2D8EBC487 846521A4-D962-... More...

Posted by ScottPhillips2, Posted on 21 Feb 2012, Last updated 21 Feb 2012 | 2 comments

11 votes
Ad Mediator for Corona®

Ad Mediator for Corona is a client-side ad mediation module very much like AdWhirl. It supports admob, inmobi, inneractive, herewead and house ads out of the box and can be extended easily by using a simple plugin framework. Ad Mediator is using providers' http api interface to request and fetch ad banners. By using this method, it knows whether there aren't any ads from a provider and able to select next available... More...

Posted by deniz, Posted on 16 Feb 2012, Last updated 13 Mar 2012 | 88 comments

2 votes
LunarAds | Promote Apps | Monetize Traffic | Measure Performance

Hi Everyone, Our new ad network SDK for Corona developers is ready for the masses! https://lunarads.com/signup/ It's been running solid for over 2 years in-house and we think it's time to let you guys take advantage of it! We are opening this up to Corona developers first (because we love you guys so much!) Below is the simple Corona wrapper that installs in seconds and lets you begin pushing Lunar ads. More...

Posted by MBD, Posted on 15 Feb 2012, Last updated 17 Feb 2012 | 17 comments

7 votes
Maths Library

NOTE: I have commented out the line at the top, so you now only need to require the mathlib in your main.lua and Disclaimer: I am not a mathematician and never will be. The library I've posted here has been developed to help me do things I don't really understand. I have derived all the code here either from first principles or translated it from other code posted to forums and which I can rely on working. It is... More...

Posted by horacebury, Posted on 15 Feb 2012, Last updated 11 May 2012 | 8 comments

0 votes
Much Improved 'dump' function and XML simplify

UPDATE: This post now has a lot more functionality, described just before the code... Original blog post: http://blog.anscamobile.com/2011/07/how-to-use-xml-files-in-corona/ Original shared code: https://developer.anscamobile.com/code/xml-table-parser This code is an update/huge improvement to my original post, above. The dump function traverses a table's contained tree and prints all of it's content to the console... More...

Posted by horacebury, Posted on 2 Feb 2012, Last updated 21 Feb 2012 | 8 comments

0 votes
cipr.struct

Data structure utilities for Corona, part of the Cipr project. Includes: cipr.struct.grid.Grid - An efficient 2D grid cipr.struct.grid.GridView - Translates a Grid into display coordinates cipr.struct.Set - An unorderd set cipr.struct.Vector2D - 2D vector operations Installation Installation is done with cipr cipr install git://github.com/six8/cipr.struct.git Usage Some examples. See source for full functionality... More...

Posted by cixate, Posted on 28 Jan 2012, Last updated 28 Jan 2012 | 0 comments

1 vote
Get Sprite by Name in a Sprite Sheet

Are you upset with the order of you sprite sheets? I am :) It's easy, for me, to sort sprite by name, example : "ship_1,ship_2", and to get the index of the first frame. Use the Basic layout in Zwoptex, then choose to order by name/Ascending. Here is a short snippet to get a sprite picture index in a sprite sheet. pSheetData is the sprite sheet used by sprite.newSpriteSheetFromData. pName is the picture name,... More...

Posted by dmekersa, Posted on 27 Jan 2012, Last updated 31 Jan 2012 | 1 comments

2 votes
Ad Manager for Corona

******************************************************************************************************** This module is obsolete. Please use Ad Mediator for Corona instead. It is an ad mediation module very much like Adwhirl. Ad Mediator for Corona: http://developer.anscamobile.com/code/ad-mediator-corona ********************************************************************************************************... More...

Posted by deniz, Posted on 25 Jan 2012, Last updated 16 Feb 2012 | 11 comments

0 votes
XML to table parser

Please see the updated version: http://developer.anscamobile.com/code/much-improved-dump-function-and-xml-simplify http://blog.anscamobile.com/2011/07/how-to-use-xml-files-in-corona/ In the blog post above Jon Beebe explains how to use XML in lua via a small library module. The one downside with this was that tables returned, while well structured, are not structured with the XML naming schema of the XML file. I... More...

Posted by horacebury, Posted on 25 Jan 2012, Last updated 2 Feb 2012 | 0 comments

0 votes
Basic drawing code

This is a very simply point drawing piece of code. Click on the simulator to create dots. Each new dot is joined to the last by a line. The length of the line is displayed next to it. The dots can be dragged and the first dot is green. Tap a dot to remove it. main.lua: 1 2 3 4 5 6 7 8 9 10 11 12 local stage = display.getCurrentStage()   local dots, lines = display.newGroup(), display.newGroup... More...

Posted by horacebury, Posted on 12 Jan 2012, Last updated 13 Jan 2012 | 4 comments

1 vote
Calculating area of an object

I have wanted to calculate the mass of an object for use in my previously submitted sample code (trajectory plotting.) The following code does that - calculates the area of an object, where it's points are clockwise in order and do not overlap. The limitation of 8 points maximum is not present. Using files produced from PhysicsEditor (that of a table of tables to represent more than 8 points) is left as an exercise... More...

Posted by horacebury, Posted on 7 Jan 2012, Last updated 7 Jan 2012 | 0 comments

0 votes
Load or Save Defaults / Preferences

This is some sample code to show one way in which you application / game can preserve state between sessions. There are many ways to do this, here is mine. Use it, abuse it, add to it, whatever you like. Happy to hear from you if you have extras to contribute, but I dont need to know if you use another method. ;) (I may move these functions out into a lobal.lua file at some point) To make use of this system, there... More...

Posted by jeff472, Posted on 5 Jan 2012, Last updated 7 Jan 2012 | 2 comments

2 votes
Simple XML Parser

Story I've used XML Parser created by Jonathan Beebe ( http://blog.anscamobile.com/2011/07/how-to-use-xml-files-in-corona/ ) to read small and simple XML files. However for one of my projects I do have a large XMLs to parse which are generated automatically for me. As you know, automatically may mean - random. Using a list of nodes and looping through it was out of the question. This is why I've created this little... More...

Posted by krystian6, Posted on 27 Dec 2011, Last updated 13 Feb 2012 | 6 comments

0 votes
Strip HTML Tags from Text

There is no genius here on my part, I just started with Corona a few days ago, however, I found a lua snippet that removes HTML tags from code, leaving just the plain text, and its working great for me. The original source for the code: http://board.ptokax.ch/index.php?topic=7165.0 I made a slight change in the first few lines to make it work with the text that is passed in vs from a file. It has worked well for me... More...

Posted by ethanpil, Posted on 20 Dec 2011, Last updated 20 Dec 2011 | 2 comments

4 votes
Calculating Trajectory

This code calculates every point (to the granularity you want) of an object travelling along a trajectory, starting with a given angle and velocity. I wanted to provide some very simply functions developers can call and have the most simple demonstration code - because that's all I can deal with. I have to say that I did not work this stuff out myself, but just went looking for a really good tutorial, which I found... More...

Posted by horacebury, Posted on 5 Dec 2011, Last updated 5 Dec 2011 | 6 comments

0 votes
I18N Strings

Java-Like Locale String Resources (i18n) I found a few examples of locale string resource handling in Corona, but I wasn't satisfied. I thought Rosetta had a good thing going, but I couldn't use it as I wanted to. This class allows strings to be added in a genreal to more specific way. You set up the resources files from most general to most specific. The first one, strings.i18n, should always be present and... More...

Posted by bpappin, Posted on 29 Oct 2011, Last updated 29 Oct 2011 | 4 comments

7 votes
Director Slim - Stripped down Director Class

I've managed to strip it down to only 15 lines of code! That's right. Plus 6 lines for the header. Works faster, with lower overhead - hence higher performance. UPDATE 2011-11-05: Reduced to 15 lines. Fully working example added to GitHub. I didn't like director 1.3 when it came out, so I decided to stick with version 1.2a - the one with improved group cleaning function. I was fine with it thanks to Ricardo and... More...

Posted by Lerg, Posted on 29 Oct 2011, Last updated 4 Nov 2011 | 37 comments

4 votes
Load Progress Bar

This example shows you how to add a progress bar to your loading screen. The progress bar updates after each data chunk is loaded. You can change the bUseListener value in cSceneLoad.lua to specify if you want the bar updated every frame, or just when each data chunk has been loaded (preferred method). This example is licensed under the MIT license so you are free to modify it and use it however you like. More...

Posted by KenRogoway, Posted on 12 Oct 2011, Last updated 12 Oct 2011 | 43 comments

0 votes
A different way of managing dynamic image resolution [and scaling font size]

// A note: after a comment by nicholasclayg I've changed my code so that now it doesn't use "package.seeall" (now deprecated) and therefore doesn't use global namespace // // Note 2: I've loaded my example code (for Windows) on GitHub; this version of DynResManager contains also some useful functions for determining actual screen size of your device and real values of visible x/y boundaries. Next time I'll explain... More...

Posted by mmagrilov, Posted on 1 Oct 2011, Last updated 7 Nov 2011 | 7 comments

28 votes
Ice

Ice allows you save and load data when using the Corona ® SDK. It is very simple to use and allows you to create as many 'iceboxes' as you like. Great for storing local high scores, settings and other data. I hope to update my site here - http://grahamranson.co.uk/lib.php?id=6 - with proper usage instructions but until then you can get the majority of stuff done pretty easily. 1 2 3 4 5 6 7 require( "ice... More...

Posted by GrahamRanson, Posted on 29 Sep 2011, Last updated 13 Nov 2011 | 282 comments

8 votes
Flickr Photo Browser

Awhile ago, I was approached to do a custom app for someone. The app itself is finished (not published yet) and in the process of creating it I thought it would be a good idea to publish the source for the dynamic image slider control I created. Well, not content with just publishing a simple control, I decided to create an entire demonstration app to see it in action. The Flickr Photo Browser is the result of this... More...

Posted by codepunk_schmidt, Posted on 20 Sep 2011, Last updated 20 Sep 2011 | 9 comments

3 votes
settings.lua for storing info

settings.lua stores info in a local file. It will persis Do this somewhere in main(): 1 settings.load() Then you can get values easily: 1 2 3 4 5 6 local soundOn = settings.get('sound_on') if soundOn then   print("Sound is on") else   print("Sound is off") end You can also set values easily: 1 2 settings.set('sound_on', false) settings.set('... More...

Posted by hoan, Posted on 6 Sep 2011, Last updated 6 Sep 2011 | 12 comments

3 votes
Various utility functions (priority heap, pretty printer, xml parser, clamper, etc...)

I collected a small library of useful functions. Some of them aren't of my implementation, but I still included them. utils.lua------------------------------------------- -- Various utility functions and constants -- Some of these are mine (Lerg), some I found on the net -- Release date: 2011-08-25 -- Version: 1.0 -- License: MIT I guess, at least my part -------------------------------------------... More...

Posted by Lerg, Posted on 25 Aug 2011, Last updated 28 Aug 2011 | 0 comments

4 votes
Dynamic Module Loading

“Dynamic Module Loading”. Sounds fancy but in fact it really isn’t. Whenever I start a new project and am in the design phase, I look for areas of the design that can benefit from being data driven and a way to support an extensible plugin model. The code I’m about to show you here does just that. Again, not rocket science but I think you’ll see that it can help you quite a bit. The whole concept behind this lies... More...

Posted by codepunk_schmidt, Posted on 17 Aug 2011, Last updated 17 Aug 2011 | 2 comments

1 vote
Thousands Separator for Large Numerical Strings

This will take in a number and outputs a string of that number with commas put in to mark the thousands. I took this from an old forum post and slightly altered it, but it seems like it would be more useful here in the code exchange. Hope it saves you a little time. Note: this will not work for numbers that are longer than 14 digits. Those will automatically be converted into scientific notation before entering the... More...

Posted by w2md, Posted on 11 Aug 2011, Last updated 11 Aug 2011 | 1 comments

0 votes
RSS Parser

This is an attempt to parse and RSS feed and provide the caller with a table of stories. Usage: 1 2 3 4 5 6 7 8 9 10 11 12 local rss = require("rss")   stories = {}   stories = rss.feed("index.rss", system.TemporaryDirectory)   for i = 1, #stories do     print(stories.title)     print(stories.content_encoded)  ... More...

Posted by robmiracle, Posted on 10 Aug 2011, Last updated 10 Aug 2011 | 27 comments

0 votes
Sketch Smash 2 Source Files

Here are the Sketch Smash 2 Source Files for your learning, modding, and hacking delight. I want to say thanks to the awesome Corona community. I wouldn't be able to make my indie game without ya. Include Sketch Smash and Sketch Smash 2 Source Code is Based on Beebe Games 'Ghosts vs Monsters' Most images created by my wife and I Needs Corona SDK to build You can get the the Source at my website. http://www.blamza.... More...

Posted by ciaphuas, Posted on 8 Aug 2011, Last updated 8 Aug 2011 | 1 comments

1 vote
Subfolders for Lua, audio, xml and other files. Keep sanity.

Tired of keeping tons of files inside the root app directory? Want to group similar files in separate folders? Losing your mind while searching for a specific file? Then my solution is right for you! Concept is simple: while coding place your files in subfolders. Access them with: someModule = require('some/subfolder/some_module') That already works for the simulator, but fails when building an end... More...

Posted by Lerg, Posted on 17 Jul 2011, Last updated 29 Apr 2012 | 10 comments

7 votes
Upload binary from Corona to PHP script

Uploading a binary from your app to a web server is a bit tricky with Corona... but not if you have this code! ;-) Here's all you need in order to get it done... In your app, you'll want this uploadBinary function: 1 2 3 4 5 6 7 8 9 10 11 function uploadBinary ( filename, url, onComplete )           local mime = require "mime"         local path =... More...

Posted by kennw, Posted on 25 Jun 2011, Last updated 30 Jan 2012 | 27 comments

3 votes
Shuffle/randomize Tables

The following function implements the modern version of the Fisher-Yates shuffling algorithm: 1 2 3 4 5 6 7 8 9 10 function table.shuffle(t)         math.randomseed(os.time())         assert(t, "table.shuffle() expected a table, got nil")         local iterations = #t         local j  ... More...

Posted by Ludicrous Software, Posted on 7 Jan 2011, Last updated 7 Jan 2011 | 19 comments

8 votes
Rosetta

Rosetta is a very simple module that makes it easy to include multiple languages (or just one) in your app or game. Languages are stored in external files which allow your designers/translators to edit them without requiring the help of a programmer. Example usage -- Load Rosetta local rosetta = require("rosetta").new()   -- Initiate Rosetta - this will load all languages and settings... More...

Posted by GrahamRanson, Posted on 4 Jan 2011, Last updated 27 Aug 2011 | 25 comments

1 vote
Async/Sync State Management For Debug

I got really excited when I read about Niels Async HTTP workaround using Web Pop Ups. I realised early on the difficulty of trying to debug code which couldn't run within the Corona Simulator which doesn't support Web Pop Ups. I wrote some code which which can switch between Sync for local debug, and Async for deployment to the phone. In order to maintain the event flow I had to build in an onComplete event for Sync... More...

Posted by bedhouin, Posted on 14 Dec 2010, Last updated 14 Dec 2010 | 0 comments

6 votes
Useful functions for Tables and Arrays

This module includes 5 very useful methods for working with Tables and Arrays: 1 2 3 4 5 keys(table) -- Returns the keys from the table values(table) -- Returns the values from the table include(table, value) -- Checks if the given value is included in the table select(table, expression) -- Selects values from the table by the given expression reject(table, expression) --... More...

Posted by tjackiw, Posted on 18 Oct 2010, Last updated 21 Oct 2010 | 5 comments

7 votes
Wrap Text

Use this function to wrap long bodies of text. Supports paragraphs. More...

Posted by Gilbert, Posted on 14 Jul 2010, Last updated 14 Jul 2010 | 31 comments

6 votes
explode function

This function is intended to work just like PHP's explode function. It's handy for parsing data. More...

Posted by Gilbert, Posted on 13 Jul 2010, Last updated 16 Jul 2010 | 6 comments

2 votes
Read an RSS feed into a Lua table

Download an RSS feed into a table for later parsing: More...

Posted by d3mac123, Posted on 2 Jun 2010, Last updated 7 Oct 2010 | 8 comments