Easy way to pass arguments to an event handler

Posted by emi, Posted on June 5, 2013

1 vote

Hi,

A ugly way to pass arguments to an event handler is doing this:

1
2
3
4
5
6
7
8
9
10
function printVars(event, var1, var2)
    if event.phase == "ended" then
        print(var1)
        print(var2)
    end
end
 
local button = display.newRect(0, 0, 100, 30)
 
button:addEventListener( 'touch', function(event) printVars(event, 'foo', 'bar') end )

To avoid this mess of code, I've written a wrapper function named 'curry' that simplifies this code:

1
2
3
4
5
function curry(...)
        local func = arg[1]
        local args = arg
        table.remove(args, 1)
        return function(event)

Structuring your display objects and their transitions/timers for easy removal

Posted by BeyondtheTech, Posted on April 2, 2013

0 votes

When building a display object, structure the timers and transitions under it. So, when it comes time to destroy the object, any timers and transitions you've used regarding it will be properly canceled, preventing any memory leaks or crashes due to unresolved tweens. With the two functions below, you can destroy a single object, an object in an array, or an entire array of objects.

1
2
3
4
5
6
7
8
local function destroy( ... )
    local i, j  
    if #arg > 0 then
                for i = 1, #arg do
                        local obj = arg[ i ]
                        if obj ~= nil then
                                if #obj.timer > 0 then
                                        for j = 1, #obj.timer do

Sweeping through a table of display objects

Posted by BeyondtheTech, Posted on March 25, 2013

0 votes

Perhaps some of you know this already, but it wouldn't hurt to post, since it can help bring everyone up to speed.

Let's say you create a table of display objects, like gems, or missiles or enemy ships, and you want to sweep through the entire table to do something with them, like making them all explode or disappear instantly.

CBResources

Posted by Caleb P, Posted on March 20, 2013, Last updated April 6, 2013

1 vote

After much work, CBResources has just been finished.

Includes a manual, reference, bragging rights, sample browser app, roadmap, info, and the old, outdated previous samples.

To run the sample app, you'll need to copy CBEffects into the CBResources root folder.

Edit Apr. 6: Supports Widget 2.0

Enjoy!

Caleb

Get it from Gymbyl

loadSoundLibrary: a quick way of structuring and loading your sound effects

Posted by BeyondtheTech, Posted on March 8, 2013

0 votes

If your code (and your build files) are getting a little discombobulated with all the sound effect files you have to load, this little code snippet can make loading sounds a lot easier with a lot less code.

As your development progresses, many of you might notice a growing list of sound files sitting in the same folder as your image files as well as your lua code, so having a long directory could get a little messy to sift through when you need to. This snippet also takes that into consideration and allows you to put it in a separate subfolder for a little more peace of mind.

Thumbprint Scanner

Posted by croisened, Posted on February 5, 2013

1 vote
GitHub URL: 
https://github.com/Croisened/ThumbScanner

This project I created for several reason and I’m pleased to share it with all of you. If anyone has used my Corona Shell Project (A starting point for any project) based on Director 1.4 you know how handy it is to get a jump start on a new project when you already have some plumbing in place. I created this Thumb Scanner as a fun aspect to “secure” scenes from users until they put in the proper code and “scan” their thumb on the thumb scanner. it is completely revamped to used Corona SDK Storyboard and Widgets as opposed to Director and the historic ui.lua

NeonPong - Complete Pong Sample Game/Template

Posted by Caleb P, Posted on January 17, 2013, Last updated January 30, 2013

0 votes

I made a complete version of Pong for a demo/sample code example. I commented all of the code (heavily) and it wasn't all that complicated in the first place, so there should be no trouble with understanding it :)

There is a CPU, different difficulties, (easy, medium, hard, and endless), and it does collision checking and moving of the ball without physics.

It's also quite fun ;)

Side Scroller Game

Posted by Mark Falkland, Posted on December 28, 2012

0 votes

A side scroller game with Storyboard, Physics (collisions, gravity, forces) as well as Parallax Scrolling. Intended for beginners or people some a small to medium amount of coding experience.

Comes with a video tutorial (about 2hrs all up) that shows how to build the entire game. The video tutorial begins at:

http://www.youtube.com/watch?v=0GtUxdSeWzk&feature=youtu.be

Get the full graphics and lua files here:
http://www.mediafire.com/?tz4tizasm6ww4r8

Bouncy Lines Demo

Posted by Caleb P, Posted on December 17, 2012

1 vote

I was playing around with my ParticlePhysics library (from CBEffects) and I came up with this interesting demo. You'll need to get the ParticlePhysics library and copy it into the root folder.

It does get out of sync sometimes, but still, it's quite cool-looking :)

1
2
3
4
5
6
7
8
9
10
11
12
13
local physics=require("ParticlePhysics").createPhysics()
physics.start()
 
local numThings=5
local numLines=6
 
local things={}
 
for i=1, numThings do
        local x, y=math.random(100, 924), math.random(100, 668)
        things[i]={}
        things[i].object={}
        local velX, velY=math.random(-5, 5), math.random(-5, 5)

Rectangle Drawing Demo

Posted by Caleb P, Posted on November 8, 2012

0 votes

Here's a little demo I made to draw rectangles, like a lot of image editing programs can do. Drag and drop to draw one. When you touch, move, and let go, it will print some stats about the event. I've added quite a lot of comments, so it shouldn't be too difficult to understand :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
--[[
Rectangle drawing demo.
 
Drag and let go to make a rectangle.
--]]
display.setStatusBar(display.HiddenStatusBar) -- Hide the status bar
 
local startX, startY
local s
local squareWidth, squareHeight
local prevTime
local nowTime
local timeSpent
local hasMoved
 
local bkg={}