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 3 of 9 1 2 3 4 5 »
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#51

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

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


[TOPIC: post.html]
#52

0x90

[GLOBAL: userInfoPane.html]
0x90
  • Enthusiast

  • 30 posts
  • Corona SDK

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.
uid: 10292 topic_id: 17828 reply_id: 69885


[TOPIC: post.html]
#53

Yogamatta

[GLOBAL: userInfoPane.html]
Yogamatta
  • Enthusiast

  • 45 posts
  • Corona SDK

@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
physics.stop()
in
function scene:exitScene( event )
.
uid: 40334 topic_id: 17828 reply_id: 69892


[TOPIC: post.html]
#54

0x90

[GLOBAL: userInfoPane.html]
0x90
  • Enthusiast

  • 30 posts
  • Corona SDK

@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.
uid: 10292 topic_id: 17828 reply_id: 69893


[TOPIC: post.html]
#55

Yogamatta

[GLOBAL: userInfoPane.html]
Yogamatta
  • Enthusiast

  • 45 posts
  • Corona SDK

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

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


[TOPIC: post.html]
#56

0x90

[GLOBAL: userInfoPane.html]
0x90
  • Enthusiast

  • 30 posts
  • Corona SDK

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

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.
uid: 10292 topic_id: 17828 reply_id: 69902


[TOPIC: post.html]
#57

Yogamatta

[GLOBAL: userInfoPane.html]
Yogamatta
  • Enthusiast

  • 45 posts
  • Corona SDK

@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
storyboard.purgeScene(storyboard.getPrevious())
. It should be called in
function scene:enterScene()
. 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.
uid: 40334 topic_id: 17828 reply_id: 69906


[TOPIC: post.html]
#58

NuclearResearch.net

[GLOBAL: userInfoPane.html]
NuclearResearch.net
  • Enthusiast

  • 67 posts
  • Corona SDK

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!
uid: 67641 topic_id: 17828 reply_id: 69911


[TOPIC: post.html]
#59

leonZak

[GLOBAL: userInfoPane.html]
leonZak
  • Observer

  • 22 posts
  • Enterprise

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 ...
uid: 101604 topic_id: 17828 reply_id: 69944


[TOPIC: post.html]
#60

lKinx

[GLOBAL: userInfoPane.html]
lKinx
  • Contributor

  • 193 posts
  • Corona SDK

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? :P

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.

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)endfunction 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 = 5 and chooseProjectile = 9 and chooseProjectile = 12 and chooseProjectile = 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.viewendfunction scene:destroyScene(event)	local group = self.viewendscene:addEventListener("createScene", scene)scene:addEventListener("enterScene", scene)scene:addEventListener("exitScene", scene)scene:addEventListener("destroyScene", scene)return scene
uid: 103624 topic_id: 17828 reply_id: 70033


[TOPIC: post.html]
#61

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

@RAoM_games: That's great to hear! Thanks for doing that test, and I'm glad see that the results turned out good :-)

@leonZak: Thanks for bringing this to our attention. Do you have similar experience using other Android devices + Storyboard, or just that phone? We'll be looking more into this.

@lKinx: Just from looking at it, seems like your code looks good. Once you subscribe, you'll have access to the API and be able to play around with the sample code and easily test your code out (I also encourage changing things and messing around with the samplecode itself for familiarity). Also, in your exitScene you should remove event listeners, stop timers, etc. and remove objects in your destroyScene event.

--------

Regarding physics bodies....

Storyboard does not automatically remove physics bodies, because there's no way to predict 100% what everyone wants their scene to do. Therefore, nothing is unloaded unless you explicitly tell storyboard to do so, or on a low memory warning (in which case the least used scene's 'view' group will be removed).

All of the adding/removal decisions are left up to you. Physics falls in the same realm as Runtime listeners and timers. If you add event listeners, timers, etc. as always, it is your responsibility to ensure they are removed at some point.

In order to provide flexibility, we have to leave what actually goes INTO the event listeners up to you.

We believe that the four events provided (createScene, enterScene, exitScene, and destroyScene) encompass just about all aspects of the scene creation/removal/transitioning process.

My suggestion for physics bodies would be, since they are removed when you call 'removeSelf' on an object, I would just create the objects during 'createScene' and then remove them during a 'destroyScene' event.

For the actual physics simulation, I would do as user Yogamatta suggested and start/stop physics during your enterScene/exitScene events.
uid: 52430 topic_id: 17828 reply_id: 70089


[TOPIC: post.html]
#62

HabitatSoftware

[GLOBAL: userInfoPane.html]
HabitatSoftware
  • Enthusiast

  • 49 posts
  • Corona SDK

I've had the exact same problem as leonZak with every version of storyboard since it's release. It always freezes on the transition from scene 2 to scene 3. Tested on the Droid X and build from Mac and Windows with the same result.
I keep hoping it'll be fixed soon because I'm looking forward to using it on future apps.

Jeff
uid: 14119 topic_id: 17828 reply_id: 70167


[TOPIC: post.html]
#63

mobilefun4me

[GLOBAL: userInfoPane.html]
mobilefun4me
  • Enthusiast

  • 48 posts
  • Corona SDK

The following caused my error using quotation in a find/replace.

local previousName = storyboard.getPrevious()

local previousScene = storyboard.getScene( previousName )
--storyboard.purgeScene( "scene1" )
--storyboard.purgeScene( "previousName" ) wrong!
storyboard.purgeScene( previousName") --correct
uid: 6288 topic_id: 17828 reply_id: 70396


[TOPIC: post.html]
#64

Blue Spruce Games

[GLOBAL: userInfoPane.html]
Blue Spruce Games
  • Contributor

  • 159 posts
  • Corona SDK

I know I saw this somewhere else, but I can't find it:
What is the best way to create a background image that stays throughout all the scenes? I assume it is better to load it once, rather that load it on every scene change. If I put it in the main.lua file, the background is loaded above the rest of the app. What is the best way to do this?
uid: 38000 topic_id: 17828 reply_id: 70470


[TOPIC: post.html]
#65

Lava Level

[GLOBAL: userInfoPane.html]
Lava Level
  • Contributor

  • 274 posts
  • Corona SDK

Sort of the same as Peters but with variables.

Peter, what I have done is make my scenes have a transparent background so I can watch the layer get deleted below it. If it is just 1 image you could set it up to always stay on if you skip this

function scene:destroyScene( event )
	
	print( "((destroying scene 2's view))" )
end

? not to sure, you wouldn't want anything else to be on there so maybe just a scene with that image that doesn't destroy itself and move on to the next scene. (again someone help him out if I am wrong)

I set up a map in my function init() in main that contains my Map[], playerX, PlayerY, Player XY and I can't access it in another scene?

How do I make data accessible across multiple scenes?
**This topic could use its own forum
uid: 100299 topic_id: 17828 reply_id: 70620


[TOPIC: post.html]
#66

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

@leonZak and HabitatSoftware: There seems to be an issue with the 'showNativeActivityIndicator' argument on Android devices, so I suggest until we get this worked out that you don't use that optional argument. In the Storyboard sample, going from scene2 to scene3 is the only place that has that parameter set to true.

e.g.
storyboard.gotoScene( true, "scene3", "fade" )

should be:
storyboard.gotoScene( "scene3", "fade" )

In the next update, I think we're going to remove that argument and allow users to control the native activity indicator on their own within their listeners.
@peter9221: When you call 'require "storyboard"' for the first time, it creates a display group on the stage (which will hold all of your scene view groups. So to create a background image, you can do it in two ways:

1) In your main.lua, create the background before you call 'require "storyboard"'.

2) Or create your background at any time and call "background:toBack()" to place it behind all other objects/groups in the display hierarchy.
uid: 52430 topic_id: 17828 reply_id: 70675


[TOPIC: post.html]
#67

leonZak

[GLOBAL: userInfoPane.html]
leonZak
  • Observer

  • 22 posts
  • Enterprise

Tried it without the 'showNativeActivityIndicator' argument and it works on the Atrix.

thank you.
uid: 101604 topic_id: 17828 reply_id: 70679


[TOPIC: post.html]
#68

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

Quick update, the strange activity indicator issue on Android has been fixed.

We decided to deprecate the 'showActivityIndicator' optional first argument to storyboard.gotoScene() ... Keep a look out for the daily build with the fix in it. In the meantime, just ensure you're not using that argument and you'll have no issues.

Also, previous code that uses that argument will be fine (nothing will break).

Thanks for those who identified the issue!
uid: 52430 topic_id: 17828 reply_id: 70683


[TOPIC: post.html]
#69

ncass

[GLOBAL: userInfoPane.html]
ncass
  • Observer

  • 2 posts
  • Corona SDK

Is it possible to goto the same scene by just calling storyboard.gotoScene( "lvl1" ) when your already on a lvl1 scene for example? like for a retry button for example?
I had a go but just seems to go into a infinite loop and crashes

Thanks
uid: 94536 topic_id: 17828 reply_id: 71311


[TOPIC: post.html]
#70

Dirtybit

[GLOBAL: userInfoPane.html]
Dirtybit
  • Enthusiast

  • 72 posts
  • Enterprise

@ncass: We made a workaround by creating a "dummyScene". The dummyScene first removes the previous scene and then calls gotoScene(previousScene). So if your retry button calls the dummyScene, the scene will be restarted.
uid: 88922 topic_id: 17828 reply_id: 71400


[TOPIC: post.html]
#71

kbradford

[GLOBAL: userInfoPane.html]
kbradford
  • Contributor

  • 234 posts
  • Corona SDK

I'm playing around with Storyboard, and anytime I use an Android or Kindle (aka non iOS dimensions) it crops off the top and bottom portion of the scene during the transition. So in effect, it puts a big black bar on top and bottom of the screen, then transitions it out.

I've tried this on the Storyboard sample code and can reproduce. Change the background on scene1 to take up the full screen, then run on any Android device and you'll see it crops it right before the transition.

Are Android builds not supported on Storyboard yet? Running build 698.
uid: 84258 topic_id: 17828 reply_id: 71529


[TOPIC: post.html]
#72

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

@kbradford: The reason why you're getting black bars with the WidgetDemo sample is due to the fact that the config.lua is set to "letterBox" with a width of 320x480 (iPhone dimensions).

If you're building for a specific device dimension (e.g. Kindle's 1024x600 display), you should set your width to 600 and the height to 1024 to avoid letter-boxing (or stretching).
uid: 52430 topic_id: 17828 reply_id: 71597


[TOPIC: post.html]
#73

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

@ncass: I'm not able to reproduce the infinite loop you're seeing when calling the same scene. If you modify the Storyboard sample code, scene1, and change the call to storyboard.gotoScene() from "scene2" to "scene1", you'll see that the scene successfully transitions to the same scene (effectively reloading it, but with an optional effect).

In your exitScene listener, are you stopping timers/transitions, and removing touch event listeners?

uid: 52430 topic_id: 17828 reply_id: 71622


[TOPIC: post.html]
#74

kbradford

[GLOBAL: userInfoPane.html]
kbradford
  • Contributor

  • 234 posts
  • Corona SDK

@jonathanbeebe That would be doable if I was only building for a handle full of devices, but I build for Android/Kindle/iOS and I never know what the resolution will be for the device that's installing. Isn't that the purpose of using letterBox and dynamic scaling, to handle a variety of resolutions?

If we have to specify the exact resolution to use Storyboard, that makes it pretty much useless to me.
uid: 84258 topic_id: 17828 reply_id: 71921


[TOPIC: post.html]
#75

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

@kbradford: So you're saying your app does not have the borders at the top/bottom, but when you do a scene transition it does?
uid: 52430 topic_id: 17828 reply_id: 71925



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