Created
February 13, 2014 21:21
-
-
Save elmogallen/8984095 to your computer and use it in GitHub Desktop.
Make stuff stick to the top or bottom of the screen in Corona SDK.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Putting a rectangle at the bottom of the screen and having it expand | |
-- all the way across the screen, like a status bar. | |
-- Important to note: I'm using "Letterbox" mode in my config.lua | |
local actualBottomY = display.contentHeight - display.screenOriginY | |
local actualTopY = display.screenOriginY | |
local deviceWidth = ( display.contentWidth - (display.screenOriginX * 2) ) / display.contentScaleX | |
local scaleFactor = deviceWidth / display.actualContentWidth | |
local actualWidth = (deviceWidth / scaleFactor) | |
local actualLeftX = (display.contentWidth - actualWidth) * .5 | |
print ("screenOriginY:", display.screenOriginY) | |
print ("actualBottomY:", actualBottomY) | |
print ("actualTopY:", actualTopY) | |
print ("deviceWidth:", deviceWidth) | |
print ("scaleFactor:", scaleFactor ) | |
print ("actualWidth:", actualWidth) | |
print ("actualContentWidth:", display.actualContentWidth) | |
print ("actualLeftX:", actualLeftX) | |
local topRect = display.newRect( 0, 0, actualWidth, 40) | |
topRect.anchorX = .5 | |
topRect.anchorY = 0 | |
topRect.x = halfW | |
topRect.y = actualTopY | |
topRect:setFillColor( 0, 0, 1) | |
topRect.strokeWidth = 2 | |
topRect:setStrokeColor( 1 ) | |
group:insert (topRect) | |
local bottomRect = display.newRect( 0, 0, actualWidth, 40) | |
bottomRect.anchorX = .5 | |
bottomRect.anchorY = 1 | |
bottomRect.x = halfW | |
bottomRect.y = actualBottomY | |
bottomRect:setFillColor( 1, 0, 0) | |
bottomRect.strokeWidth = 2 | |
bottomRect:setStrokeColor( 1 ) | |
group:insert (bottomRect) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment