Introducing Lime - A module to import 2D tilemaps in your game.

Do I understand it correctly from your last post, that the slow graphics update/performance when using Tiled+Lime with Corona SDK is caused by the Corona codes and not Lime? I mean, it works superbly smooth on the simulator but it’s practically “worthless” once installed on the iPhone.

Don’t get me wrong, I’m just itching to be able to use Tiled+Lime for my games, infact I got the levels ready for some of the games already, just waiting for the performance bugs to be killed so I can actually use them. [import]uid: 44742 topic_id: 3598 reply_id: 30594[/import]

I’m pretty new to Corona, and I’m not the programmer in our team, so what exactly is the culling and what is it’s function? [import]uid: 44742 topic_id: 3598 reply_id: 30596[/import]

Currently in Corona every visual object is drawn regardless of whether it is on screen or not which results in a lot of objects being drawn when they don’t need to be, a culling function would hide any objects that shouldn’t be seen. This can be done in Lua, and currently is in Lime however not perfectly, but it could be done much faster if it is in native code. [import]uid: 5833 topic_id: 3598 reply_id: 30597[/import]

Ah yes, I can understand that. I guess it’s the Lime culling then that’s causing the tiles to go black/partially black around the edges of the screen when using a Tiled map + Lime, then scrolling it in either direction? [import]uid: 44742 topic_id: 3598 reply_id: 30598[/import]

Yup that would be it, it certainly isn’t perfect yet. If you wish you can call lime.disableScreenCulling() before loading your map to disable the culling function. [import]uid: 5833 topic_id: 3598 reply_id: 30630[/import]

Hi,

First of all thx for your Lime !!! it’s magic !

But! :slight_smile: i’m stuck for RPG item and collision somebody can help me and show me how make Tree and rock walkthrough impossible ?

Thx for all! [import]uid: 73995 topic_id: 3598 reply_id: 46222[/import]

I have found a solution …
I set gravity to 0

[code]
– On cache la bar
display.setStatusBar( display.HiddenStatusBar )

– Demarrage Module Physics
local physics = require(“physics”)
physics.start()

– On tue la gravitée
physics.setScale( 60 )
physics.setGravity( 0, 0 )
– gestion du multitouch
system.activate( “multitouch” )

– Demarrage de Lime :slight_smile:
local lime = require(“lime”)
– Demarrage Joystick
local joystickClass = require( “joystick” )

– On charche la map 01.tmx
local map = lime.loadMap(“01.tmx”)

local onPlayerSpawnObject = function(object)
local layer = map:getTileLayer(“Player”)
player = display.newImage(layer.group, “guy.png”)
player.x = 300
player.y = 100
physics.addBody(player)
player.isFixedRotation = true
end

map:addObjectListener(“PlayerSpawn”, onPlayerSpawnObject)

– Create the visual
local visual = lime.createVisual(map)

– Build the physical
local physical = lime.buildPhysical(map)

local function movePlayer( event )
local xAmount, yAmount = event.joyX, event.joyY

if type(xAmount) == “number” then
player.x = player.x + xAmount * 4
end

if type(yAmount) == “number” then
player.y = player.y + yAmount * 4
end

end
– Add A New Joystick
local playerJoystick = joystickClass.newJoystick
{
outerImage = “joystickOuter.png”,
outerAlpha = 0.8,
innerImage = “joystickInner.png”,
innerAlpha = 0.8,
position_x = 35,
position_y = 380,
onMove = movePlayer
}

playerJoystick.xScale = 0.7
playerJoystick.yScale = 0.7

local function onCollision(self, event )

if ( event.phase == “began” ) then
if event.other.IsDoor then
print “Touche …”
end
elseif ( event.phase == “ended” ) then
if event.other.IsDoor then
print “Touche plus …”
end
end
end

player.collision = onCollision
player:addEventListener( “collision”, player )
[/code] [import]uid: 73995 topic_id: 3598 reply_id: 46283[/import]

Now I’m looking how can i switch tilemap …

Director class ? other ?

Thx. [import]uid: 73995 topic_id: 3598 reply_id: 46285[/import]

If you look in the “Viewer” app that comes with the Lime download you should see one way of using Director to change maps etc and there is also this tutorial here - http://justaddli.me/tutorial.php?t=0&id=19 [import]uid: 5833 topic_id: 3598 reply_id: 46301[/import]

Thx for your fast reply.

I did the same thing …
Work 10 time on the simulator before lag and crash

dont work on the device …

[code]
module(…, package.seeall)
new = function ()
local localGroup = display.newGroup()

– On cache la bar
display.setStatusBar( display.HiddenStatusBar )

– Demarrage Module Physics
local physics = require(“physics”)
physics.start()

– On tue la gravitée
physics.setScale( 60 )
physics.setGravity( 0, 0 )
– gestion du multitouch
system.activate( “multitouch” )

– Demarrage de Lime :slight_smile:
local lime = require(“lime”)
– Demarrage Joystick
local joystickClass = require( “joystick” )

– On charche la map 01.tmx
local map = lime.loadMap(“02.tmx”)

local onPlayerSpawnObject = function(object)
local layer = map:getTileLayer(“Player”)

player = display.newImage(layer.group, “guy.png”)
player.x = object.x * 1.3
player.y = object.y * 1.3

physics.addBody(player)
player.isFixedRotation = true
end

map:addObjectListener(“PlayerSpawn”, onPlayerSpawnObject)

– Create the visual
local visual = lime.createVisual(map)

– Build the physical
local physical = lime.buildPhysical(map)

local function movePlayer( event )
local xAmount, yAmount = event.joyX, event.joyY

if type(xAmount) == “number” then
player.x = player.x + xAmount * 4
end

if type(yAmount) == “number” then
player.y = player.y + yAmount * 4
end

end
– Add A New Joystick
local playerJoystick = joystickClass.newJoystick
{
outerImage = “joystickOuter.png”,
outerAlpha = 0.8,
innerImage = “joystickInner.png”,
innerAlpha = 0.8,
position_x = 35,
position_y = 380,
onMove = movePlayer
}

playerJoystick.xScale = 0.7
playerJoystick.yScale = 0.7

local function onCollision(self, event )

if ( event.phase == “began” ) then
if event.other.IsDoor then

print “Porte …”
physics.stop()
director:changeScene( “01”, “crossfade” )

end
elseif ( event.phase == “ended” ) then
if event.other.IsDoor then
print “pas de Porte …”
end
end
end

player.collision = onCollision
player:addEventListener( “collision”, player )
return localGroup

end
[/code] [import]uid: 73995 topic_id: 3598 reply_id: 46319[/import]

When you change the scene you will probably want to destroy the map as well via map:destroy() [import]uid: 5833 topic_id: 3598 reply_id: 46322[/import]

Thx a lot…

The destory() function work ! no more lag and crash…

But when i build it dont work on the device when i try to change map the App block and quit.

i’m on Android (Samsung Galaxy S2) do you have any idea why ? [import]uid: 73995 topic_id: 3598 reply_id: 46326[/import]

Hi,

I finely found THE solution !!!

work fine prety fast and all is by the tmx file …

here is the code :

--name is the filemap you want to load  
-- nseo is the north south est ouest for replace the player @good possition  
  
function chargemap(name,nseo)  
 coll = "non"  
  
 if (nseo=="nord") then  
 playerx = player.x  
 playery = 430  
 elseif (nseo=="sud") then  
 playerx = player.x  
 playery = 50  
 elseif (nseo=="est") then  
 playerx = 750  
 playery = player.y  
 elseif (nseo=="ouest") then  
 playerx = 50  
 playery = player.y  
 end  
  
 player:removeSelf()  
  
 map:destroy()  
  
 timer.performWithDelay(1,function()  
 map = lime.loadMap(name)  
  
 visual = lime.createVisual(map)  
 lime.buildPhysical(map)  
  
 creatplayer()  
  
 player.collision = onCollision  
 player:addEventListener( "collision", player )  
 -- We put the Joystick on TOP  
 local parent = playerJoystick.parent  
 parent:insert( playerJoystick )  
  
 end,1)  
  
 --playerJoystick:joystickStart()  
end  

here the creatplayer function

  
function creatplayer()  
 layer = map:getTileLayer("Player")  
  
 player = display.newImage(layer.group,"guy.png")  
 player.x = playerx  
 player.y = playery  
  
 physics.addBody(player)  
 player.isFixedRotation = true  
end  
  

for the TMX file just make zone like this :

http://djdarko.free.fr/dev/tmx.jpg

here the full code of my main.lua

-- On cache la bar  
display.setStatusBar( display.HiddenStatusBar )  
  
-- Demarrage Module Physics  
local physics = require("physics")  
physics.start()  
  
-- On tue la gravitée  
physics.setScale( 60 )  
physics.setGravity( 0, 0 )  
  
coll = "non"  
playerx = 300  
playery = 200  
-- gestion du multitouch  
system.activate( "multitouch" )  
  
-- Demarrage de Lime :)  
local lime = require("lime")  
-- Demarrage Joystick  
local joystickClass = require( "joystick" )  
  
-- On charche la map 01.tmx  
local map = lime.loadMap("1.tmx")  
  
-- Create the visual  
visual = lime.createVisual(map)  
  
-- Build the physical  
physical = lime.buildPhysical(map)  
function creatplayer()  
 layer = map:getTileLayer("Player")  
  
 player = display.newImage(layer.group,"guy.png")  
 player.x = playerx  
 player.y = playery  
  
 physics.addBody(player)  
 player.isFixedRotation = true  
end  
  
function onCollision(self, event )  
  
 if ( event.phase == "began" ) then  
 if event.other.IsDoor then  
 coll = "oui"  
  
chargemap(event.other.mapname..".tmx",event.other.sens)  
 end  
 elseif ( event.phase == "ended" ) then  
 if event.other.IsDoor then  
  
 end  
 end  
end  
  
function movePlayer( event )  
 xAmount, yAmount = event.joyX, event.joyY  
 if type(xAmount) == "number" and type(player.x) == "number" then  
 player.x = player.x + xAmount \* 4  
 end  
 if type(yAmount) == "number" and type(player.y) == "number" then  
 player.y = player.y + yAmount \* 4  
 end  
end  
  
creatplayer()  
player.collision = onCollision  
player:addEventListener( "collision", player )  
  
-- Add A New Joystick  
local playerJoystick = joystickClass.newJoystick  
{  
 outerImage = "joystickOuter.png",   
 outerAlpha = 0.7,   
 innerImage = "joystickInner.png",   
 innerAlpha = 0.7,   
 position\_x = 20,   
 position\_y = 345,  
 --ghost = 20, -- Fade Effect Delay ( In MilliSeconds )   
 onMove = movePlayer   
}  
  
playerJoystick.xScale = 1  
playerJoystick.yScale = 1  
  
function chargemap(name,nseo)  
 coll = "non"  
  
 if (nseo=="nord") then  
 playerx = player.x  
 playery = 430  
 elseif (nseo=="sud") then  
 playerx = player.x  
 playery = 50  
 elseif (nseo=="est") then  
 playerx = 750  
 playery = player.y  
 elseif (nseo=="ouest") then  
 playerx = 50  
 playery = player.y  
 end  
  
 player:removeSelf()  
  
 map:destroy()  
  
 timer.performWithDelay(1,function()  
 map = lime.loadMap(name)  
  
 visual = lime.createVisual(map)  
 lime.buildPhysical(map)  
  
 creatplayer()  
 player.collision = onCollision  
 player:addEventListener( "collision", player )  
 local parent = playerJoystick.parent  
 parent:insert( playerJoystick )  
  
 end,1)  
  
end  

here the map test

http://djdarko.free.fr/dev/1.tmx
http://djdarko.free.fr/dev/2.tmx
http://djdarko.free.fr/dev/3.tmx
http://djdarko.free.fr/dev/guy.png
http://djdarko.free.fr/dev/forest.png

Hope that can help someone one day :slight_smile: … [import]uid: 73995 topic_id: 3598 reply_id: 46500[/import]

Looking good! Glad you got it working! [import]uid: 5833 topic_id: 3598 reply_id: 46531[/import]

Hi,

We work a lot on hour game … but we have now Lag Problems …

On my Galaxy S2 no probleme but if we try on Galaxy S the game is not playable …

we use : 25x15 map created with tiled editor.
32x32

with :
width=480,
height=800,
scale = “zoomStretch”

We have paste from 50x30 with 16x16 to 25x15 with 32x32 … so we kill all the lag on the Galaxy s2 but not on small devices :frowning:

do you know a way for reduce the lag ?

[import]uid: 73995 topic_id: 3598 reply_id: 48082[/import]

There are lots of things that could affect the speed, have you enabled culling?

If you want and are able to, please send your project to support@justaddli.me and I will take a look at it for you. All work is completely confidential and will be deleted from my computer once the issues are resolved. [import]uid: 5833 topic_id: 3598 reply_id: 48105[/import]