From my understanding the “view” property of a scene is it’s display group, but in my testing it doesn’t seem to respond to xScale/yScale modifications. Anyone know why? [import]uid: 54030 topic_id: 17828 reply_id: 77059[/import]
Does it matter where in storyboard I create my physics objects? I don’t use the storyboard transition effects either if that helps.
For example in my game I create a lot of static physics objects in the function scene:createScene( event ). Will this pose any problems I’m not aware of?
[import]uid: 38820 topic_id: 17828 reply_id: 77098[/import]
@ kbradford: I use that too. I’m using a rect above everything to simulate fade. But now I have another problem. Rotation. In before scene transitions, storyboard shows the content in the default orientation.
Someone has a workaround for the rotation issue? I’m using rotationfix lib by E. Gonenc.
Edit: Sorry, actually with the rectabove everything, the upside down image could not be seen, so, in this case, this is not a visible problem. [import]uid: 50425 topic_id: 17828 reply_id: 77348[/import]
Im calling a collision event in my ‘enterscene’(line83) and upon that collision I want to restart the level storyboard.gotoScene(‘scene1’) but I keep running into errors. I tried delaying it then instead of restarting the scene1 it would loop to scene2
[lua]–scene1–
–
– scenetemplate.lua
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
physics = require(‘physics’)
physics.start()
physics.setGravity(0,9.3)
–physics.setDrawMode(‘hybrid’)
local p = 0
local bg1, floor1, present1, dropButton
local phys1 = {friction = .7, bounce = .1, density = .3}
local h = display.contentHeight
local w = display.contentWidth
local level1Presents
local onTouch
local createDropButton
local dropPresents
local onCollision = {}
local delay
–
– NOTE:
– Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.
– BEGINNING OF YOUR IMPLEMENTATION
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
bg1 = display.newRect(0, 0, w, h)
bg1:setFillColor(200,0,0)
group:insert(bg1)
floor1 = display.newRect(0, h-1, w, 1)
floor1.name = ‘floor1’
physics.addBody(floor1, “static”,{density = 9, friction = .7, bounce = .2})
floor1:addEventListener(‘collision’, floor1)
group:insert(floor1)
– CREATE display objects and add them to ‘group’ here.
– Example use-case: Restore ‘group’ from previously saved state.
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
print( “1: enterScene event” )
local function delay()
storyboard.gotoScene(‘scene1’)
end
function floor1:collision ()
print “test”
–storyboard.purgeScene( “scene1” )
storyboard.gotoScene(‘scene1’)
–local tmr = timer.performWithDelay(1, delay, 1)
end
local function level1Presents()
p = p+1
print §
if (p ==1) then
present1 = display.newRect(0,0, 50, 50)
physics.addBody(present1, ‘kinematic’, phys1)
present1.x = w/2
present1.y = h/7
present1.name = ‘present1’
present1:addEventListener(‘touch’, onTouch)
– present1:addEventListener(‘collision’, onCollision)
group:insert(present1)
elseif (p == 2) then
present2 = display.newRect(0,0, 100, 50)
physics.addBody(present2, ‘kinematic’, phys1)
present2.x = w/2
present2.y = h/7
present2.name = ‘present2’
present2:addEventListener(‘touch’, onTouch)
–present2:addEventListener(‘collision’, onCollision)
group:insert(present2)
elseif (p == 3) then
storyboard.gotoScene(‘scene2’)
end
end
function onTouch(event)
t = event.target
t.name = ‘t’
local phase = event.phase
if event.phase == “began” then
display.getCurrentStage():setFocus(t)
t.isFocus = true
t.x0= event.x - t.x
elseif t.isFocus then
if event.phase == “moved” then
t.x = event.x - t.x0
elseif event.phase == ‘ended’ or ‘cancelled’ then
display.getCurrentStage():setFocus(nil)
t.isFocus = false
createDropButton()
t:removeEventListener(‘touch’, onTouch)
end
end
return true
end
function createDropButton()
dropButton = display.newRect(w-100,h/4, 80, 80)
dropButton:addEventListener(‘tap’, dropPresent)
end
function dropPresent()
t.bodyType = ‘dynamic’
timer.performWithDelay(3000, level1Presents, 1)
display.remove(dropButton)
–dropButton:removeEventListener
end
level1Presents()
– INSERT code here (e.g. start timers, load audio, start listeners, etc.)
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
print( “1: exitScene event” )
–local group = self.view
present1:removeEventListener(‘touch’, onTouch)
present1:removeEventListener(‘touch’, onTouch)
–dropButton:removeEventListener(‘tap’, dropPresent)
– INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)
end
– Called prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )
–local group = self.view
print( “((destroying scene 1’s view))” )
– INSERT code here (e.g. remove listeners, widgets, save state, etc.)
end
– END OF YOUR IMPLEMENTATION
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )
– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )
– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )
– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )
return scene [import]uid: 75779 topic_id: 17828 reply_id: 77525[/import]
Okay I got my collision event to fire. just had to delay it a milli-second and send it to the correct scene. [import]uid: 75779 topic_id: 17828 reply_id: 77775[/import]
It works like a charm but I do have one question.
I have built all the logic in my game and I have a simliar world / game select as Angry Birds. Swipe through the worlds and pick a level. That works perfect in the storyboard.
My question is this, is it possible to show a popup or something that indicates that the level is loading, and when the level is loaded - wipe out the loading screen? Any suggestions or hints, where or how I should implement this?
Best regards, Joakim [import]uid: 81188 topic_id: 17828 reply_id: 79183[/import]
@Joakim: What I would suggest is you create an object separate from your scenes (similar to how the tabBar is implemented in the Storyboard and WidgetDemo sample projects), but make it your “loading” image and set the isVisible property to false initially (so it’s hidden).
Whenever you call storyboard.gotoScene(), simply set the isVisible property to true.
Then, within the “enterScene” listener for each one of your scenes, just set the isVisible property of that image back to false. [import]uid: 52430 topic_id: 17828 reply_id: 79300[/import]
@Jonathan, I will try this approach when I am back tonight, I get back with the result!
Thanks, Joakim [import]uid: 81188 topic_id: 17828 reply_id: 79353[/import]
Nope, that didn’t work either. It seems like the engine is having a lot of things to do, so therefore it doesn’t have time to show the “Loading…” sign. It is shown slightly, but that is when the level is loaded.
Any other suggestions of approach?
Best regards, Joakim
[import]uid: 81188 topic_id: 17828 reply_id: 79416[/import]
I have scenes which are parameter driven. Based on parameter values are the scene will look different. How can I use gotoScene considering the parameter decides the actual scene content? Even if I pass storyboard.params, it is showing the scene which was created at first call. I can remove the scene after each occuarance and the scene is recreated with different parameter values. But that defeats the purpose of caching scenes. Any ideas? [import]uid: 19297 topic_id: 17828 reply_id: 79777[/import]
@dirtyBit I’m also creating a ‘dummy scene’ if u had 20 levels would u also need 20 dummy scenes? I’d like to have 1 dummy scene and pass a variable from the level to the dummy scene which level to send it back to, but I can’t pass the variable. [import]uid: 75779 topic_id: 17828 reply_id: 80030[/import]
@rmckee282002,
Store a variable in the storyboard:
storyboard.level = "1\_1"
and then just read in your game logic scene. I am doing that and it works perfect.
Joakim [import]uid: 81188 topic_id: 17828 reply_id: 80031[/import]
I cannot do a Screen transition in the middle of a touch event: I have a touch event listener that calls onTouch function with ‘beginnig’, ‘middle’, and ‘end’ event phases.
I cant remove the touch event because the logic is you have two objects with touch eventlisteners. Say Object1 falls to the ground you have 5 seconds to move around Object2 to try to stop the ‘collisionScene’(Object1/ground). If the storyboard.gotoScene(‘collisionScene’) fires while you are still moving around Object2 the simulator crashes.
Removing the touch event listener from Object 2 in ‘exitScene’ doesn’t work because I believe it is in the ‘middle’ phase of the onTouch event. And what happens is it transitions to ‘collisionScene’ then the ‘end’ phase of the onTouch event is being called and it crashes the simulator.
Purging the scene in ‘collisionScene’ doent work either.
[import]uid: 75779 topic_id: 17828 reply_id: 80105[/import]
@ rmckee282002
As far as the last thing you said about removing a touch listener in the “middle” phase of an event, I don’t think that has an effect, because touch events (as far as I know) are just single time things that are thrown each frame, with the qualifiers of what “type” of touch event they are. However, if you are not properly removing your event listener but destroying your object, there could be an error. [import]uid: 62193 topic_id: 17828 reply_id: 80109[/import]
Im sorry I don’t understand. As far as I know a touch event is continuously being called when you move an object. The way I test this is by putting a ‘print’ statement inside of the onTouch function. It will print continuously when you move an object.
Can you please explain how a touch event is a ‘single time thing’ when you are touching an object and moving it across the screen?
with the qualifiers of what “type” of touch event they are-- I dont understand what your saying here please explain?
I think I am properly removing my event listeners.
Any more advice on this dilemna would be much appreciated! [import]uid: 75779 topic_id: 17828 reply_id: 80140[/import]
Hate to be a meto post but yea… I’m in the CGImageCreate: invalid image size: 0 x 0. error pool to.
My guess it’s due to me using ui.lua and those listeners not clearing.
edit: new build fixed that error, now just dealing with display object problems
I have to stay porting a non storyboard app to storyboard is kind of a pain. I miss python
ok cranky rant over, night.
[import]uid: 110373 topic_id: 17828 reply_id: 80127[/import]
Just FYI…
storyboard.purgeScene -vs- storyboard.removeScene().
I just wanted to make everyone aware of a little issue. I’ll try to create a sample and send it to ansca sometime in the next day or so but.
when using purgeScene and going back and forth to a few screens somehow the API gets confused or lost. Example.
Screen A loads
>> goto screen B ( purge screen A )
>> goto screen C ( purge screen B )
>> goBackTo screen B ( purge screen C )
>> goBackTo screen C ( purge screen B )
removing listeners and adding them back in the create scene. (purge forces rerun of create scene ).
Now after doing back and forth a few times with button events, somewhere we get lost and when clicking the button event will actually fire the reloading of the screen / lua file and not the proper button listener.
using removeScene instead seems to fix this flawlessly.
Good Luck,
Larry Meadows
DoubleSlashDesign.com
[import]uid: 11860 topic_id: 17828 reply_id: 80184[/import]
@ rmckee282002 : any time a finger is on the screen, touch events are constantly fired, as you noticed with your print statement (however, it is not continuous in the mathematical sense, there are a discreet number of times it fires). The first time you touch the screen the touch event is a “began” type, and after that, if the finger moves, “moved” type touch events are fired, and finally a “ended” event when you lift your finger off the screen. Each touch event that is fired is a separate event. So if you have an object that listens for touch events, it will be alerted many times, and your “touch” function for that object will be called. The only way the object knows that it is in the middle phase of a touch event is by checking what type of touch event was called. However, the object has no real way of knowing that any future touch events will be fired to it or not. In other words, the only way the object knows that it is being touched is that it is constantly reminded by receiving many touch listener calls. The object/listener is never in the middle of a “phase” of a touch, but your code may emulate that functionality by checking the “began”, “moved”, “ended” type of the touch events that are fired to it.
Sorry that’s a really bad explanation, but I don’t know how else to say it. In fact, there is a good blog post on events and listeners that you should read. It mentioned that any time an object is removed, any associated touch listeners are removed as well. So if you are in the middle of touching an object and the storyboard tries to remove it, there shouldn’t be a problem doing so, the only result is that the object will never see a “ended” type touch event.
Also, if the simulator is crashing, it’s probably something more serious that touch listeners. [import]uid: 62193 topic_id: 17828 reply_id: 80198[/import]
Please do you have link to this blog? Or who wrote it? That sounds like it it may be helpful
With storyboard we are removing all our objects with the purgeScene correct , so yes the event listener should be destroyed.
The only time the simulator crashes is when you keep your finger pressed on an object during a screen transition. Whats interesting is if you keep your finger pressed on the object the screen will transition and be fine until you actually release your finger from the screen in the next scene. Then it will crash.
that’s what makes me believe the ‘ended’ part of the onTouch function is responsible.
[import]uid: 75779 topic_id: 17828 reply_id: 80221[/import]
I’ve been working with the Storyboard API during the Global Game Jam this weekend, and I’ve been getting that weird malloc exception every now and then. I’ve been able to clear it up by being sure of the following 3 things:
- Always add something to the scene’s group view in createScene()
- Always make sure to remove all of your event listeners in exitScene()
- Don’t call gotoScene() from within enterScene(). Wrap it in a performWithDelay() if you have to (this is my most recent discovery after a great deal of painful trial and error). [import]uid: 82003 topic_id: 17828 reply_id: 83301[/import]