It looks like you're new here. If you want to get involved, click one of these buttons!
--[[-----------------------------------------]]-- --[[ Gideros resolution/aspect ratio example ]]-- --[[ Made by rolfpancake ]]-- --[[ Licence CC0 ]]-- --[[-----------------------------------------]]-- --[[------------------------------------]]-- --[[ Functions and application settings ]]-- --[[------------------------------------]]-- -- We need a function for colors (thanks to evs) local function rgbToColor(r, g, b) local hex = r * 65536 + g * 256 + b return hex end -- We set our aspect ratio (same as project properties) application:setLogicalDimensions(480, 800) -- Set Orientation by number (just for testing purposes) local orientations = { "portrait", "portraitUpsideDown", "landscapeLeft", "landscapeRight" } application:setOrientation(orientations[1]) -- 1 -> portrait -- Set ScaleMode by number (just for testing purposes) local scalemodes = { "noScale", "center", "pixelPerfect", "letterbox", "crop", "stretch", "fitWidth", "fitHeight" } application:setScaleMode(scalemodes[4]) -- 4 -> letterbox --[[--------------------------------]]-- --[[ Dimensions and other variables ]]-- --[[--------------------------------]]-- -- Logical dimensions local WIDTH = application:getContentWidth() local HEIGHT = application:getContentHeight() -- DX and DY (thanks ar2rsawseen, read his article on <a href="http://appcodingeasy.com" rel="nofollow">http://appcodingeasy.com</a>) local DX = application:getLogicalTranslateX() / application:getLogicalScaleX() local DY = application:getLogicalTranslateY() / application:getLogicalScaleY() -- Screen Coordinates (X = Horizontal, Y = Vertical) local Screen = { LEFT = -DX, RIGHT = DX + WIDTH, TOP = -DY, BOTTOM = DY + HEIGHT, CENTER_X = WIDTH / 2, CENTER_Y = HEIGHT / 2 } -- Shape dimensions local Rect = {WIDTH = 100, HEIGHT = 100} -- Change the background. Pro-Tip: Don't use 240,240,240 <img class="emoji" src="https://forum.gideros.rocks/resources/emoji/lol.png" title=":D" alt=":D" height="20" /> application:setBackgroundColor(rgbToColor(210, 200, 190)) --[[------------------------]]-- --[[ The rect in the center ]]-- --[[------------------------]]-- -- Init the middle shape local midshape = Shape.new() -- Set its color midshape:setFillStyle(Shape.SOLID, rgbToColor(66, 99, 132), 1) -- Draw a beautiful rect midshape:beginPath() midshape:moveTo(0, 0) midshape:lineTo(Rect.WIDTH, 0) midshape:lineTo(Rect.WIDTH, Rect.HEIGHT) midshape:lineTo(0, Rect.HEIGHT) midshape:lineTo(0, 0) midshape:endPath() -- Add that shape to the stage stage:addChild(midshape) -- Push the shape to the center midshape:setPosition(Screen.CENTER_X - Rect.WIDTH/2, Screen.CENTER_Y - Rect.HEIGHT/2) --[[------------------------]]-- --[[ A rect for each corner ]]-- --[[------------------------]]-- -- Create 4 shapes and add them to stage local cornershapes = {} for i=1, 4 do -- Init the shape cornershapes[i] = Shape.new() -- Set color depending on the current shape cornershapes[i]:setFillStyle(Shape.SOLID, rgbToColor(i*60, i*45, i*35), 1) -- Draw a beautiful rect cornershapes[i]:beginPath() cornershapes[i]:moveTo(0, 0) cornershapes[i]:lineTo(Rect.WIDTH, 0) cornershapes[i]:lineTo(Rect.WIDTH, Rect.HEIGHT) cornershapes[i]:lineTo(0, Rect.HEIGHT) cornershapes[i]:lineTo(0, 0) cornershapes[i]:endPath() -- Add that shape to the stage stage:addChild(cornershapes[i]) end -- Push the shapes to the corners cornershapes[1]:setPosition(Screen.LEFT, Screen.TOP) -- topleft cornershapes[2]:setPosition(Screen.RIGHT - Rect.WIDTH, Screen.TOP) -- topright cornershapes[3]:setPosition(Screen.LEFT, Screen.BOTTOM - Rect.HEIGHT) -- bottomleft cornershapes[4]:setPosition(Screen.RIGHT - Rect.WIDTH, Screen.BOTTOM - Rect.HEIGHT) -- bottomright --[[------------------------------------]]-- --[[ Console log for debugging purposes ]]-- --[[------------------------------------]]-- ---[[ print("\n========== Testing ==========") print("BackgroundColor: " .. application:getBackgroundColor()) print("ScaleMode: " .. application:getScaleMode()) print("Orientation: " .. application:getOrientation()) print("DeviceWidth: " .. application:getDeviceWidth()) print("DeviceHeight: " .. application:getDeviceHeight()) print("Device aspectratio (W:H): " .. application:getDeviceWidth() / application:getDeviceHeight()) print("Logical WIDTH: " .. WIDTH) print("Logical HEIGHT: " .. HEIGHT) print("Logical aspectratio (W:H): " .. WIDTH / HEIGHT) print("DX: " .. DX) print("DY: " .. DY) print("Screen.LEFT: " .. Screen.LEFT) print("Screen.RIGHT: " .. Screen.RIGHT) print("Screen.TOP: " .. Screen.TOP) print("Screen.BOTTOM: " .. Screen.BOTTOM) print("Screen.CENTER_X: " .. Screen.CENTER_X) print("Screen.CENTER_Y: " .. Screen.CENTER_Y) print("=============================\n") --]] |