Hello, I have a problem with moveSpriteTo (at least i think this is where the issue is)
I am moving to waypoints to navigate around my map but have an issue, when the sprite reaches a waypoint it pauses before moving to the next waypoint. I need it to go to each waypoint with no pauses. I have put a quick demo together of what is happening. I would be really grateful if somebody could give some advice on how to solve this, thanks!
display.setStatusBar(display.HiddenStatusBar); -- lime = require("lime.lime") local mte = require ("mte") local physics = require ("physics") --Require the physics library.. physics.start() physics.setGravity( 0, 0 ) --Set gravity to 0 and start the physics. local enemies = {} local waypoint = {} local mRound = math.round -- display.setDefault( "magTextureFilter", "nearest" ) -- display.setDefault( "minTextureFilter", "nearest" ) system.activate("multitouch") --LOAD MAP ----------------------------------------------------------------------------- mte.loadMap("pluto") local blockScale = 32 local locX = 10 local locY = 24 mte.goto({locX = 1, locY = 10, blockScale = 30}) mte.constrainCameraToScreen({ edges = {true, true, true, true}, time = 50 }) mte.fadeLayer(4, 0.35, 100, "linear") local waypoints = mte.getLayers({layer = 3}) for i = #waypoints.objects, 1, -1 do local waypoint\_array = waypoints.objects[i] waypoint[i] = display.newRect(0,0,waypoint\_array.width,waypoint\_array.height) waypoint[i].name = waypoint\_array.name waypoint[i].path = waypoint\_array.properties.path waypoint[i]:setFillColor(0,255,0) -- waypoint[i].alpha = 0.01 local setup = { kind = "sprite", layer = mte.getSpriteLayer(1), levelPosX = waypoint\_array.x, levelPosY = waypoint\_array.y, levelWidth = 15, levelHeight = 15, } mte.addSprite(waypoint[i], setup) end --CREATE AN ENEMY ----------------------------------------------------------------------------- local enemy = display.newRect(0,0, 24, 24) enemy.name = "enemy"; enemy.movPoint = "WP1" --Used in the gameloop physics.addBody(enemy, { isSensor = true } ) --Make it a physics sensor. local setup = { kind = "sprite", layer = mte.getSpriteLayer(1), levelPosX = 150, levelPosY = 0, levelWidth = 15, levelHeight = 15, } table.insert( enemies, enemy) mte.addSprite(enemy, setup) --GAME LOOP ----------------------------------------------------------------------------- local function gameLoopEnemyCheck( movPoint ) --All these variables are returned to the gameLoop local transDirecX, transDirecY, rect, nextPoint, rotate --Called from the below loop. Sets the rotation and translation ints. local function getDirect( moveArray ) transDirecX = moveArray.levelPosX transDirecY = moveArray.levelPosY end --Loop through each part of the movArray that we create in the Level.lua files. --This calls the above function as well to set some vars. local i for i=1, #waypoint-1 do if movPoint == "WP"..i then rect = waypoint[i] getDirect(waypoint[i]) nextPoint = "WP"..i+1 elseif movPoint == "ep" then rect = waypoint[i] getDirect(waypoint[i]) nextPoint = "ep" end end --Return it all to the gameLoop so we know where to move the enemy etc. return transDirecX, transDirecY, rect, nextPoint, rotate end local function gameLoop(event) mte.update() for i = #enemies,1,-1 do local enemy = enemies[i] if enemy ~= nil and enemy.x ~= nil then local transDirecX, transDirecY, rect, nextPoint, rotate = gameLoopEnemyCheck(enemy.movPoint) mte.moveSpriteTo({sprite = enemy, levelPosX = transDirecX, levelPosY = transDirecY, time = 2000, easing = "linear"}) if rect.levelPosX == mRound(enemy.levelPosX) and rect.levelPosY == mRound(enemy.levelPosY) then enemy.movPoint = nextPoint end end end end Runtime:addEventListener( "enterFrame", gameLoop )