Storyboard API Questions

The recent Storyboard API blog post has been getting quite a few comments, with many being questions, so I started this thread so you can post your Storyboard API-related questions here and give the comments section on the blog a little break :wink:

UPDATE: Please see the recently published Common Storyboard API Questions blog post to see if any questions you have are answered there first. [import]uid: 52430 topic_id: 17828 reply_id: 317828[/import]

Thanks John. That’s s just great!
[import]uid: 89165 topic_id: 17828 reply_id: 68035[/import]

@Jonathan
I think it’s great to start the discussion on the forum and then continue on the blog.
But I have a little request.

There are some great blog posts (a lot written by you) about important things (external modules being part of it) but that would be really helpful to have it more accessible.
For example it could be well organized in the doc section and updated regularly (best practices, etc…).

Currently, informations is spread among blog posts, blog comments, forum threads…

If one doesn’t spend time on the forums or the blog, there is a big loss of informations for new users.
Browsing forums (search) and blog posts (search) is too time-consuming for someone that is not looking for something specifically, but just “best practices”.

Also most frequently asked questions that appear on the forum could appear in a frequently updated faq with links pointing to the right discussion.
Those discussions would be updated when the api/best practices/ change.

What do you think about this?

[import]uid: 95346 topic_id: 17828 reply_id: 68051[/import]

@ckausik: I’m not fully understanding what your problem is… could you post some code to demonstrate what’s going on (as well as the intended outcome vs. actual outcome is).

@MrMells: I’m in the process of writing a “Frequently Asked Questions” for the Storyboard API, and I’ll be sure to place a link to it from the API reference documentation as well.

I will keep your suggestion in mind for other topics—great idea! [import]uid: 52430 topic_id: 17828 reply_id: 68052[/import]

@Jonathan Beebe:

I have been trying out the storyboard with all sorts of widgets. I have one big problem - tableView does not show if a storyboard is called 2nd time. if I use purgeScene before the 2nd call, it works fine. I verified that the display objects are available and have alpha = 1. But only tabBar and tabBar title (“embossed text”) show up. [import]uid: 19297 topic_id: 17828 reply_id: 68049[/import]

@ jonathanbeebe

It’s a complicated piece of code. But let me try to explain a little better: I have 3 scenes each with tableView, background image, tabBar, embossed text for tabBar title and back button. When I go from scene 1 to scene 2, everything works fine. It works fine, if I go from scene 2 to 3.

But from scene 2, if I call scene 1, it displays everything except the tableView. But the tableView is still part of the display group and has alpha 1, but it is not viewable.

If I purge scene 1 after going to scene 2, the same code works and displays scene 1 with tableView.

I’ll try to write a simplified code to demonstrate this. [import]uid: 19297 topic_id: 17828 reply_id: 68054[/import]

@ckausik: The tableViews and scrollViews are still a little problematic with storyboard (due to problems with inserting them into groups).

Here’s my recommendation:

When you have scenes that use the tableView, do you tableView creation in the “enterScene” event, and be sure to also remove it during the “exitScene” event. This way, you won’t have to insert it into the scene’s “view” property.

This will effectively make the tableView NOT part of that scene, so it won’t respond well to transitions. I would recommend either NOT using transition effects for these scenes, or remove the tableView before the transition effect begins (or it could look funny).

Or…

You can try using the open-source tableView module instead. This one may not suffer the same issues when adding it to a group. We are working on fixing these widgets, so hopefully in the meantime the above fixes should allow you to use them with storyboard. [import]uid: 52430 topic_id: 17828 reply_id: 68058[/import]

Jon,

So I downloaded the sample app for this and ran it on the simulator, and the memory usage is growing instead of staying stable. Starting with scene1 and transitioning through the seems and back to scene1 there is a noticable increase in memory as reported by the app itself (on screen). Isn’t one of the main purposes of this API to help us avoid memory leaks while transitioning between scenes?

Also of note, I went to the main blog page to find the related post but it was removed from the first page. I had to do a search to find it. And the link at the top of this forum posting also links back to this forum posting, and not the initial blog post. Just saying… [import]uid: 64596 topic_id: 17828 reply_id: 68059[/import]

Just want to give everyone a heads up, I just published a new blog post that attempts to answer some of the more commonly asked questions I’ve received about the storyboard API so far:

http://blog.anscamobile.com/2011/11/common-storyboard-api-questions/ [import]uid: 52430 topic_id: 17828 reply_id: 68060[/import]

@shane.lipscomb: Memory will climb depending on what is on the next scene, but once the Lua garbage collector catches up, it will go back down. In the Sample, continue transitioning through the scenes and you’ll see memory usage will go back down. It may take a few rounds before you see this happen.

What I recommend is uncomment the block at the end of main.lua to see memory usage (and texture memory usage) updated in realtime (via the terminal) … this way you’ll see memory usage going up and reaching a certain point, but never going past that point, and eventually going back down to close to where it was originally (as you go through the scenes).

When I run it, MemUsage climbs to about 0.4mb but then at some point goes back down to about 0.2mb and keeps fluctuating from there. That is expected.

It would be a problem if it continued to go past 0.4mb, and never went back down from there. The fact that it’s going back down, and never going past a certain point shows that there is no memory leaks.

If you were transitioning between scenes relatively quickly, you might see it go up to a higher threshold, but it will go back down once the Lua garbage collector kicks in.

Hope that helps! [import]uid: 52430 topic_id: 17828 reply_id: 68061[/import]

@ jonathanbeebe

Thanks for the explanation. This is app uses both tableView & scrollView extensively. There is almost no scenes without these widgets. I guess that I have to wait until the issues with these widgets are resolved. [import]uid: 19297 topic_id: 17828 reply_id: 68062[/import]

@ckausik: You’re free to use those widgets with storyboard, if you’re comfortable with creating them on every “enterScene” event and removing them on every “exitScene” event (which is the equivalent to what was going on if you were using the Director class).

The only thing you’d do different is avoid adding the widgets to the “view” property of your scene, and avoid using transition effects (though some of the effects may still be okay doing it this way). [import]uid: 52430 topic_id: 17828 reply_id: 68063[/import]

I realise that might not be the first priority, but I would like to make a request to add “page turn” as an effect.

And thanks for this feature. Very appreciated. [import]uid: 40334 topic_id: 17828 reply_id: 68140[/import]

Hi there,

What is the _preferred_ way of calling a function defined in a scene.lua file?

function scene:myFunction()  
 -- i want to call this function from another lua file  
end  

I wish we could get a reference to the scene object itself… i.e.:

local myScene = storyboard.getScene("my\_scene")

@eugen5: Thanks for the suggestion! I actually have a way to do a pageturn, but unfortunately, it uses masks + bitmap and would need a different mask + bitmap for every single screen configuration. I’m afraid this one will probably have to wait until there is a more dynamic way to do it (e.g. 2.5d image transforms).

@deniz: Didn’t realize people would be wanting to access scene-specific functions from other scenes, since scenes-as-modules was more of an organizational method rather than a modular coding technique.

As a reminder you could always place your ‘global’ functions in an external module that’s accessible by other modules.

Great suggestion though (being able to get a reference to another already-loaded scene), it’s been added to the next update (which should hopefully roll out in one of the upcoming daily builds this week).

UPDATE: Your request has been put in and will be available in build 2011.688 as storyboard.getScene( sceneName ). So thank you very much for your suggestion!

Here’s the API reference page for the new function:

http://developer.anscamobile.com/reference/index/storyboardgetscene [import]uid: 52430 topic_id: 17828 reply_id: 68178[/import]

One of the primary issues with using the Director Class was that coding errors were often convoluted and masked within the Director class. It was a challenge to code with Director for that very reason I’m not in full understanding why that is; I am curious to see what happens within Storyboard.

EDIT: To be clear, when a coding error occurred the Runtime Error message would often mask the problem deep within the Director class and it was nearly impossible to track down the coding error.

I just did a test within Storyboard and the Runtime error information is in fact specific to allow for efficient debugging. I’m sure one of the more gifted programmers/engineers could explain why Director’s runtime errors resulted in what they did, but for me - this already is a huge attraction in wanting to migrate to Storyboard. Thanks Beebe! [import]uid: 74844 topic_id: 17828 reply_id: 68122[/import]

Hi Jonathan, I’m so excited about this new Storyboard API. I currently use Director Class (and I may not change over just yet because it feels so daunting to make the big change when my current game project with close to two dozen external scene modules working together fine at the moment.)

That said, one thing missing in Director Class is the swipe functionality. That is, instead of touching a screen or a button to change a scene, it would be nice if a swipe motion can trigger a scene change. For example, when a user swipes from right to left, it would perform the fromRight scene change (assuming the new scene would slide in from the right side of the screen). Better yet, old scene would slide left as new scene would slide in…

I imagine there would be a numerous difficulties to achieve this swipe effect (and need for sorting out the type of swipe effect that works the best and most practical), but for some type of app/game scenes, it would feel like the most proper/expected way to handle a scene change.

So… the short question is, do you think swipe effect may eventually be added to Storyboard API?

Naomi [import]uid: 67217 topic_id: 17828 reply_id: 68212[/import]

Hey Naomi, I`m excited like you with the Storyboard API! :slight_smile:

So as you asked above, I would like to ask also regarding your question about:

  • What if to “simulate” the swipe effect we use the “moved” phase into some function (eg. in the background of the scene)? Would that work simulating the swipe? :S

Looking forward for JonBebee answers too. :slight_smile:
Regards,
Rodrigo. [import]uid: 89165 topic_id: 17828 reply_id: 68216[/import]

If we’re swiping, is pinch/zoom difficult to embed within a scene? [import]uid: 74844 topic_id: 17828 reply_id: 68219[/import]

I just have a few general question on OOP and StoryBoard use.

I have a scene that is used for every game level. Within the scene other external modules are loaded i.e. local player = require (“player”) etc. When I call to remove the scene I understand the scene will be removed from memory but when I call the scene again, after removing it, the external modules are not reloaded along with the scene. I assume these are still in memory? Is their a correct way to also remove these external modules when destroying a scene?

@Naomi

I believe you could try something like this:

[blockcode]
–scene would turn as the user is swiping

local function touch(event)
– this could be used to measure the length of the swipe so the scene does not change the second the touch moves
swipeLength = math.abs(event.x - event.xStart)

if event.phase == “began” then

elseif event.phase == “moved” then
– this would check if the user was swiping right to left and that the swipe was longer than 100 pixels
if event.xStart > event.x and swipeLength > 100 then
storyboard.gotoScene( “nextScene” , fromRight )
end
end
return true
end
–scene would change at the end of a swipe

local function touch(event)
if event.phase == “ended” then
if event.xStart > event.x then
storyboard.gotoScene( “nextScene” , fromRight)
end
end
return true
end
[import]uid: 10192 topic_id: 17828 reply_id: 68224[/import]