How to move sprite within map?

I’m having some difficulty placing my sprite in the map in the desired location.

I do the following, but whatever I set locX and locY to, the sprite is in the top left hand corner of the screen.

[lua]

local startX = 20

local startY = 12.9

local blockScale = 15

mte.goto({locX = startX, locY = startY, blockScale = blockScale})

local startPos = mte.getObject({name=“startPos”})

local sheetInfo = require(“Hurricane”)

local myImageSheet = graphics.newImageSheet( “Hurricane.png”, sheetInfo:getSheet() )

local hurricane = display.newSprite( myImageSheet , {name=“fly”, frames={1, 2, 3, 4, 5, 6}, time = 800} )

local setup = {

            kind = “sprite”,

            layer =  4,

            locX = startPos[1].x,

            locY = startPos[1].y,

            levelWidth = 43,

            levelHeight = 54

}

mte.addSprite(hurricane, setup)

[/lua]

It’s worth printing out startPos[1].x and startPos[1].y to see what the values are - I suspect they’re map co-ordinates and not the grid array location that AddSprite is requiring.

In which case you’ll want to see MTE’s convert function to get the correct values.

Alright so that was a mistake, but my sprite won’t move regardless of what I put into locX and locY. Is there some property on my map that I need to set, in addition to spriteLayer=true ?

Are you calling mte.update() in your enterFrame event? Until update executes the sprite will not position itself correctly on the map.

On an unrelated note, you can pass map positions as the setup parameters by using levelPosX and levelPosY instead of locX and locY, if you need pixel precision in your sprite positioning. 

Ah, didn’t realize I had to do that. Thanks Dyson!

It’s worth printing out startPos[1].x and startPos[1].y to see what the values are - I suspect they’re map co-ordinates and not the grid array location that AddSprite is requiring.

In which case you’ll want to see MTE’s convert function to get the correct values.

Alright so that was a mistake, but my sprite won’t move regardless of what I put into locX and locY. Is there some property on my map that I need to set, in addition to spriteLayer=true ?

Are you calling mte.update() in your enterFrame event? Until update executes the sprite will not position itself correctly on the map.

On an unrelated note, you can pass map positions as the setup parameters by using levelPosX and levelPosY instead of locX and locY, if you need pixel precision in your sprite positioning. 

Ah, didn’t realize I had to do that. Thanks Dyson!