It looks like you're new here. If you want to get involved, click one of these buttons!
application:setScaleMode("letterbox") contentWidth = application:getContentWidth() contentHeight = application:getContentHeight() logicalTranslateX = application:getLogicalTranslateX() logicalTranslateY = application:getLogicalTranslateY() logicalScaleX = application:getLogicalScaleX() logicalScaleY = application:getLogicalScaleY() logicalScreenLeft = -logicalTranslateX / logicalScaleX logicalScreenTop = -logicalTranslateY / logicalScaleY logicalScreenWidth = contentWidth + logicalTranslateX / logicalScaleX * 2 logicalScreenHeight = contentHeight + logicalTranslateY / logicalScaleY * 2 print("logicalScreenHeight =", logicalScreenHeight) print("logicalScreenWidth =", logicalScreenWidth) worldWidth = logicalScreenWidth * 1.4 local size = logicalScreenHeight * 0.5 local myWindow = Shape.new() myWindow:setLineStyle(2) myWindow:setFillStyle(Shape.SOLID, 0xff00ff) myWindow:beginPath() myWindow:moveTo(logicalScreenLeft,logicalScreenTop) myWindow:lineTo(worldWidth,logicalScreenTop) myWindow:lineTo(worldWidth,logicalScreenHeight) myWindow:lineTo(logicalScreenLeft,logicalScreenHeight) myWindow:lineTo(logicalScreenLeft,logicalScreenTop) myWindow:endPath() stage:addChild(myWindow) myWindow:setPosition(0,0) -- left hand guide triangle local myShape = Shape.new() myShape:setLineStyle(2) myShape:setFillStyle(Shape.SOLID, 0x0000ff) myShape:beginPath() myShape:moveTo(logicalScreenLeft,logicalScreenTop) myShape:lineTo(size,logicalScreenTop) myShape:lineTo(logicalScreenLeft,size) myShape:lineTo(logicalScreenLeft, logicalScreenTop) myShape:endPath() myWindow:addChild(myShape) -- right hand guide triangle local myShape2 = Shape.new() myShape2:setLineStyle(2) myShape2:setFillStyle(Shape.SOLID, 0x0000ff) myShape2:beginPath() myShape2:moveTo(worldWidth-size,logicalScreenTop) myShape2:lineTo(worldWidth,logicalScreenTop) myShape2:lineTo(worldWidth,logicalScreenTop+size) myShape2:lineTo(worldWidth-size,logicalScreenTop) myShape2:endPath() myWindow:addChild(myShape2) -- guide line to show whether full triangle is in view local myLine = Shape.new() myLine:setLineStyle(2) myLine:setFillStyle(Shape.SOLID, 0x0000ff) myLine:beginPath() myLine:moveTo(logicalScreenLeft, size) myLine:lineTo(worldWidth, size) myLine:endPath() myWindow:addChild(myLine) myWindow:setScale(0.9) -- change this to see right hand align breaking local function boundX(x) local scale = myWindow:getScaleX() local lhs = (1 - scale) * logicalScreenLeft -- this works to bound x value to lhs --TODO: fix right hand side bounds to work with scaling (perfect at 1) local rhs = -(worldWidth - logicalScreenWidth - logicalScreenLeft) x = math.max(x, rhs) x = math.min(x, lhs) -- bounds to left side of screen at all scales print("bounded x =", x) return x end local function setPosition(x) myWindow:setX(boundX(x)) end -- now moving the sprite show that right hand side doesn't work at scales other than one -- positive value for left hand align, high negative for right hand setPosition(-10000) -- positve correctly bounds to left hand side at all scale levels -- negative only works to bound right hand side at scale = 1 |
Comments
Likes: snooks
Likes: antix