Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Storyboard API Questions
Started by jonathanbeebe Nov 16 2011 06:37 AM

- - - - -
207 replies to this topic
[TOPIC CONTROLS]
Page 1 of 9 1 2 3 »
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

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 ;-)

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


[TOPIC: post.html]
#2

@RSCdev

[GLOBAL: userInfoPane.html]
@RSCdev
  • Corona Geek

  • 1,489 posts
  • Corona SDK

Thanks John. That's s just great!
uid: 89165 topic_id: 17828 reply_id: 68035


[TOPIC: post.html]
#3

MrMells

[GLOBAL: userInfoPane.html]
MrMells
  • Enthusiast

  • 75 posts
  • Corona SDK

@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?

uid: 95346 topic_id: 17828 reply_id: 68051


[TOPIC: post.html]
#4

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

@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!
uid: 52430 topic_id: 17828 reply_id: 68052


[TOPIC: post.html]
#5

ckausik

[GLOBAL: userInfoPane.html]
ckausik
  • Contributor

  • 231 posts
  • Corona SDK

@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.
uid: 19297 topic_id: 17828 reply_id: 68049


[TOPIC: post.html]
#6

ckausik

[GLOBAL: userInfoPane.html]
ckausik
  • Contributor

  • 231 posts
  • Corona SDK

@ 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.
uid: 19297 topic_id: 17828 reply_id: 68054


[TOPIC: post.html]
#7

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

@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.
uid: 52430 topic_id: 17828 reply_id: 68058


[TOPIC: post.html]
#8

shane.lipscomb

[GLOBAL: userInfoPane.html]
shane.lipscomb
  • Contributor

  • 107 posts
  • Corona SDK

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...
uid: 64596 topic_id: 17828 reply_id: 68059


[TOPIC: post.html]
#9

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

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/
uid: 52430 topic_id: 17828 reply_id: 68060


[TOPIC: post.html]
#10

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

@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!
uid: 52430 topic_id: 17828 reply_id: 68061


[TOPIC: post.html]
#11

ckausik

[GLOBAL: userInfoPane.html]
ckausik
  • Contributor

  • 231 posts
  • Corona SDK

@ 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.
uid: 19297 topic_id: 17828 reply_id: 68062


[TOPIC: post.html]
#12

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

@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).
uid: 52430 topic_id: 17828 reply_id: 68063


[TOPIC: post.html]
#13

Yogamatta

[GLOBAL: userInfoPane.html]
Yogamatta
  • Enthusiast

  • 45 posts
  • Corona SDK

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.
uid: 40334 topic_id: 17828 reply_id: 68140


[TOPIC: post.html]
#14

deniz

[GLOBAL: userInfoPane.html]
deniz
  • Contributor

  • 152 posts
  • Corona SDK

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")
uid: 11686 topic_id: 17828 reply_id: 68166


[TOPIC: post.html]
#15

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

@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
uid: 52430 topic_id: 17828 reply_id: 68178


[TOPIC: post.html]
#16

jerome82

[GLOBAL: userInfoPane.html]
jerome82
  • Contributor

  • 159 posts
  • Corona SDK

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!
uid: 74844 topic_id: 17828 reply_id: 68122


[TOPIC: post.html]
#17

Naomi

[GLOBAL: userInfoPane.html]
Naomi
  • Corona Geek

  • 2,303 posts
  • Corona SDK

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
uid: 67217 topic_id: 17828 reply_id: 68212


[TOPIC: post.html]
#18

@RSCdev

[GLOBAL: userInfoPane.html]
@RSCdev
  • Corona Geek

  • 1,489 posts
  • Corona SDK

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

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. :)
Regards,
Rodrigo.
uid: 89165 topic_id: 17828 reply_id: 68216


[TOPIC: post.html]
#19

jerome82

[GLOBAL: userInfoPane.html]
jerome82
  • Contributor

  • 159 posts
  • Corona SDK

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


[TOPIC: post.html]
#20

risingfrom

[GLOBAL: userInfoPane.html]
risingfrom
  • Observer

  • 8 posts
  • Guests

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
uid: 10192 topic_id: 17828 reply_id: 68224


[TOPIC: post.html]
#21

scott0

[GLOBAL: userInfoPane.html]
scott0
  • Enthusiast

  • 79 posts
  • Corona SDK

Jonathan:
Where do the 'scenes' sit in the overall display hierarchy? Or, to ask more directly:
I'd like to have a common background bitmap shown on of my scenes, without the memory and performance expense of re-loading it as a new bitmap on each scene.

When I attempt to place the bitmap before loading the first scene, I don't see any of the scene content.
??

Thanks
uid: 31041 topic_id: 17828 reply_id: 68225


[TOPIC: post.html]
#22

Naomi

[GLOBAL: userInfoPane.html]
Naomi
  • Corona Geek

  • 2,303 posts
  • Corona SDK

@risingfrom, thank you so much for the code -- it's awesome! But now, you've made me feel torn between converting from Director to Storyboard API. (Converting means tons of work and tons of testing, but converting also means it's possible to add swipe-effect... what do I do...?)

Thanks again!
Naomi
uid: 67217 topic_id: 17828 reply_id: 68226


[TOPIC: post.html]
#23

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

Regarding the swipe question, looks like someone beat me to it! That's exactly how I'd recommend doing it, so thanks @risingfrom.

To answer your question about modules.

When you call storyboard.removeScene( "myScene" ), that module IS completely removed from memory. When you call storyboard.gotoScene( "myScene" ), the module is then reloaded (as if it was the first time you loaded it). It is only when you call storyboard.purgeScene( "myScene" ) that the module is not unloaded (only the scene.view display group).

@scott0: That's actually a bug that I've already fixed over here (along with a bunch of other good stuff, which I'll get into in a moment), so stay tuned for an update that will fix the 'objects on top' issue. When the daily build with the update is available, you'll simply create the background object before the 'require "storyboard"' line in main.lua.

If you can't wait for the update (should be out within the next couple daily builds), then currently, in the version that's out now, the scenes sit just below everything you might've created in main.lua, so if you want something to go behind your scenes when using storyboard, you can do something like this:


local storyboard = require "storyboard"

storyboard.gotoScene( "scene1" )

-- create image
local background = display.newImage( "bg.png" )

-- do a timer delay or it won't work
timer.performWithDelay(1, function()
display.getCurrentStage():insert( 1, background )
end, 1 )
[/code]

Before the update gets checked-in (should be very soon), you'll have to do that whenever you do a scene change, so you may want to store a reference to your background object in the storyboard table. I recommend waiting until the daily build with the fix comes out before setting a background image though, so you don't have to go back and modify your code.

Quick Update on What's Coming



The following new things should be available soon, within the next few Daily Builds.

New Effects



Currently, all of the available effects will leave the current scene in place. However, due to popular demand, I've added some 'sliding' effects that will push the original scene over:

slideLeft
slideRight
slideDown
slideUp

New Functions



storyboard.purgeAll() - purges all loaded scenes (except for the current scene).

storyboard.removeAll() - removes all loaded scenes (except for the current scene).

storyboard.getPrevious() - returns the previous scene name (as a string).

storyboard.getScene( sceneName ) - returns the specified sceneName's scene object.

New Feature



In the upcoming update, you will be able to optionally specify a 'sceneName' when calling storyboard.newScene(), so scenes do not actually HAVE to be attached to external modules. For examples, you can create three (or more) different scene objects in one module, and just assign the appropriate listeners to them as you would other objects! (for scene events, of course).

This is a special-use feature, as most will probably be sticking to the scene-per-module method, where no sceneName is specified in your call to storyboard.newScene() — as you are doing now.

-----

I'll update this thread (and the documentation pages) once a Daily Build with these changes is available for download.

Thanks for the feedback/questions everyone!
uid: 52430 topic_id: 17828 reply_id: 68244


[TOPIC: post.html]
#24

@RSCdev

[GLOBAL: userInfoPane.html]
@RSCdev
  • Corona Geek

  • 1,489 posts
  • Corona SDK

Hey Jon,

Thank you for the Good NEWS!

I have a question reagarding already the new API`s you said will be out soon. So it`s about the storyboard.getPrevious() and storyboard.getScene()

How about using these new APIs mentioned above regarding the storyboard.removeScene() and storyboard.purgeScene()?

When I call from a scene storyboard.getPrevious() for example, will the storyboard call the purge or remove scene functions if I have it set in my scene.lua file or as I`ve used the getScene() or getPrevious() the purge or remove functions will be ignored?

Tip: I am thinking about these new APIs (getScene and previousScene) as it would get the called scenes via some kind of "buffer" and so it would ignore any function of purgeScene or removeScene. Does it make sense for you?
Thank in advance.

Rodrigo.
uid: 89165 topic_id: 17828 reply_id: 68246


[TOPIC: post.html]
#25

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

@RSCdev: I'm not exactly sure what you're asking, but the new functions you mentioned are there to mainly get a reference to other scenes.

storyboard.getPrevious() will return a string of the scene name (since all scenes must have a unique name). This is used mainly if you do not know what scene you came from (e.g. your app goes to a random scene), it is useful for getting the scene name so you can purge it or remove it if necessary.

storyboard.getScene() will take one argument, sceneName, that retrieves the scene object that has a name matching the one you specified. A common use for this would be if you have a function in a specific scene module that you need to access, you can call storyboard.getScene() to get a reference to your scene, and then get a reference to the function/variable you need.

Neither of the functions affect storyboard.purgeScene() or storyboard.removeScene().

UPDATE: We *just* pushed in the changes, so the updates should be in the next Daily Build. The API documentation pages have been updated.

Here's the index page:
http://developer.anscamobile.com/content/storyboard
uid: 52430 topic_id: 17828 reply_id: 68263



[topic_controls]
Page 1 of 9 1 2 3 »
 
[/topic_controls]