MorphingLabel

426
Vote up!

MorphingLabel is a simple module to easily allow you to animate changing a label's text. It works by duplicating the text object and crossfading/scaling between the old and new text for a seamless look.

Example morph gif

Usage

local MorphingLabel = require "MorphingLabel"

local label = MorphingLabel.newLabel {
    text = "Morphing",
    x = 128, y = 128,
    font = native.systemFont,
    fontSize = 32,
}

label:setFillColor(1.0, 0.0, 0.0)
label:morphText("Label", 500)
label:setFillColor(1.0, 0.0, 1.0)

label:morphText accepts two parameters: the text to change to, and the duration of the transition in ms (optional). To animate the color change, call label:setFillColor immediately after label:morphText.

Caveats

  • Use setFillColor's 4th parameter if you want to control transparency of the object directly (label.alpha is used for the animation).
  • Works best with single line text
  • Scaling the text might break the animation
Works with Corona build #: 
2014.2511
Category: 
Contributor: 
Kyle Coburn