Hello, I am using Tiled to create maps for Corona and when I center the map to center of screen with this piece of code
map.x,map.y = display.contentCenterX - map.designedWidth/2, display.contentCenterY - map.designedHeight/2
then objects collision area stays on its original position as shown on images.
Here is my code.
----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- local tiled = require "com.ponywolf.ponytiled" local physics = require "physics" physics.setDrawMode("hybrid") physics.start() physics.setGravity( 0, 0 ) local json = require "json" -- Hide the status bar display.setStatusBar( display.HiddenStatusBar ) local strokes = 5 local strokesText local ballSize = 12 -- Set up display groups local ballGroup = display.newGroup() local backGroup = display.newGroup() local mainGroup = display.newGroup() local uiGroup = display.newGroup() --Load background local background = display.newImageRect( backGroup, "texture/background/background.jpg", 1080 , 1920 ) background.x = display.contentCenterX background.y = display.contentCenterY local mapData = json.decodeFile(system.pathForFile("map.json", system.ResourceDirectory)) -- load from json export --Load map local map = tiled.new(mapData) map.x,map.y = display.contentCenterX - map.designedWidth/2, display.contentCenterY - map.designedHeight/2 --Get array of wall objects local walls\_vert = map:listTypes( "wall\_vert" ) --Add ball local ball = display.newCircle(ballGroup, display.contentCenterX, display.contentCenterY, ballSize ) ballGroup:toFront() --Add ball to physics physics.addBody( ball, "dynamic", { radius=ballSize, isSensor=false, bounce=0.6, density = 10 } ) ball.myName = "ball" ball.linearDamping = 1 --Add walls to physics -- Display strokes left strokesText = display.newText( uiGroup, "Strokes: " .. strokes, display.contentCenterX, 80, native.systemFont, 36 ) --Function that moves ball depending on touch start and release local begX local begY local endX local endY local finX local finY local function stroke(event) if ( event.phase == "began" ) then print( "Touch event began on: " .. event.x .. " " .. event.y ) begX = event.x begY = event.y elseif event.phase == "moved" then --print( "Touch event moved on: " .. event.x .. " " .. event.y ) elseif event.phase == "ended" then endX = event.x endY = event.y finX = begX - endX finY = begY - endY ball:applyLinearImpulse( finX \* 0.5, finY \* 0.5, ball.x, ball.y ) print( "Touch event ended on: " .. event.x .. " " .. event.y ) end --transition.to( ball, { linearDamping = 0.7, time = 250 } ) end backGroup:addEventListener( "touch", stroke )
Any suggestions how to fix this issue?
Thank you in advance