Giter VIP home page Giter VIP logo

hump.timer.actions's Introduction

hump.timer.actions Build Status

Composable actions, powered by hump.timer. Inspired by LibGDX actions. Represents a monoid. This approach also lends itself to manipulation by higher order functions (similar to parser combinators).

Example

local Actions = require "actions"
local Timer = require "hump.timer"

local objectA = {val = 0}, objectB = {val = 0}
local action = Actions.Sequence(
	Actions.Print("Started action..."),
	Actions.Wait(3),
	Actions.Print("3 seconds passed..."),
	Actions.Parallel(
		Actions.Tween(3.0, objectA, {val=10}, 'linear'),
		Actions.Tween(2.0, objectB, {val=10}, 'linear')
	)
)

--[[ Play the action by calling it as a function.
The first argument is the Hump.Timer object used to run
events, and the second argument is a continuation to
be run on the completion of the action. ]]--
action(Timer, function()
	print("Continuation...")
end)

Documentation

Action Primitives

These functions return actions that, when played, will do something.

Actions.Empty()

An empty 'identity' action which does nothing.

Actions.Wait(duration)

An action which waits for the provided amount of seconds.

Actions.Do(func)

An action which invokes the provided function, then continues.

Actions.Print(func)

An action which prints to the console.

Actions.Tween(duration, subject, target, method, ...)

Tweens an object. See Timer.tween for more details.

Combinators

Combinators take in actions, compose them, and return new actions that can be further composed.

Actions.Sequence(...)

Takes in a variable number of actions, and returns a new action which plays them all in sequence.

Actions.Parallel(...)

Takes in a variable number of actions, and returns a new action which plays them all in parallel. The continuation is invoked when

Creating a Custom Action Primitive

Part of what makes this approach effective is that you can create your own Action primitives. Here are some examples.

function Actions.PlaySource(source)
  return function(timer, cont)
    love.audio.play(source)
    cont()
  end
end

function Actions.DestroyEntity(entity)
  return function(timer, cont)
    entity:destroy()
    cont()
  end
end

hump.timer.actions's People

Contributors

rameshvarun avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.