Issues with toggleWorldWrap

My project is not displaying correctly when I use toggleWorldWrapX and toggleWorldWrapY. It seems fine when I turn it off though. I’ve tried everything I know, can you guys take a look?

Attached are screenshots of what it looks like when toggleWorldWrapX and toggleWorldWrapY are set to true. Parts of the map flicker on and off as the player moves around (the black is not supposed to be there…)

My code:

[lua]

display.setStatusBar( display.HiddenStatusBar )

local storyboard = require( “storyboard” )

local scene = storyboard.newScene()

local mte = require(“MTE.mte”).createMTE()

local json = require “json”

system.activate( “multitouch” )

local moveTime = 300

local holding = false;

local angle = nil    

– FUNCTIONS

local isSolid = function(level, levelPosX, levelPosY)

    local tileX = mte.levelToLocX(levelPosX)

    local tileY = mte.levelToLocX(levelPosY)

    local tiles = mte.getTileProperties({level = level, locX = tileX, locY = tileY})

    for i = 1, #tiles, 1 do

        if tiles[i].properties then

            if tiles[i].properties.solid then

                return true

            end

        end

    end

end

– Rounds a number to given decimal places

function round(num, idp)

    local mult = 10^(idp or 0)

    return math.floor( num * mult + 0.5 ) / mult

end

– Handler for Dpad touches.

local function dPadTouchHandler( event )

    if event.phase == “began” then

        display.getCurrentStage():setFocus(event.target, event.id)

        event.target.isFocus = true

    end

    if event.phase == “began” or event.phase == “moved” then

        holding = true

        local dirX = event.x - event.target.x – Calculates the distance between the touch point and the centre of the Dpad

        local dirY = event.y - event.target.y – "

        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

        --angle = round(angle, 0) – Round to integer

    elseif event.phase == “ended” or event.phase == “cancelled” then

        holding = false

        display.getCurrentStage():setFocus( event.target, nil )

        event.target.isFocus = false

    end

    return true

end

local function gameLoop( event )

    – Move player

    local destX = nil

    local destY = nil

    if holding then

        local radAngle = math.rad(angle) – Convert to radians

        local lengthX = 30 * math.sin(radAngle)

        local lengthY = -30 * math.cos(radAngle)

        destX = round(player.x + lengthX, 0)

        destY = round(player.y + lengthY, 0)

    else

        angle = nil

        destX = nil

        destY = nil

    end

        player.rotation = angle + 90 --Rotate the sprite to face the correct direction

        local tileSolid = isSolid( player.level, destX, destY)

        if tileSolid then

            player:pause()

        else

            player:play()

            mte.moveSpriteTo( { sprite = player, levelPosX = destX, levelPosY = destY, time = moveTime, easing = “linear” } )

        end

    else

        player:pause()

    end

    

    collectgarbage(“step”, 20)    

    --mte.debug()

    mte.update()

end

– STORYBOARD

function scene:willEnterScene( event )

    local screenGroup = self.view

    mte.toggleWorldWrapX(true)

    mte.toggleWorldWrapY(true)

     mte.loadTileSet(“complete white house”, “map/completewhitehouse.bmp”);

     mte.loadTileSet(“green”, “map/green.bmp”);

     mte.loadMap(“map/bedfield”);

    mte.setCamera({locX = 5, locY = 5, blockScale = 32})

    --Load player sprite

    local spriteSheet = graphics.newImageSheet(“sprites/player.png”, {width = 30, height = 30, numFrames = 4})

    local sequenceData = {

            name = “walk”, 

            start = 1,  

            count = 4,  

            time = 500,  

            loopCount = 0,

            loopDirection = “forward”

    }

    player = display.newSprite(spriteSheet, sequenceData)

    local setup = {

        kind = “sprite”, 

        locX = locX, 

        locY = locY, 

        layer =  mte.getSpriteLayer(1),

        levelWidth = 30, 

        levelHeight = 30,

        name = “player”

    }

    mte.addSprite(player, setup); --adds sprite to the map

    mte.setCameraFocus(player); --sets the camera to follow this sprite

    screenGroup:insert(mte.getMapObj())    

    --Setup D-pad

    Dpad = display.newImageRect(screenGroup, “Dpad.png”, 100, 100)

    Dpad.x = 60

    Dpad.y = display.viewableContentHeight - 60

    Dpad:toFront()

    Dpad:addEventListener(“touch”, dPadTouchHandler)

end

function scene:enterScene( event )

    local screenGroup = self.view

    Runtime:addEventListener(“enterFrame”, gameLoop) – Runs at 30 or 60 FPS (set in config.lua)

end

function scene:exitScene( event )

    local group = self.view

end

function scene:destroyScene( event )

    local group = self.view

    mte.cleanup()

end

scene:addEventListener( “willEnterScene”, scene )

scene:addEventListener( “enterScene”, scene )

scene:addEventListener( “exitScene”, scene )

scene:addEventListener( “destroyScene”, scene )

return scene

[/lua]

Hello Agor8684,

If you’d like to email the project to me I can investigate from my end. This would be much quicker than if we tried to troubleshoot the problem over the forum. 

Out of curiosity Dyson, what was the issue with this one?

Thanks. :slight_smile:

Agor hasn’t sent me his project files, so I can’t say for certain. This is one of those problems I haven’t run into before and haven’t been able to duplicate.

Hello Agor8684,

If you’d like to email the project to me I can investigate from my end. This would be much quicker than if we tried to troubleshoot the problem over the forum. 

Out of curiosity Dyson, what was the issue with this one?

Thanks. :slight_smile:

Agor hasn’t sent me his project files, so I can’t say for certain. This is one of those problems I haven’t run into before and haven’t been able to duplicate.