Giter Club home page Giter Club logo

magnet's Introduction

Magnet

Screenshots of Magnet functionality in portrait and landscape

Position Helper for Corona SDK Graphics 2.0

A module to position display objects on different screen resolutions. This helper will only work with the newest version of Corona (aka 2.0). Anchors and screen orientations are internally managed to provide consistency.

Recent changes:

  • Storyboard replaced with Composer API
  • Refreshed build.settings with portrait orientation as a default
  • Removed all print() logs

Positioning

To position you just call the function and pass the displayObject

magnet:topLeft( displayObject )

Margins

If you need to have a margin of 10px from the left this is how you do it:

magnet:topLeft( displayObject, 10 )

or same as before but with 20 px from the top:

magnet:topLeft( displayObject, 10, 20)

If you want to reposition after a screen rotation all you need to do is call the following function on the orientation event:

magnet:updateCurrentOrientation()

Basic Alignments

magnet:top(obj, marginY)
magnet:right(obj, marginX)
magnet:bottom(obj, marginY)
magnet:left(obj, marginX)
magnet:center(obj, marginX, marginY)

Composed Alignments

magnet:topLeft(obj, marginX, marginY)
magnet:topRight(obj, marginX, marginY)
magnet:bottomLeft(obj, marginX, marginY)
magnet:bottomRight(obj, marginX, marginY)
magnet:topCenter(obj, marginX, marginY)
magnet:centerRight(obj, marginX, marginY)
magnet:bottomCenter(obj, marginX, marginY)
magnet:centerLeft(obj, marginX, marginY)

Generic Call

Or a generic call with the align as a parameter:

magnet:alignTo(sAlign, obj, ...)

where sAlign is the method name in a string like:

magnet("bottomRight", myObject, xMargin, yMargin)

Other utilities

magnet:getPercentX( percent )
magnet:getPercentY( percent )

Gotchas

When positioning display objects inside snapshots you'll need to provide an additional parameter "parent" as the current snapshot that contains it. Otherwise it won't work!

local snapshot = display.newSnapshot(width, height)
local circle = display.newCircle(snapshot.group, 0, 0, 10)
magnet:center(circle, 0, 0, snapshot) --add the parent

magnet's People

Contributors

lomza avatar

Watchers

James Cloos avatar  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.