Pixel Envision Ltd.
Mobile Game Development Studio
  • Home
  • About Us
  • Our Games
    • Hyper-Casual
    • Casual Games
      • Don’t Get Caught
      • Hordes of Enemies
      • noded
      • kubic
      • Whip Swing
      • Witches’ Brew
    • Kids Apps
      • Coloring Book
      • Cars & Trucks Puzzle
      • Train Puzzles for Kids
      • Animal Puzzle
      • Fairy Tale Puzzles for Kids
      • Find the Differences
  • Support
  • Privacy Policy
Select Page ...

Category: Lua

We have stopped developing with the Corona SDK

February 14, 2012 CoronaSDK, Lua

Due to recent developments, we will no longer be using Corona SDK. If anyone wants to know why, all I can say is that’s because of all the little things stacking up on each other such as:

  • Dropping ArmV6 support, first on Android and now on iOS.
  • Forcing 32 bit frame buffers for Android (to fix gradient banding issues) which causes slowdowns, without an option to disable it.
  • Launchpad Analytics appended to each app but simply I do not want Ansca to track my apps… Yes, I know there is an option to disable this but it’ll be back on as soon as you add something like game network, ads, etc…
  • They are still adding new features while there are major stuff waiting to be fixed such as properly working masks, better (retina, rotation, etc) sprites, etc…
  • Outdated core engine, Box2D
  • Bloating app size day by day with the stuff I won’t be using such as Papaya, super rewards, etc.
  • We wanted iAds, Ansca added InMobi. We wanted iAds, Ansca added Inneractive. We wanted iAds….well, still nothing…
  • Simulator vs Device inconsistency

I still think CoronaSDK is an good alternative but simply, it’s not suited for us anymore…

Btw, following CoronaSDK projects maintained by us will be discontinued as well. If anyone wants to continue working on those projects may do so freely.

Autocomplete Wordlist for Corona Project Manager (CPM) *
CoronaSDK Enhanced UI Library (ui.lua)
CoronaSDK Proper Orientation Rotation with Animation

* This project is taken over by Jay himself, thank you Jay…

For anyone looking for similar LUA based cross platform alternatives, I would suggest looking at Gideros or Moai SDK + Rapanui
Edit 2: Since I made that post, there were some improvements to the SDK such as Box2D update (appears to be WIP), new sprite API, off-screen culling, etc. I’m glad to see things are improving…

Autocomplete Wordlist for Corona Project Manager (CPM)

December 9, 2011 CoronaSDK, Lua

If you are serious about mobile development using CoronaSDK there is one tool you should definitely check out, Corona Project Manager by J. A. Whye. For me, it’s an organic extension to CoronaSDK and makes it very easier to work with.

One of the most important features of CPM is the autocomplete function. It speeds up my coding but also it reminds me the functions I might have forgotten at the time, or functions recently added which might make things easier. Because of that, I’d like to keep it up-to-date. You may copy & paste the following list to keep yours updated as well! ;)

Updated on December 9, 2011 for Corona SDK 2011.701+

Lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
analytics.init (  )
analytics.logEvent (  )
and
assert(   )
audio.dispose (  )
audio.fade ( [ { [channel=] [, time=] [, volume= ] } ] )
audio.fadeOut ( [ { [channel=] [, time=] } ] )
audio.findFreeChannel (  )
audio.freeChannels
audio.getDuration (  )
audio.getMaxVolume ( { channel= } )
audio.getMinVolume ( { channel= } )
audio.getVolume ( [ { channel= } ] )
audio.isChannelActive (  )
audio.isChannelPaused (  )
audio.isChannelPlaying (  )
audio.loadSound (   )
audio.loadStream (   )
audio.pause (  )
audio.play (  [, { [channel=] [, loops=] [, duration=] [, fadein=] [, onComplete=]  } ] )
audio.reserveChannels (  )
audio.reservedChannels
audio.resume (  )
audio.rewind ( [  ] [, { channel= } ] )
audio.seek (   [, { channel= } ] )
audio.setMaxVolume ( , { channel= } )
audio.setMinVolume ( , { channel= } )
audio.setVolume (  [,{ channel= }] )
audio.stop (  )
audio.stopWithDelay (   )
audio.totalChannels
audio.unreservedFreeChannels
audio.unreservedUsedChannels
audio.usedChannels
body.angularDamping
body.angularVelocity
body.bodyType
body.isAwake
body.isBodyActive
body.isBullet
body.isFixedRotation
body.isSleepingAllowed
body.linearDamping
body:applyAngularImpulse (  )
body:applyForce ( , , ,  )
body:applyLinearImpulse ( , , ,  )
body:applyTorque (  )
body:getLinearVelocity ( )
body:resetMassData ( )
body:setLinearVelocity ( ,  )
break
crypto.digest ( ,   )
crypto.hmac ( , ,   )
crypto.md4
crypto.md5
crypto.sha1
crypto.sha224
crypto.sha256
crypto.sha384
crypto.sha512
display.captureScreen (  )
display.contentCenterX
display.contentCenterY
display.contentHeight
display.contentScaleX
display.contentScaleY
display.contentWidth
display.getCurrentStage ( )
display.loadRemoteImage ( , ,  ,    )
display.newCircle( , ,  )
display.newGroup ( )
display.newImage(    )
display.newImage(      )
display.newImageRect (    ,  )
display.newLine(  , , ,  )
display.newRect(  , , ,  )
display.newRoundedRect(  , , , ,  )
display.newText(  "", , , ,  )
display.save ( ,   )
display.screenOriginX
display.screenOriginY
display.setDefault( , , ,   )
display.setStatusBar (  )
display.statusBarHeight
display.viewableContentHeight
display.viewableContentWidth
do
easing.inExpo ( , , ,  )
easing.inOutExpo ( , , ,  )
easing.inOutQuad ( , , ,  )
easing.inQuad ( , , ,  )
easing.linear ( , , ,  )
easing.outExpo ( , , ,  )
easing.outQuad ( , , ,  )
else
elseif
end
error (   )
event.accuracy
event.altitude
event.city
event.cityDetail
event.count
event.country
event.countryCode
event.delta
event.direction
event.errorCode
event.errorMessage
event.force
event.friction
event.geographic
event.id
event.invalidProducts
event.isError
event.isShake
event.latitude
event.longitude
event.magnetic
event.name
event.object1
event.object2
event.other
event.phase
event.postalCode
event.products
event.region
event.regionDetail
event.source
event.speed
event.sprite
event.street
event.streetDetail
event.time
event.transaction
event.type
event.url
event.x
event.xGravity
event.xInstant
event.xStart
event.y
event.yGravity
event.yInstant
event.yStart
event.zGravity
event.zInstant
facebook.login ( ,   )
facebook.logout ( )
facebook.request (   )
facebook.showDialog (  )
false
file:close ( )
file:flush ( )
file:lines ( )
file:read (    )
file:seek (   )
file:setvbuf (   )
file:write (    )
for
function
getfenv (  )
getmetatable (  )
group.numChildren
group:insert(  ,  )
group:remove (  )
if
in
io.close (  )
io.flush ( )
io.input (  )
io.lines (  )
io.open (   )
io.output (  )
io.popen ( )
io.read (    )
io.tmpfile ( )
io.type (  )
io.write (    )
ipairs (  )
joint.dampingRatio
joint.frequency
joint.isLimitEnabled
joint.isMotorEnabled
joint.jointAngle
joint.jointSpeed
joint.jointTranslation
joint.length
joint.length1
joint.length2
joint.maxForce
joint.maxMotorForce
joint.maxMotorTorque
joint.maxTorque
joint.motorForce
joint.motorSpeed
joint.motorTorque
joint.ratio
joint:getAnchorA ( )
joint:getAnchorB ( )
joint:getLimits ( )
joint:getReactionForce ( )
joint:getRotationLimits ( )
joint:removeSelf ( )
joint:setLimits ( ,  )
joint:setRotationLimits ( ,  )
local
math.abs (  )
math.acos (  )
math.asin (  )
math.atan (  )
math.atan2 ( ,  )
math.ceil (  )
math.cos (  )
math.cosh (  )
math.deg (  )
math.exp (  )
math.floor (  )
math.fmod ( ,  )
math.frexp (  )
math.huge
math.ldexp (  , )
math.log (  )
math.log10 (  )
math.max ( ,  )
math.min ( ,  )
math.modf (  )
math.pi
math.pow ( ,  )
math.rad (  )
math.random (  )
math.randomseed (  )
math.sin (  )
math.sinh (  )
math.sqrt (  )
math.tan (  )
math.tanh (  )
media.getSoundVolume ( )
media.newEventSound (   )
media.newRecording(  )
media.pauseSound ( )
media.playEventSound (    )
media.playSound(    )
media.playSound(    )
media.playVideo(  , ,  )
media.setSoundVolume(  )
media.show ( ,  )
media.stopSound ( )
module (   )
movieclip.newAnim (  )
myMap.isLocationVisible =
myMap.isScrollEnabled =
myMap.isZoomEnabled =
myMap.mapType =
myMap:addMarker ( , , [{ title="", subtitle="" } ] )
myMap:getAddressLocation (  )
myMap:getUserLocation ( )
myMap:removeAllMarkers ( )
myMap:setCenter ( , ,  )
myMap:setRegion ( , , , ,  )
native.cancelAlert (  )
native.cancelWebPopup ( )
native.getFontNames ( )
native.newFont (   )
native.newTextBox ( , , ,  )
native.newTextField ( , , ,   )
native.setActivityIndicator (  )
native.setKeyboardFocus (  )
native.showAlert ( ,   )
native.showWebPopup(   )
native.showWebPopup( , , , ,   )
network.download ( , ,  ,   )
network.request ( , ,   )
next (   )
nil
not
object.align
object.alpha
object.baseUrl
object.font
object.hasBackground
object.height
object.isHitTestable
object.isSecure
object.isVisible
object.parent
object.play ( )
object.rotation
object.size
object.strokeWidth
object.text
object.urlRequest
object.width
object.x
object.xOrigin
object.xReference
object.xScale
object.y
object.yOrigin
object.yReference
object.yScale
object:addEventListener ( ,  )
object:dispatchEvent(  )
object:getSampleRate ( )
object:getTunerFrequency ( )
object:getTunerVolume ( )
object:isRecording ( )
object:nextFrame ( )
object:play ( )
object:play { startFrame=, endFrame=, loop=, remove= }
object:previousFrame ( )
object:removeEventListener ( ,  )
object:reverse ( )
object:reverse { startFrame=, endFrame=, loop=, remove= }
object:rotate(  )
object:scale ( ,  )
object:setDrag ( drag= )
object:setFillColor ( , ,   )
object:setLabels { frameLabel1=, frameLabel2=, frameLabelN= }
object:setReferencePoint (  )
object:setSampleRate(  )
object:setStrokeColor ( , ,   )
object:setTextColor ( , ,   )
object:startRecording ( )
object:startTuner ( )
object:stop ( )
object:stopAtFrame (  )
object:stopRecording ( )
object:stopTuner ( )
object:translate ( ,  )
openfeint.downloadBlob ( ,  )
openfeint.init ( , , ,  )
openfeint.launchDashboard (  )
openfeint.launchDashboard ( ,  )
openfeint.setHighScore ( { leaderboardID=, score=  } )
openfeint.unlockAchievement (  )
openfeint.uploadBlob ( ,  )
or
os.clock ( )
os.date (  )
os.difftime ( ,  )
os.execute(  )
os.exit (  )
os.remove (  )
os.rename ( ,  )
os.time (  )
package.loaded
package.loaders
package.seeall (  )
pairs (  )
pcall ( , ,  )
physics.addBody ( ,  {density=, friction=, bounce= [,radius=]} )
physics.addBody ( ,  {density=, friction=, bounce= [,shape=]} )
physics.newJoint ( , , , ,  )
print (  )
rawequal ( ,  )
rawget ( ,  )
rawset ( , ,  )
removeSelf()
repeat
require (  )
return
select ( ,  )
setfenv ( ,  )
setmetatable ( ,  )
setReferencePoint(display.TopLeftReferencePoint)
sprite.add ( , , , , ,  )
sprite.newSpriteSet ( , ,  )
sprite.newSpriteSheet ( ,   ,  )
sprite.newSpriteSheetFromData( ,   )
spriteInstance.animating
spriteInstance.currentFrame
spriteInstance.newSprite (  )
spriteInstance.sequence
spriteInstance:addListener (  )
spriteInstance:pause ( )
spriteInstance:play ( )
spriteInstance:prepare (  )
spriteSheet:dispose ( )
stage:setFocus (  )
store.canMakePurchases
store.finishTransaction (  )
store.init (  )
store.loadProducts ( ,  )
store.purchase (  )
store.restore()
string.byte (   )
string.char (   )
string.find ( ,   )
string.format (   )
string.gmatch( ,  )
string.gsub ( , ,   )
string.len (  )
string.lower (  )
string.match ( ,   )
string.rep ( ,  )
string.reverse (  )
string.sub ( ,   )
string.upper (  )
system.getInfo(  )
system.getPreference ( ,  )
system.getTimer ( )
system.openURL (  )
system.pathForFile ( )
system.setAccelerometerInterval (  )
system.setIdleTimer (  )
system.setLocationAccuracy (  )
system.setLocationThreshold (  )
system.vibrate ( )
table.concat (   )
table.insert ( ,   )
table.maxn (  )
table.remove (   )
table.sort (   )
then
timer.cancel (  )
timer.performWithDelay ( ,   )
tonumber (   )
tostring (  )
transition.cancel (  )
transition.dissolve( , , ,  )
transition.from ( ,  )
transition.to ( ,  )
true
type (  )
unpack (   )
until
while
_G
alphabet
align
alpha
baseUrl
font
hasBackground
height
isHitTestable
isSecure
isVisible
parent
rotation
size
contentBounds
contentHeight
contentWidth
strokeWidth
text
urlRequest
width
xOrigin
xReference
xScale
yOrigin
yReference
yScale
addEventListener ( ,  )
dispatchEvent(  )
getSampleRate ( )
getTunerFrequency ( )
getTunerVolume ( )
isRecording ( )
nextFrame ( )
play ( )
play { startFrame=, endFrame=, loop=, remove= }
previousFrame ( )
removeEventListener ( ,  )
reverse ( )
reverse { startFrame=, endFrame=, loop=, remove= }
rotate(  )
scale ( ,  )
setDrag ( drag= )
setFillColor ( , ,   )
setLabels { frameLabel1=, frameLabel2=, frameLabelN= }
setReferencePoint (  )
setSampleRate(  )
setStrokeColor ( , ,   )
setTextColor ( , ,   )
startRecording ( )
startTuner ( )
stop ( )
stopAtFrame (  )
stopRecording ( )
stopTuner ( )
translate ( ,  )
math.round(  )
table.copy( ,   )
table.indexOf( ,  )
credits.init( , ,  )
credits.requestUpdate( )
credits.showOffers( )
event.newCredits
event.totalCredits
graphics.newMask(    )
display.remove(  )
object:contentToLocal( ,  )
object:localToContent( ,  )
object:removeSelf( )
object:setMask(  )
object:toBack( )
object:toFront( )
object.contentBounds
object.contentHeight
object.contentWidth
object.isHitTestMasked
object.maskRotation
object.maskScaleX
object.maskScaleY
object.maskX
object.maskY
object:append( ,  )
object:setColor( , ,   )
native.newMapView( , , ,  )
system.DocumentsDirectory
system.ResourceDirectory
system.TemporaryDirectory
system.activate(  )
system.orientation( )
network.canDetectNetworkStatusChanges
network.setStatusListener( ,  )
native.systemFont
event.address
event.isConnectionOnDemand
event.isConnectionRequired
event.isInteractionRequired
event.isReachable
event.isReachableViaCellular
event.isReachableViaWiFi
event.channel
event.completed
event.handle
event.action
event.index
event.target
event.numTaps
object.inputType =
physics.getGravity( )
physics.pause( )
physics.setDrawMode(  )
physics.setGravity( ,  )
physics.setPositionIterations(  )
physics.setScale(  )
physics.setVelocityIterations(  )
physics.start(  )
physics.stop( )
body.isSensor
joint.reactionTorque
spriteInstance.timeScale
sprite.newSpriteMultiSet({ { sheet = , frames = { n1, n2, nx} }, })
audio.supportsSessionProperty
audio.setSessionProperty( ,  )
audio.getSessionProperty(  )
audio.ActiveMode
audio.MixMode
audio.OverrideMixWithOthers
audio.OtherAudioIsPlaying
audio.OtherMixableAudioShouldDuck
audio.AmbientMixMode
audio.SoloAmbientMixMode
audio.MediaPlaybackMixMode
audio.RecordAudioMixMode
audio.PlayAndRecordMixMode
system.setGyroscopeInterval( )
system.hasEventSource(  )
event.deltaTime
event.xRotation
event.yRotation
event.zRotation
gameNetwork.init (   )
gameNetwork.request (   )
gameNetwork.show (   )
json.encode(  )
json.decode(  )
json.null()
event.keyName
event.phase
event.name
physics.removeBody(  )
timer.pause(  )
timer.resume(  )
ads.init( ,  )
ads.show(   )
ads.hide( )
object.isEditable
graphics.newGradient( ,   )
system.scheduleNotification(   )
system.scheduleNotification(   )
system.cancelNotification(  )
display.newRetinaText(  "", , ,  ,  )
display.newEmbossedText(  "", , ,  , ,  )
widget.newButton (  )
widget.newSlider (  )
widget.newScrollView (  )
widget.newTableView (  )
widget.newTabBar (  )
widget.newPickerWheel (  )
widget.setTheme (  )
storyboard.newScene ( )
storyboard.gotoScene (  ""  )
storyboard.purgeScene ( "" )
storyboard.removeScene ( "" )
storyboard.getPrevious ( )
storyboard.getScene ( "" )
storyboard.purgeAll ( )
storyboard.removeAll ( )
system.setLocationThreshold(  )

CoronaSDK Enhanced UI Library (ui.lua)

August 3, 2011 CoronaSDK, Lua

While working with CoronaSDK I ended up using ui.lua for the buttons in our upcoming iPhone/iPad game. But I had hard time locating the latest version as many other developers had their own versions.

So, I have decided to make an ultimate latest version that will combine all previous enhancements along with my own. Copy of that Lua code is still available at Ansca code exchange.

NEW: Updated to eliminate the use of LUAs deprecated module() function. This is an internal change only, usage stays the same.
NEW: Added event support, now returns even.target, event.x & event.y values. You can use x/y values to provide different actions based on the coordinates of the touch event reative to the x/y size of the button image.
NEW: isActive state enhanced, so the button can be enabled/disabled without checking current isActive state with if-then.

ui.lua v2.4

Lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
-- ui.lua (currently includes Button class with labels, font selection and optional event model)
 
-- Version 2.4
-- Based on the folowing original provided by Ansca Inc.
-- Version 1.5 (works with multitouch, adds setText() method to buttons)
--
-- Copyright (C) 2010 ANSCA Inc. All Rights Reserved.
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
-- this software and associated documentation files (the "Software"), to deal in the
-- Software without restriction, including without limitation the rights to use, copy,
-- modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
-- and to permit persons to whom the Software is furnished to do so, subject to the
-- following conditions:
--
-- The above copyright notice and this permission notice shall be included in all copies
-- or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
-- INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
-- PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
-- FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-- DEALINGS IN THE SOFTWARE.
 
-- Version 1.6 Works with Dynamic Scaling.
-- Based on the work edited by William Flagello, williamflagello.com
-- Original from https://developer.anscamobile.com/code/ui-library
--
-- Version 1.7 Dynamic Scaling text fixes by Jonathan Bebe
-- http://developer.anscamobile.com/forum/2010/12/17/easily-make-your-text-sharp-retina-displays#comment-18164
-- Provided in Ghosts & Monsters Sample Project
--
-- Version 1.71 Retina Updates by Jonathan Bebe
-- http://developer.anscamobile.com/forum/2010/12/17/easily-make-your-text-sharp-retina-displays#comment-38284
-- Adapted to 1.7 base code by E. Gonenc, pixelenvision.com
--
-- Version 1.8 added support for providing already realized display-objects for use in Tiled/Lime
-- Based on the file changed by Frank Siebenlist
-- http://developer.anscamobile.com/forum/2011/02/19/enhanced-uilua-v15
-- Adapted to 1.7 base code by E. Gonenc, pixelenvision.com
--
-- Version 1.9
-- Added transparency & scaling options to use as over state. newLabel updated to support retina text.
-- Edited by E. Gonenc, pixelenvision.com
--
-- Version 1.91
-- Added suggested fix for overlapping buttons by Jonathan Bebe
-- http://jonbeebe.net/to-return-true-or-not-to
-- Adapted by E. Gonenc, pixelenvision.com
--
-- Version 2.02
-- Button text will now follow scaling & alpha states of over button
-- Edited by E. Gonenc, pixelenvision.com
--
-- Version 2.1
-- Added suggested .isActive update by monoxgas http://developer.anscamobile.com/code/enhanced-ui-library-uilua#comment-49272
-- Edited by E. Gonenc, pixelenvision.com
--
-- Version 2.2
-- Updated to eliminate the use of LUAs deprecated module() function. This is an internal change only, usage stays the same.
-- http://blog.anscamobile.com/2011/09/a-better-approach-to-external-modules/
-- Edited by E. Gonenc, pixelenvision.com
--
-- Version 2.3
-- Updated to use object.contentBounds instead of deprecated object.stageBounds
-- Added event support, now returns even.target, event.x & event.y values. You can use x/y values to provide different actions
-- based on the coordinates of the touch event reative to the x/y size of the button image.
-- Edited by E. Gonenc, pixelenvision.com
--
-- Version 2.4
-- isActive state enhanced to button can be enabled/disabled without checking current isActive state with if-then.
-- ie. btn.isActive = true (Default state, button is enabled) btn.isActive = false (button is disabled, no animation and action)
-- Edited by E. Gonenc, pixelenvision.com
 
local M = {}
 
-------------
-- convenience test functions added by Frank.
 
local coronaMetaTable = getmetatable(display.getCurrentStage())
 
--- Test function that returns whether object is a Corona display object.
-- Note that all Corona types seem to share the same metatable...
local isDisplayObject = function(o)
return type(o) == "table" and getmetatable(o) == coronaMetaTable
end
 
-----------------
-- Helper function for newButton utility function below
local function newButtonHandler( self, event )
 
local result = true
 
local default = self[1]
local over = self[2]
local txt1,txt2,txt3
 
local OX,OY,SX,SY,SM
if self[3] then txt1 = self[3] end
if self[4] then txt2 = self[4] end
if self[5] then txt3 = self[5] end
if txt1 or txt2 or txt3 then
  if display.contentScaleX < 1.0 or display.contentScaleY < 1.0 then SM = 2 else SM = 1 end
  OX,OY = (over.xScale/default.xScale),(over.yScale/default.yScale)
  SX,SY = (default.xScale/over.xScale),(default.yScale/over.yScale)
end
 
-- General "onEvent" function overrides onPress and onRelease, if present
local onEvent = self._onEvent
 
local onPress = self._onPress
local onRelease = self._onRelease
 
local buttonEvent = {}
if (self._id) then
  buttonEvent.id = self._id
end
buttonEvent.isActive = self.isActive
buttonEvent.target = self
local phase = event.phase
if self.isActive then
  if "began" == phase then
    if over then
      default.isVisible = false
      over.isVisible = true
      if txt1 then txt1:scale(OX,OY);txt1.alpha = over.alpha end
      if txt2 then txt2:scale(OX,OY);txt2.alpha = over.alpha end
      if txt3 then txt3:scale(OX,OY);txt3.alpha = over.alpha end
    end
 
    if onEvent then
      buttonEvent.phase = "press"
      buttonEvent.x = event.x - self.contentBounds.xMin
      buttonEvent.y = event.y - self.contentBounds.yMin
      result = onEvent( buttonEvent )
    elseif onPress then
      result = onPress( event )
    end
 
    -- Subsequent touch events will target button even if they are outside the contentBounds of button
    display.getCurrentStage():setFocus( self, event.id )
    self.isFocus = true
 
  elseif self.isFocus then
    local bounds = self.contentBounds
    local x,y = event.x,event.y
    local isWithinBounds =
    bounds.xMin = x and bounds.yMin = y
 
    if "moved" == phase then
      if over then
        -- The rollover image should only be visible while the finger is within button's stageBounds
        default.isVisible = not isWithinBounds
        over.isVisible = isWithinBounds
        if txt1 and not isWithinBounds and txt1.xScale*SM == OX then txt1:scale(SX,SY);txt1.alpha = default.alpha
      elseif txt1 and isWithinBounds and txt1.xScale*SM ~= OX then txt1:scale(OX,OY);txt1.alpha = over.alpha end
        if txt2 and not isWithinBounds and txt2.xScale*SM == OX then txt2:scale(SX,SY);txt2.alpha = default.alpha
      elseif txt2 and isWithinBounds and txt2.xScale*SM ~= OX then txt2:scale(OX,OY);txt2.alpha = over.alpha end
        if txt3 and not isWithinBounds and txt3.xScale*SM == OX then txt3:scale(SX,SY);txt3.alpha = default.alpha
      elseif txt3 and isWithinBounds and txt3.xScale*SM ~= OX then txt3:scale(OX,OY);txt3.alpha = over.alpha end
      end
 
    elseif "ended" == phase or "cancelled" == phase then
      if over then
        default.isVisible = true
        over.isVisible = false
        if txt1 and txt1.xScale*SM == OX then txt1:scale(SX,SY);txt1.alpha = default.alpha end
        if txt2 and txt2.xScale*SM == OX then txt2:scale(SX,SY);txt2.alpha = default.alpha end
        if txt3 and txt3.xScale*SM == OX then txt3:scale(SX,SY);txt3.alpha = default.alpha end
      end
 
      if "ended" == phase then
        -- Only consider this a "click" if the user lifts their finger inside button's stageBounds
        if isWithinBounds then
          if onEvent then
            buttonEvent.phase = "release"
            buttonEvent.x = event.x - bounds.xMin
            buttonEvent.y = event.y - bounds.yMin
            result = onEvent( buttonEvent )
          elseif onRelease then
            result = onRelease( event )
          end
        end
      end
 
      -- Allow touch events to be sent normally to the objects they "hit"
      display.getCurrentStage():setFocus( self, nil )
      self.isFocus = false
    end
  end
end
return true
 
end
 
---------------
-- Button class
 
local function newButton( params )
local button, defaultSrc , defaultX , defaultY , overSrc , overX , overY , overScale , overAlpha , size, font, textColor, offset
 
local sizeDivide = 1
local sizeMultiply = 1
 
if display.contentScaleX < 1.0 or display.contentScaleY < 1.0 then
  sizeMultiply = 2
  sizeDivide = 0.5
end
 
if params.defaultSrc then
  button = display.newGroup()
  if isDisplayObject(params.defaultSrc) then
    default = params.defaultSrc
  else
    default = display.newImageRect ( params.defaultSrc , params.defaultX , params.defaultY )
  end
  button:insert( default, false )
end
 
if params.overSrc then
  if isDisplayObject(params.overSrc) then
    over = params.overSrc
  else
    over = display.newImageRect ( params.overSrc , params.overX , params.overY )
  end
  if params.overAlpha then
    over.alpha = params.overAlpha
  end
  if params.overScale then
    over:scale(params.overScale,params.overScale)
  end
  over.isVisible = false
  button:insert( over, false )
end
 
-- Public methods
function button:setText( newText )
 
  local labelText = self.text
  if ( labelText ) then
    labelText:removeSelf()
    self.text = nil
  end
 
  local labelShadow = self.shadow
  if ( labelShadow ) then
    labelShadow:removeSelf()
    self.shadow = nil
  end
 
  local labelHighlight = self.highlight
  if ( labelHighlight ) then
    labelHighlight:removeSelf()
    self.highlight = nil
  end
 
  if ( params.size and type(params.size) == "number" ) then size=params.size else size=20 end
  if ( params.font ) then font=params.font else font=native.systemFontBold end
  if ( params.textColor ) then textColor=params.textColor else textColor={ 255, 255, 255, 255 } end
 
  size = size * sizeMultiply
 
  -- Optional vertical correction for fonts with unusual baselines (I'm looking at you, Zapfino)
  if ( params.offset and type(params.offset) == "number" ) then offset=params.offset else offset = 0 end
 
  if ( params.emboss ) then
    -- Make the label text look "embossed" (also adjusts effect for textColor brightness)
    local textBrightness = ( textColor[1] + textColor[2] + textColor[3] ) / 3
 
    labelHighlight = display.newText( newText, 0, 0, font, size )
    if ( textBrightness > 127) then
      labelHighlight:setTextColor( 255, 255, 255, 20 )
    else
      labelHighlight:setTextColor( 255, 255, 255, 140 )
    end
    button:insert( labelHighlight, true )
    labelHighlight.x = labelHighlight.x + 1.5; labelHighlight.y = labelHighlight.y + 1.5 + offset
    self.highlight = labelHighlight
 
    labelShadow = display.newText( newText, 0, 0, font, size )
    if ( textBrightness > 127) then
      labelShadow:setTextColor( 0, 0, 0, 128 )
    else
      labelShadow:setTextColor( 0, 0, 0, 20 )
    end
    button:insert( labelShadow, true )
    labelShadow.x = labelShadow.x - 1; labelShadow.y = labelShadow.y - 1 + offset
    self.shadow = labelShadow
 
    labelHighlight.xScale = sizeDivide; labelHighlight.yScale = sizeDivide
    labelShadow.xScale = sizeDivide; labelShadow.yScale = sizeDivide
  end
 
  labelText = display.newText( newText, 0, 0, font, size )
  labelText:setTextColor( textColor[1], textColor[2], textColor[3], textColor[4] )
  button:insert( labelText, true )
  labelText.y = labelText.y + offset
  self.text = labelText
 
  labelText.xScale = sizeDivide; labelText.yScale = sizeDivide
end
 
if params.text then
  button:setText( params.text )
end
 
if ( params.onPress and ( type(params.onPress) == "function" ) ) then
  button._onPress = params.onPress
end
if ( params.onRelease and ( type(params.onRelease) == "function" ) ) then
  button._onRelease = params.onRelease
end
 
if (params.onEvent and ( type(params.onEvent) == "function" ) ) then
  button._onEvent = params.onEvent
end
 
-- set button to active (meaning, can be pushed)
button.isActive = true
 
-- Set button as a table listener by setting a table method and adding the button as its own table listener for "touch" events
button.touch = newButtonHandler
button:addEventListener( "touch", button )
 
if params.x then
  button.x = params.x
end
 
if params.y then
  button.y = params.y
end
 
if params.id then
  button._id = params.id
end
 
return button
end
M.newButton = newButton
 
--------------
-- Label class
 
local function newLabel( params )
local labelText
local size, font, textColor, align
local t = display.newGroup()
 
local sizeDivide = 1
local sizeMultiply = 1
 
if ( params.bounds ) then
  local bounds = params.bounds
  local left = bounds[1]
  local top = bounds[2]
  local width = bounds[3]
  local height = bounds[4]
 
  if ( params.size and type(params.size) == "number" ) then size=params.size else size=20 end
  if ( params.font ) then font=params.font else font=native.systemFontBold end
  if ( params.textColor ) then textColor=params.textColor else textColor={ 255, 255, 255, 255 } end
  if ( params.offset and type(params.offset) == "number" ) then offset=params.offset else offset = 0 end
  if ( params.align ) then align = params.align else align = "center" end
 
  if ( params.text ) then
    labelText = display.newText( params.text, 0, 0, font, size * 2 )
    labelText.xScale = 0.5; labelText.yScale = 0.5
    labelText:setTextColor( textColor[1], textColor[2], textColor[3], textColor[4] )
    t:insert( labelText )
    -- TODO: handle no-initial-text case by creating a field with an empty string?
 
    if ( align == "left" ) then
      labelText.x = left + labelText.contentWidth * 0.5
    elseif ( align == "right" ) then
      labelText.x = (left + width) - labelText.contentWidth * 0.5
    else
      labelText.x = ((2 * left) + width) * 0.5
    end
  end
 
  labelText.y = top + labelText.contentHeight * 0.5
 
  -- Public methods
  function t:setText( newText )
    if ( newText ) then
      labelText.text = newText
 
      if ( "left" == align ) then
        labelText.x = left + labelText.contentWidth * 0.5
      elseif ( "right" == align ) then
        labelText.x = (left + width) - labelText.contentWidth * 0.5
      else
        labelText.x = ((2 * left) + width) * 0.5
      end
    end
  end
 
  function t:setTextColor( r, g, b, a )
    local newR = 255
    local newG = 255
    local newB = 255
    local newA = 255
 
    if ( r and type(r) == "number" ) then newR = r end
    if ( g and type(g) == "number" ) then newG = g end
    if ( b and type(b) == "number" ) then newB = b end
    if ( a and type(a) == "number" ) then newA = a end
 
    labelText:setTextColor( r, g, b, a )
  end
end
 
-- Return instance (as display group)
return t
 
end
M.newLabel = newLabel
 
return M

CoronaSDK Proper Orientation Rotation with Animation

August 3, 2011 CoronaSDK, Lua

This is a code I came up when learning Lua & CoronaSDK programming. Copy of the original code still available at Ansca code exchange.

It is mostly working as I wanted except a small bug. If you rotate the device while app is loading assets, there might be a small delay. I’m planning to work on an update for that as soon as our game is out…

rotationfix.lua

Lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
--]]
 
-- SET YOUR ORIENTATIONS HERE
local mainOr = "portrait"
local altOr = "portraitUpsideDown"
 
-- MASTER CODE
local stage = display.getCurrentStage( )
stage:setReferencePoint(display.CenterReferencePoint)
 
isRotated = false
local rotatefilter --function reserve
local rotatestart --function reserve
local rotatecomplete --function reserve
local curOrientation = mainOr --inital launch always match mainOr
local rota = 0
local isrotating = false
local rd = 600
 
-- iPad rotates slower
if system.getInfo("model") == "iPad" then rd = 750 end
 
function rotatefilter( )
  if (system.orientation == mainOr or system.orientation == altOr ) then
    return system.orientation
  else
    if curOrientation then return curOrientation else return mainOr end
  end
end
 
function rotatestart( val, initial )
  if isrotating == false and curOrientation ~= val then
    if val == mainOr then
      rota = 180
      curOrientation = mainOr
    elseif val == altOr then
      rota = -180
      curOrientation = altOr
    end
    isrotating = true
    if initial and rd == 750 then
      transition.to( stage, { rotation=rota, time=0, delta=true, onComplete=rotatecomplete } )
    else
      transition.to( stage, { rotation=rota, time=rd, delta=true, transition=easing.inOutQuad, onComplete=rotatecomplete } )
    end
  end
end
 
function rotatecomplete( )
  isrotating = false
  if curOrientation == altOr then isRotated = true else isRotated = false end
  if curOrientation ~= rotatefilter() then rotatestart(rotatefilter()) end
end
 
--Check initial orientation and and rotate if needed
if ( system.orientation == altOr and isrotating == false) then rotatestart(altOr,true) end
 
local function onOrientationChange( event )
  local type = event.type
  if ( type == mainOr or type == altOr ) then rotatestart(type) end
end
 
Runtime:addEventListener( "orientation", onOrientationChange )

  • Tags

    3ds Max Coming Soon CoronaSDK Featured Flash Lua MAXScript PHP Programming Reviews Tips & Tricks Unity 3D Windows Phone
  • Recent Comments

    • Yogesh Singh on ZIP (POSTAL) Code Validation Regex & PHP code for 12 Countries
    • Admin on Maxscript – Vray Cubemap Generator for Unity
    • charlie on Maxscript – Vray Cubemap Generator for Unity
    • Mastan on PHP Currency Converter
    • Rakesh Vishnoi on ZIP (POSTAL) Code Validation Regex & PHP code for 12 Countries
    • Find us on

      amazonandroidapplefacebooklinkedintwitterwindowsyoutube
    • Company Information

      Lytchett House, 13 Freeland Park, Wareham Road, Poole, Dorset, BH16 6FA

      Pixel Envision Limited is a company registered in England, company number: 09558675. Registered Office: Preston Park House, South Road, Brighton, East Sussex, BN1 6SB, United Kingdom

    • Privacy Policy
    Copyright © 2011-2021 Pixel Envision Ltd, all rights reserved.