Storyboard API Questions

So,
I’ve Installed last one “CoronaSDK-2011.694.dmg” on my MAC, and when I use “slideLeft” the same problem. Where I can send the sample code and capture of my screen?

Thanks in advance, IVan [import]uid: 13367 topic_id: 17828 reply_id: 69385[/import]

@iciler: That’s very strange. I created an object outside of the contentBounds (in the same way you did), and the “slideLeft” function within scene1 worked fine.

Please send your samplecode to jonathan [at] anscamobile.com

Thanks! [import]uid: 52430 topic_id: 17828 reply_id: 69393[/import]

hi there,

thanks for the awesome storyboard api!

i encounter a problem though:

i am not able to delete a widget.tableView completely while changing scenes with object:removeSelf in the exitScene() event.

my tableView:

local listOptions = widget.newTableView {   
 top = 70,  
  
height = 360,  
 maskFile = ("images/mask-320x360.png"),  
 bgColor = { 0, 0, 0, 255 },  
};  
  
videoList = widget.newTableView (listOptions)  

my code:

-- Called when scene is about to move offscreen:  
function scene:exitScene( event )  
 local screenGroup = self.view  
  
 display.remove(videoList)  
 videoList = nil  
end  

when i am changing scenes, the background of the tableView is still visible and overlays everything else.

when i turn the background alpha of my tableview to 0, i am able to see the elements on the other page, but they dont responde to any (touch)events, because the background of the tableview is still overlaying.

i am not adding the tableView.view to the screengroup “local group = self.view”, cause that seem to cause some problems.

am i missing something?!

cheers,

max

(sorry for the weird spacing in the sourcecode…) [import]uid: 42936 topic_id: 17828 reply_id: 69440[/import]

@mschmidt: This is most-likely due to the fact that ‘listOptions’ is also a tableView you’re creating. listOptions should just be a regular table.

local listOptions = { top = 70, height = 360, maskFile = ("images/mask-320x360.png"), bgColor = { 0, 0, 0, 255 },} videoList = widget.newTableView (listOptions)[/code]You were creating videoList tableView, which actually had nothing ... and the actual tableView you were seeing was listOptions.The above code should work for you...Also, don't forget to set a forward declaration to videoList somewhere to keep it local within your scene :-) [import]uid: 52430 topic_id: 17828 reply_id: 69446[/import]

ouch, so obvious when you see it. :slight_smile:

thanks a lot!

hah that solved 2 other problems i had. thanks again twice! [import]uid: 42936 topic_id: 17828 reply_id: 69447[/import]

In my game I use storyboard.testvar to update one relevant parameter, level after level.

All goes smoothly until the end of game, where I have a final scene from which you can go back to scene1 and play again. It happens that if I play again, storyboard.testvar behaves randomly level after level. It simply reports and adds the wrong number.

I suppose I need to clear that storyboard.testvar at the first end of the game, but I’ve not found a working manner yet… storyboard.testvar is assigned to the same global parameter at each level and I probably need to delete/clear/reset that global parameter once the game is completed.

Any suggestion from more expert users? Thanks in advance.

[import]uid: 67641 topic_id: 17828 reply_id: 69449[/import]

@RAoM_games: Ensure that one of your events aren’t changing the value of testvar … Perhaps do a print statement that shows you the value of testvar after each event (in the problematic scene) and identify exactly *where* things are being changed/reset improperly. [import]uid: 52430 topic_id: 17828 reply_id: 69457[/import]

What is the storyboard equivalent of director’s “popup” scenes? I want to create a pause menu in the middle of my game, but I don’t see an easy way to show a new scene without removing the last from beneath it. Does anyone know a way to do this? [import]uid: 38000 topic_id: 17828 reply_id: 69460[/import]

@peter9221: That is definitely possible with Storyboard, since scenes don’t automatically get purged or remove on scene change.

Here’s how I would do it…

Change to your new scene (popup) but do so with no effect (or do a crossFade or something that won’t move the prior scene out of place).

Then, during your “createScene” or “enterScene” event, you can just get the previous scene and set it’s view group’s isVisible property to true (so the previous scene is no longer hidden).

Example:

local previousName = storyboard.getPrevious()local previousScene = storyboard.getScene( previousName )previousScene.view.isVisible = truepreviousScene.view.alpha = 1.0[/code]The above would go in your "createScene" or "enterScene" for the popup scene.Of course, if you already know the scene name of where you're coming from then the first line isn't necessary. [import]uid: 52430 topic_id: 17828 reply_id: 69465[/import]

*** error: can’t allocate region

With StoryBoard (Version 2011.695 (2011.8.2), I put together a quick game prototype but have received the following error message after I display a “Win.lua” scene after playing a game.lua screen. So it goes from the game.lua screen with a win to the win.lua screen, back to the game.lua screen and win.lua screen again but on this return to the game.lua the following is displayed?

Corona Simulator(549,0xa0a02540) malloc: *** mmap(size=4294819840) failed (error code=12)
*** error: can’t allocate region
*** set a breakpoint in malloc_error_break to debug
Fri Nov 25 17:46:23 dwss-macbook-pro.local Corona Simulator[549] : CGImageCreate: invalid image provider: NULL.
Fri Nov 25 17:46:23 dwss-macbook-pro.local Corona Simulator[549] : CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 8 bits/pixel; 0-component color space; kCGImageAlphaNoneSkipFirst; 4294966984 bytes/row.
Fri Nov 25 17:46:23 dwss-macbook-pro.local Corona Simulator[549] : CGContextDrawImage: invalid context 0x0
Fri Nov 25 17:46:23 dwss-macbook-pro.local Corona Simulator[549] : CGBitmapContextCreateImage: invalid context 0x0
Fri Nov 25 17:46:23 dwss-macbook-pro.local Corona Simulator[549] : CGImageDestinationAddImage image parameter is nil
Fri Nov 25 17:46:23 dwss-macbook-pro.local Corona Simulator[549] : CGImageDestinationFinalize image destination does not have enough images
Scene 5 Game 01: Exit Scene Event
2011-11-25 17:46:23.418 Corona Simulator[549:60f] glError at end unbindRenderFBO

It’s interesting that I still can keep on playing the game, but something has gone wrong.

Any ideas on where to look as this is a new message to me.

Regards! [import]uid: 6288 topic_id: 17828 reply_id: 69823[/import]

@mobilefun4me: That’s really strange (I’ve never seen an error like that before). Can you reproduce that error consistently? If so, please send a test-case sample to jonathan [at] anscamobile.com so I can try to figure out what’s going on.

Thanks! [import]uid: 52430 topic_id: 17828 reply_id: 69876[/import]

It seems that while storyboard performs perfectly (and very fast) in cleaning up objects, it fails to remove the physical bodies associated with said objects.

For example, we are creating a player object as such:

local player = display.newImageRect("bee.png",200,150)  
group:insert(player)  
physics.addBody(player)  

It runs and behaves just as expected and when we fade to the Game Over scene the player object is visually removed from sight. However turning on on hybrid viewing shows that the objects still persist on screen:

This makes it impossible to create apps with more than one scene using physics.
We tried to manually destroy scenes on every exit (nothing changed).
Do we have to manually remove the bodies from every object we create or am I missing something obvious?
If we have to do proper object destruction manually, it pretty much defeats the purpose of having a scene manager. [import]uid: 10292 topic_id: 17828 reply_id: 69885[/import]

@0x90 I’ve got little concerned after your post and activated hybrid viewing. Physics bodies are gone when I change scens. What I am doing is calling [lua]physics.stop()[/lua] in [lua]function scene:exitScene( event )[/lua]. [import]uid: 40334 topic_id: 17828 reply_id: 69892[/import]

@Yogamatta -> I have included physics.stop() in scene:exitScene() and it indeed fixes the problem half-way.
The good news is, physics bodies are now destroyed.

Still, the behavior is odd (at least when looking at it from a Director paradigm): We set up physics bodies in scene:createScene() which is where we set up all our other objects as well.
Now every time I re-enter the scene the objects already exist but the bodies don’t so I assume that what really happened was that physics.stop() destroyed the bodies but the storyboard is still malfunctioning by moving the objects themselves out of view (intended) but leaving the physics bodies. Thus when we destroy the bodies by force by stopping the physics engine, we destroy the bodies while storyboard handles the objects which is not usable for any app with more than one scene using physics either. [import]uid: 10292 topic_id: 17828 reply_id: 69893[/import]

@0x90 I am creating all bodies in [lua]function scene:enterScene(event)[/lua]. As I understand it [lua]function scene:createScene()[/lua] is for setting up display objects. Stuff such as physics, events, timers, etc should be created in [lua]function scene:enterScene(event)[/lua].

Edit: So what I am doing is calling [lua]physics.start()[/lua] in [lua]function scene:enterScene(event)[/lua] and then adding bodies. [import]uid: 40334 topic_id: 17828 reply_id: 69895[/import]

@Yogamatta -> Thank you for providing a workaround. The following is for general discussion / consideration and not meant to be a “rebuttal” to your idea. :slight_smile:

I understood scene:enterScene() to be for all tasks that need to be stopped when the scene ends (e.g. timers, events) or reset on every scene entry (e.g. object positions, scores). Adding physics seems to fall under object creation. Corona advertises that physics is built right into the objects instead of adding a secondary layer.
If this is indeed the way storyboard is intended to be used things become a lot more difficult without any real gain. It may in fact be a reason for us to go back to Director.

Is this really how we’re supposed to use storyboard?
As a walk-around, is there a way to *always* destroy a scene upon transition so we can *always* have createScene() *and* enterScene() called? I understand that you introduced the separation for performance reasons but in our case (lots of physics objects, not much else) that doesn’t pay off and we are left with having to create our objects in 2 different functions and introduce complicated tables or a bunch of globals to allow the functions to reference the objects created by the other. [import]uid: 10292 topic_id: 17828 reply_id: 69902[/import]

@0x90 I will not debate your thoughts about physics and storyboard. But I think the answer to your question about how to make createScene() to be called is [lua]storyboard.purgeScene(storyboard.getPrevious())[/lua]. It should be called in [lua]function scene:enterScene()[/lua]. The docs say it makes the program completely releas the scene from memory. Which means (I hope) that createScene() is called next time you go to the scene. [import]uid: 40334 topic_id: 17828 reply_id: 69906[/import]

Just to confirm the effectiveness of memory management in Storyboard API: running 20 scenes in a row for 3 times (that is 60 scenes without relaunching the app) led to a stable memory usage of 397-402 KB. Well done Ansca, thanks again! [import]uid: 67641 topic_id: 17828 reply_id: 69911[/import]

I downloaded the Storyboard sample and ran it in the simulator without any problems. Then I built it for android and installed on an Atrix phone. It runs to the point of changing from scene 2 to 3 then I get the spinning “wait a min” wheel (not sure the correct name), and the app hangs there. Can’t use the back button or tap for anything else. I have to use manage apps to force stop it. Then it will run again and do the same thing.

Tried with build 2011.689 and 2011.695, same result.

I put a video of it at http://chili.zaks.com/corona in both mp4 and wmv format showing what happens.

Again - made no change to the downloaded sample. I’m compiling on win7. A couple other things I’m working on with Corona work fine.

thanks,
leon … [import]uid: 101604 topic_id: 17828 reply_id: 69944[/import]

I haven’t yet subscribed to Corona, but I’m preparing to after the holidays. Anyways, today I went through my code and stuck it where I think it should be if I were using Storyboard API. My questions are:

  1. What things do I have to insert into the local group? All objects, just images, etc.?

  2. Will my code even work? As in, did I stick things into their proper spots, or did I screw up somewhere? :stuck_out_tongue:

Edit: I haven’t done the exitScene and destroyScene functions yet, but I think I can manage that after everything is working in the other functions.

[lua]display.setStatusBar(display.HiddenStatusBar)
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
require(“sprite”)
require(“physics”)

function scene:createScene(event)
local group = self.view

– Create Scene

local background = display.newImage(“images/game_background.png”, 0, 0)
ground = display.newImage(“images/game_ground.png”, 0, 445)
physics.addBody(ground, “static”)
function ground:collision(event)
event.other:removeSelf()
end
leftBoundary = display.newRect(-45, 0, 45, 480)
leftBoundary:setFillColor(0, 0, 0)
rightBoundary = display.newRect(800, 0, 45, 480)
rightBoundary:setFillColor(0, 0, 0)
coinSound = audio.loadSound(“audio/game_collectcoin.mp3”)

– Create Piggy Bank

local piggyBankSheet = sprite.newSpriteSheet(“images/game_piggybank.png”, 96, 96)
local piggyBankSet = sprite.newSpriteSet(piggyBankSheet, 1, 6)
sprite.add(piggyBankSet, “pigmleft”, 1, 3, 150, 0)
sprite.add(piggyBankSet, “pigmright”, 4, 3, 150, 0)
piggyBank = sprite.newSprite(piggyBankSet)
physics.addBody(piggyBank, “static”)
piggyBank.x = display.contentWidth / 2
piggyBank.y = 397

– Create Buttons

local motionX = 0
local speed = 8
local buttonSheet = sprite.newSpriteSheet(“images/game_buttons.png”, 72, 72)
local buttonSet = sprite.newSpriteSet(buttonSheet, 1, 4)
sprite.add (buttonSet, “leftn”, 1, 1, 60000, 0)
sprite.add (buttonSet, “leftp”, 2, 1, 60000, 0)
sprite.add (buttonSet, “rightn”, 3, 1, 60000, 0)
sprite.add (buttonSet, “rightp”, 4, 1, 60000, 0)
leftButton = sprite.newSprite(buttonSet)
leftButton.x = 51
leftButton.y = 429
rightButton = sprite.newSprite(buttonSet)
rightButton.x = 749
rightButton.y = 429

– Display Score

scorePlaceOne = 0
scorePlaceTwo = 0
scorePlaceThree = 0
scoreText = display.newText("$" … scorePlaceOne … “.” … scorePlaceTwo … scorePlaceThree, 5, 10, “309”, 60)
scoreText:setTextColor(0, 0, 0)
end

function scene:enterScene(event)
local group = self.view

– Start Physics

physics.start()
physics.setGravity(0, 9.8)

– Create Scene

ground:addEventListener(“collision”, ground)

– Create Piggy Bank

function piggyBank:collision(event)
if (event.other.type == “coinbronze”) then
scorePlaceThree = scorePlaceThree + 1
audio.play(coinSound)
elseif (event.other.type == “coinsilver”) then
scorePlaceThree = scorePlaceThree + 5
audio.play(coinSound)
elseif (event.other.type == “coingold”) then
scorePlaceTwo = scorePlaceTwo + 1
audio.play(coinSound)
elseif (event.other.type == “rock”) then

end
event.other:removeSelf()
end
piggyBank:addEventListener(“collision”, piggyBank)

– Create Buttons

local function touchLeft(event)
motionX = -speed
leftButton:prepare(“leftp”)
leftButton:play(“leftp”)
piggyBank:prepare(“pigmleft”)
piggyBank:play(“pigmleft”)
end
local function touchRight(event)
motionX = speed
rightButton:prepare(“rightp”)
rightButton:play(“rightp”)
piggyBank:prepare(“pigmright”)
piggyBank:play(“pigmright”)
end
local function movePiggyBank(event)
piggyBank.x = piggyBank.x + motionX
if (piggyBank.x < -33) then piggyBank.x = 833
elseif (piggyBank.x > 833) then piggyBank.x = -33 end
end
local function stopPiggyBank(event)
if (event.phase == “ended”) then
motionX = 0
leftButton:prepare(“leftn”)
leftButton:play(“leftn”)
rightButton:prepare(“rightn”)
rightButton:play(“rightn”)
piggyBank:pause()
end
end
leftButton:addEventListener(“touch”, touchLeft)
rightButton:addEventListener(“touch”, touchRight)
Runtime:addEventListener(“enterFrame”, movePiggyBank)
Runtime:addEventListener(“touch”, stopPiggyBank)

– Create Projectiles

function createProjectiles()
local projectilesheet = sprite.newSpriteSheet(“images/game_projectiles.png”, 48, 48)
local projectileset = sprite.newSpriteSet(projectilesheet, 1, 24)
sprite.add (projectileset, “coinbronze”, 1, 6, 250, 0)
sprite.add (projectileset, “coinsilver”, 7, 6, 250, 0)
sprite.add (projectileset, “coingold”, 13, 6, 250, 0)
sprite.add (projectileset, “rock”, 19, 6, 250, 0)
local projectile = sprite.newSprite(projectileset)
physics.addBody(projectile, “dynamic”)
projectile.isSensor = true
projectile.isFixedRotation = true
local chooseProjectile = math.random(0, 13)
if (chooseProjectile >= 0 and chooseProjectile <= 4) then
projectile.type = “coinbronze”
projectile:prepare(“coinbronze”)
projectile:play(“coinbronze”)
elseif (chooseProjectile >= 5 and chooseProjectile <= 8) then
projectile.type = “coinsilver”
projectile:prepare(“coinsilver”)
projectile:play(“coinsilver”)
elseif (chooseProjectile >= 9 and chooseProjectile <= 11) then
projectile.type = “coingold”
projectile:prepare(“coingold”)
projectile:play(“coingold”)
elseif (chooseProjectile >= 12 and chooseProjectile <= 13) then
projectile.type = “rock”
projectile:prepare(“rock”)
projectile:play(“rock”)
end
local chooseLocation = math.random(0, 1)
projectile.y = 300
projectile.x = -24 + chooseLocation * 848
projectile:applyLinearImpulse(0.2 - (chooseLocation * 0.4), -math.random(0.75, 3.475) / 10, projectile.x, projectile.y)
return projectile
end
timer.performWithDelay(math.random(750, 1500), createProjectiles, 0)

– Update

if (scorePlaceTwo >= 10) then
scorePlaceTwo = scorePlaceTwo - 10
scorePlaceOne = scorePlaceOne + 1
end
if (scorePlaceThree >= 10) then
scorePlaceThree = scorePlaceThree - 10
scorePlaceTwo = scorePlaceTwo + 1
end
scoreText.text = “$” … scorePlaceOne … “.” … scorePlaceTwo … scorePlaceThree
scoreText:setReferencePoint(display.TopLeftReferencePoint)
scoreText.x = 5

leftButton:toFront()
rightButton:toFront()
leftBoundary:toFront()
rightBoundary:toFront()
end

function scene:exitScene(event)
local group = self.view
end

function scene:destroyScene(event)
local group = self.view
end

scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“exitScene”, scene)
scene:addEventListener(“destroyScene”, scene)

return scene[/lua] [import]uid: 103624 topic_id: 17828 reply_id: 70033[/import]