Hey
if I run this isometric game from the tutorial with a bigger tile map (50 x 50) its totally smooth, but if I just copy a snippet of the code (creates the right dpad to move the map) into my app and run the same map… its laggy.
Please can you tell me what I have to consider? Do I have to learn more about display.groups?
I have both versions to compare attached. Please help me. I have a game idea and some nice graphics are ready …I’m just struggling with the isometric setup
Cheers
edit: here is the tutorial http://anthonygore.com/blog/?p=92 and I added the file
local composer = require( "composer" ) local scene = composer.newScene() local physics = require("physics") physics.start() physics.setGravity(0, 0) -------------------------------------------- -- forward declarations and other locals local screenW, screenH, halfW = display.contentWidth, display.contentHeight, display.contentWidth\*0.5 levelNum = 2 function scene:create( event ) gridmap = require("gridmap") mapData = require "map2" --assumes file is in root dir and named map1.lua mapWidth = mapData.width - 4 --Subtract the borders mapHeight = mapData.height - 4 --Subtract the borders tileWidth = mapData.tilewidth tileHeight = mapData.tileheight -- Called when the scene's view does not exist. -- -- INSERT code here to initialize the scene -- e.g. add display objects to 'sceneGroup', add touch listeners, etc. local sceneGroup = self.view --Functions function angleToDir (angle) local x, y = 0, 0 if (angle \>= 315 and angle \<= 360) or (angle \>= 0 and angle \< 45) then --North x = 0 y = -1 elseif angle \>= 45 and angle \< 135 then --East x = 1 y = 0 elseif angle \>= 135 and angle \< 225 then --South x = 0 y = 1 else --West x = -1 y = 0 end return x,y end local function mapOffset(x, y) for i = 1, #mapData.layers do if mapData.layers[i].type == "tilelayer" then mapData.layers[i].x = mapData.layers[i].x - x mapData.layers[i].y = mapData.layers[i].y - y end end --Remove the map and redraw map:removeSelf() map = gridmap:createMap(mapData) sceneGroup:insert(1, map) end --A wrapper for mapOffset when using the Dpad to move it function moveMap(angle) local x, y = angleToDir(angle) mapOffset(x, y) --Remove the map and redraw map:removeSelf() map = gridmap:createMap(mapData) sceneGroup:insert(1, map) end -------- map = gridmap:createMap(mapData) local group = display.newGroup() sceneGroup:insert(1, map) mapOffset(-10,5) end local Dpad = display.newImageRect("dpad.png", 100, 100) Dpad.x = 50 Dpad.y = 50 Dpad.holding = false Dpad.angle = nil Dpad:toFront() --DpadR -- DpadR = createDPad(display.contentWidth - 50, display.contentHeight -50) Dpad.direction = nil Dpad.getRotationAngle = function (begX, begY, endX, endY) local dirX = begX - endX local dirY = begY - endY local angle = math.deg(math.atan(dirY/dirX)) if dirX \< 0 then angle = 90 + (90 - (angle \* -1)) end angle = angle + 90 if angle == 360 then angle = 0 end return angle end --DpadR function Dpad:touch (event) if event.phase == "began" then display.getCurrentStage():setFocus(event.target, event.id) event.target.isFocus = true end if event.phase == "ended" or event.phase == "cancelled" then moveMap(self.getRotationAngle(event.x, event.y, event.target.x, event.target.y)) display.getCurrentStage():setFocus( event.target, nil ) event.target.isFocus = false end return true end Dpad:addEventListener("touch", Dpad) function createDPad (x,y) local Dpad = display.newImageRect("dpad.png", 100, 100) Dpad.x = x Dpad.y = y Dpad.holding = false Dpad.angle = nil Dpad:toFront() return Dpad end UIgroup = display.newGroup() UIgroup:insert(Dpad) function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "will" then -- Called when the scene is still off screen and is about to move on screen elseif phase == "did" then -- Called when the scene is now on screen -- -- INSERT code here to make the scene come alive -- e.g. start timers, begin animation, play audio, etc. physics.start() end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if event.phase == "will" then -- Called when the scene is on screen and is about to move off screen -- -- INSERT code here to pause the scene -- e.g. stop timers, stop animation, unload sounds, etc.) physics.stop() elseif phase == "did" then -- Called when the scene is now off screen end end function scene:destroy( event ) -- Called prior to the removal of scene's "view" (sceneGroup) -- -- INSERT code here to cleanup the scene -- e.g. remove display objects, remove touch listeners, save state, etc. local sceneGroup = self.view package.loaded[physics] = nil physics = nil end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) ----------------------------------------------------------------------------------------- return scene