I’ll get it to you ASAP. I’m just trying to track down a little stutter I think is related to timers. Anyway, this is the first map in a three-map demo it’ll come with showing off the basic functionality.
http://www.youtube.com/watch?v=Hv0EMzgr5vQ
It’s a standard retro RPG style control scheme in which the player sprite moves by exactly one block when a direction is pressed.
[code]
display.setStatusBar( display.HiddenStatusBar )
local mte = require “MTE.mte”
local json = require(“json”)
local DpadBack = display.newImageRect(“Dpad.png”, 200, 200)
DpadBack.x = 120
DpadBack.y = display.viewableContentHeight - 120
local DpadUp = display.newRect(DpadBack.x - 37, DpadBack.y - 100, 75, 75)
local DpadDown = display.newRect(DpadBack.x - 37, DpadBack.y + 25, 75, 75)
local DpadLeft = display.newRect(DpadBack.x - 100, DpadBack.y - 37, 75, 75)
local DpadRight = display.newRect(DpadBack.x + 25, DpadBack.y - 37, 75, 75)
mte.loadMap(“map/Demo.json”, “Resource”)
mte.goto({ locX = 30, locY = 106, blockScale = 64 })
local spriteSheet = graphics.newImageSheet(“spriteSheet.png”, {width = 32, height = 32, numFrames = 96})
local layer = mte.getSpriteLayer(1)
print(layer)
local setup = {kind = “sprite”, layer = mte.getSpriteLayer(mte.getVisibleLevel(30, 106)), locX = 30, locY = 106, sourceWidth = 32, sourceHeight = 32}
local options = {
imageSheet = spriteSheet,
sequenceData =
{
{name = “walkUp”, sheet = spriteSheet, frames = {85, 86}, time = 450, loopCount = 0},
{name = “walkDown”, sheet = spriteSheet, frames = {49, 50}, time = 450, loopCount = 0},
{name = “walkLeft”, sheet = spriteSheet, frames = {61, 62}, time = 450, loopCount = 0},
{name = “walkRight”, sheet = spriteSheet, frames = {73, 74}, time = 450, loopCount = 0}
},
xScale = mte.findScale(32, layer) * 1.0,
yScale = mte.findScale(32, layer) * 1.0
}
local player = mte.addSprite(setup, options)
mte.setCameraFocus(player)
local movement = nil
local move = function(event)
if event.target == DpadUp then
if event.phase == “began” or event.phase == “moved” then
movement = “up”
player:setSequence(“walkUp”)
elseif event.phase == “ended” or event.phase == “cancelled” then
movement = nil
end
elseif event.target == DpadDown then
if event.phase == “began” or event.phase == “moved” then
movement = “down”
player:setSequence(“walkDown”)
elseif event.phase == “ended” or event.phase == “cancelled” then
movement = nil
end
elseif event.target == DpadLeft then
if event.phase == “began” or event.phase == “moved” then
movement = “left”
player:setSequence(“walkLeft”)
elseif event.phase == “ended” or event.phase == “cancelled” then
movement = nil
end
elseif event.target == DpadRight then
if event.phase == “began” or event.phase == “moved” then
movement = “right”
player:setSequence(“walkRight”)
elseif event.phase == “ended” or event.phase == “cancelled” then
movement = nil
end
end
end
local gameLoop = function(event)
mte.updateCamera(0, 0)
mte.debug()
local objects = mte.getObjectProperties({locX = player.locX, locY = player.locY})
if objects ~= nil then
print(objects[1].name)
for i = 1, #objects, 1 do
if objects[i].type == “changeLevel” then
mte.changeSpriteLayer(player, mte.getSpriteLayer(tonumber(objects[i].properties.level)))
elseif objects[i].type == “hideLevels” then
local layerObjects = mte.getLayerObj()
local layers = mte.getLayers()
if objects[i].properties.levels == “above” then
for i = 1, #layers, 1 do
if layers[i].properties.Level > player.level then
layerObjects[i].isVisible = false
end
end
elseif objects[i].properties.levels == “below” then
for i = 1, # layers, 1 do
if layers[i].properties.Level < player.level then
layerObjects[i].isVisible = false
end
end
end
elseif objects[i].type == “showLevels” then
local layerObjects = mte.getLayerObj()
local layers = mte.getLayers()
if objects[i].properties.levels == “above” then
for i = 1, # layers, 1 do
if layers[i].properties.Level > player.level then
layerObjects[i].isVisible = true
end
end
elseif objects[i].properties.levels == “below” then
for i = 1, # layers, 1 do
if layers[i].properties.Level < player.level then
layerObjects[i].isVisible = true
end
end
end
elseif objects[i].type == “gotoMap” then
end
end
end
if player.timer == nil then
if movement == “up” then
local detect = mte.getTileProperties({level = player.level, locX = player.locX, locY = player.locY - 1})
local tile = 0
for i = 1, #detect, 1 do
if detect[i].tile ~= 0 then --check for empty space/void. In other words, don’t walk off cliffs.
tile = detect[i].tile
end
if detect[i].properties ~= nil then
if detect[i].properties.solid ~= nil then
detect = “stop”
player:pause()
break
end
end
end
if detect ~= “stop” and tile ~= 0 then
if player.isPlaying == false then
player:play()
end
–mte.moveSprite(player, 0, -10)
mte.moveSpriteTo({sprite = player, locX = player.locX, locY = player.locY - 1, time = 6, easing = “linear”})
end
elseif movement == “down” then
local detect = mte.getTileProperties({level = player.level, locX = player.locX, locY = player.locY + 1})
local tile = 0
for i = 1, #detect, 1 do
if detect[i].tile ~= 0 then --check for empty space/void. In other words, don’t walk off cliffs.
tile = detect[i].tile
end
if detect[i].properties ~= nil then
if detect[i].properties.solid ~= nil then
detect = “stop”
player:pause()
break
end
end
end
if detect ~= “stop” and tile ~= 0 then
if player.isPlaying == false then
player:play()
end
–mte.moveSprite(player, 0, 10)
mte.moveSpriteTo({sprite = player, locX = player.locX, locY = player.locY + 1, time = 6, easing = “linear”})
end
elseif movement == “left” then
local detect = mte.getTileProperties({level = player.level, locX = player.locX - 1, locY = player.locY})
local tile = 0
for i = 1, #detect, 1 do
if detect[i].tile ~= 0 then --check for empty space/void. In other words, don’t walk off cliffs.
tile = detect[i].tile
end
if detect[i].properties ~= nil then
if detect[i].properties.solid ~= nil then
detect = “stop”
player:pause()
break
end
end
end
if detect ~= “stop” and tile ~= 0 then
if player.isPlaying == false then
player:play()
end
–mte.moveSprite(player, -10, 0)
mte.moveSpriteTo({sprite = player, locX = player.locX - 1, locY = player.locY, time = 6, easing = “linear”})
end
elseif movement == “right” then
local detect = mte.getTileProperties({level = player.level, locX = player.locX + 1, locY = player.locY})
local tile = 0
for i = 1, #detect, 1 do
if detect[i].tile ~= 0 then --check for empty space/void. In other words, don’t walk off cliffs.
tile = detect[i].tile
end
if detect[i].properties ~= nil then
if detect[i].properties.solid ~= nil then
detect = “stop”
player:pause()
break
end
end
end
if detect ~= “stop” and tile ~= 0 then
if player.isPlaying == false then
player:play()
end
–mte.moveSprite(player, 10, 0)
mte.moveSpriteTo({sprite = player, locX = player.locX + 1, locY = player.locY, time = 6, easing = “linear”})
end
else
player:pause()
end
end
DpadUp:toFront()
DpadDown:toFront()
DpadLeft:toFront()
DpadRight:toFront()
DpadBack:toFront()
end
DpadUp:addEventListener(“touch”, move)
DpadDown:addEventListener(“touch”, move)
DpadLeft:addEventListener(“touch”, move)
DpadRight:addEventListener(“touch”, move)
Runtime:addEventListener(“enterFrame”, gameLoop)
[/code] [import]uid: 99903 topic_id: 32457 reply_id: 142167[/import]