Director Class + Lime + Memory Management

I’ve been wanting to use the director class to control which map or level is loaded in my game.

http://developer.anscamobile.com/code/director-class-10

With the director class, you add objects to a group which gets deleted from memory when you transition out of a scene. I’ve been able to get maps to load using the director class:

function new()
local localGroup = display.newGroup()

– Load Lime
local lime = require(“lime”)

– Load your map
local map = lime.loadMap(“maps/tutorial0.tmx”)

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

localGroup:insert(visual)

return localGroup
end

Question:

I know that the “visual” object will be removed from memory when localGroup is deleted. What happens to “map” and “lime” should I be worried about this? Anyone have any tips on integrating lime with the director class. My understanding of corona memory management is a bit weak.

Thanks,

m
[import]uid: 12267 topic_id: 6106 reply_id: 306106[/import]

I’m very interested in this too. My next mountain to climb! Thanks for sharing any success you have in this integration. [import]uid: 11904 topic_id: 6106 reply_id: 20933[/import]

I haven’t looked into Director class fully yet (who has time to make games? :slight_smile: ) but I would assume that it would destroy everything in your screen files thus including your map data.

What you could possibly do is create a sort of map manager class that would then get called from your screen i.e. mapManager:getMap(“map.tmx”) and then in the manager the first time that function is called it would load the map and store it and then in each subsequent call you the function would know that it is already loaded and then pass it back to you.

Does Director have an onShow and onHide function?
[import]uid: 5833 topic_id: 6106 reply_id: 20947[/import]

I have started too try out using director with Lime for figuring out how too control levels and such.
Everything is working good up until I have too go back too the menu. Nothing happens when I click the button set up too go back too menu:

local function touchedmenu ( event )
if event.phase == “ended” then
director:changeScene(“menu”,“fade”)
end
end

menuBtn:addEventListener(“touch”,touchedmenu)

I know the button works cause it executes other things I put in there… so its the changeScene that dosent work, at least thats what it looks like too me.

Other thing is that when I put objects into groups they disappear.

local localGroup = display.newGroup()
local menuBtn = display.newImage (“menu.png”)
localGroup:insert(menuBtn)

then I have the return localGroup at the end

Im new at coding so its all abit touch and go now in the beginning, any help or pointers would be greatly appreciated :slight_smile: [import]uid: 17969 topic_id: 6106 reply_id: 22052[/import]

Aaah, nevermind the question about the back too menu button, the problem was ofcourse that all the gfx was still there and over the menu buttons…

so guess the question is about the localGroup and how too unload all the graphics :slight_smile: [import]uid: 17969 topic_id: 6106 reply_id: 22053[/import]

I actually just started creating a little demo/viewer app that I intend to release on the app store so people can see Lime in action before buying and it uses Director. It’s all very basic at the moment but if you want I will post a link to it so you can have a look at the code? [import]uid: 5833 topic_id: 6106 reply_id: 22056[/import]

yes plz! [import]uid: 12267 topic_id: 6106 reply_id: 22057[/import]

Graham, I think a demo app on the store is a great idea to get more developers to take a look at your lib. I would love to see your code. Please please link it up! Thanks & good luck! [import]uid: 11904 topic_id: 6106 reply_id: 22058[/import]

I figured out the grouping issue… after reading up on it I found out that it puts the object that is put in group too the back of the stack, so I just had too put everything in the group and they display correctly and go away when tocuhed menu… now I just need too find out why the screen is black when I return too i :slight_smile: probably some small thing I have overlooked, hehe

I love looking at examples, thats mostly how I learn things :slight_smile: [import]uid: 17969 topic_id: 6106 reply_id: 22060[/import]

Please note, the app is VERY basic :slight_smile:

I have added a link to here - http://justaddli.me/members/downloads.php

I will soon rearrange that page to work better as more things get added to it. [import]uid: 5833 topic_id: 6106 reply_id: 22062[/import]

Thanks for uploading the example, will take a closer look at it today. I tried running it once yesterday but I could only get too the second screen where you choose wich map too load.

When it comes too my little director project its moving along. I can get too the menu again now from a game level. But when I go back too the game the character moves alot faster… I have used most of the code from your tutorial on how too make characters move and jump. and as far as I can see its the code part that sets the speed and makes it move:

local DIRECTION_RIGHT = 1

local onButtonRightEvent = function(event)

if event.phase == “press” then
player.direction = DIRECTION_RIGHT
player.xScale = player.direction
player.state = STATE_WALKING
else
player.state = STATE_IDLE
end

player:prepare(“anim” … player.state)

player:play()
end

local onUpdate = function(event)

if player.state == STATE_WALKING then

player:applyForce(player.direction * 7, 0, player.x, player.y)

elseif player.state == STATE_IDLE then

local vx, vy = player:getLinearVelocity()
if vx ~= 0 then
player:setLinearVelocity(vx * 0.9, vy)
end
end
end

Runtime:addEventListener(“enterFrame”, onUpdate)
not sure why it would become even faster after loading the map up again but there must be some variable that dosent get deleted but stays on? will dig into your example and maybe find some answeres there. If anyone sees the mistake I have made it would be great too know :slight_smile:
[import]uid: 17969 topic_id: 6106 reply_id: 22148[/import]

Cool demo Graham, thanks for sharing.
[import]uid: 13932 topic_id: 6106 reply_id: 22169[/import]

No problem, hope it helps someone. [import]uid: 5833 topic_id: 6106 reply_id: 22173[/import]

Hy Graham,

great demo indeed. I have a question. I’m a noob to Lua and I don’t get how the (as it seems) global table _G[“map”] is filled with the correct map to be loaded. is this _G a built-in Lua table? if not, who declares it?

another question: I can’t seem to find where the physics.start() is done. screen_map.lua is where the map is loaded and the listeners are called. but where is the physics started!??

many thanks! [import]uid: 31814 topic_id: 6106 reply_id: 22208[/import]

_G is indeed a global table created by the Lua environment, I don’t like using it at all however this was a “good enough” type solution.

When the map is built via lime.buildMap() Lime will check if the physics world has already been created and if not it will do it for you. [import]uid: 5833 topic_id: 6106 reply_id: 22282[/import]

Works great on this end. Thanks! [import]uid: 11904 topic_id: 6106 reply_id: 22603[/import]

Graham, please take a moment to look at the new Director 1.2. Your demo app seems to be crashing when you return to the main menu screen after exiting a map. [import]uid: 11904 topic_id: 6106 reply_id: 22692[/import]

Yep - same here…
[import]uid: 13932 topic_id: 6106 reply_id: 22708[/import]

Oops I didn’t even realise that 1.2 was out. I am currently away from my PC as I was meeting a client today but will look when I get back. Sorry for the inconveniance. [import]uid: 5833 topic_id: 6106 reply_id: 22714[/import]

No problem - thanks Graham :slight_smile:
[import]uid: 13932 topic_id: 6106 reply_id: 22719[/import]