bug in storyboard - offscreen objects

discovered a bug in storyboard, if the scene contains display objects that are beyond the extents of the screen it seems to mess up putting the scene exactly back in the right place when going back to the scene :frowning:

unfortunately I couldnt wait around for a replacement and to be honest I didnt need the transitions so I have my own storyboard replacement which simply treats scenes as cards and makes them visible and invisible to display (ie doesnt move them around)

if anyone wants the code I’ll publish it as open source. [import]uid: 74338 topic_id: 24822 reply_id: 324822[/import]

I have noticed what I believe to be the same bug. The main menu is never offset in any way, but continuing from there to another scene, it seems to appear at a random offset.

I love storyboard, but this is kind of a dealbreaker. I’d love to take a look at your solution, or hear of anybody else’s. [import]uid: 137902 topic_id: 24822 reply_id: 100938[/import]

my solution - includes being able to go back :wink:

[lua]-- VERSION
– -- This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
– -- http://creativecommons.org/licenses/by-sa/3.0/
– -- Absolutely no warranties or guarantees given or implied - use at your own risk
– -- Copyright © 2012 ChickenKatsu All Rights Reserved. http://www.chickenkatsu.co.uk/
–[[
there are bugs in storyboard which I cant wait around to be fixed
so this is a simpler replacement for it.

the bug is that scenes that have graphical objects that are
partly off screen cause the scene to be moved when it is restored.
which is pants

STAGE 1 - create a wrapper for storyboard — DONE
STAGE 2 - replace the content of the wrapped functions
]]–

require (“lib-events”)

– ####################################################################
– # cardscene object
– ####################################################################
cDisplayCard = {
name = nil,
view = nil,
purgeOnExit = false
}
function cDisplayCard:create( psName )
local oInstance = {}
setmetatable( oInstance, { __index = cDisplayCard } ) – sets inheritance

cLibEvents:instrument(oInstance)
oInstance.name = psName
oInstance.view = nil

return oInstance
end

– ####################################################################
– # cards object
– ####################################################################

cCards = {
history = {},
cards = {},
event={
enter = “enterScene”,
exit= “exitScene”,
destroy = “destroyScene”
}
}

–*******************************************************
function cCards:getScene(psSceneName)
return self.cards[psSceneName]
end

–*******************************************************
function cCards:createScene(psSceneName)
cDebug:print(DEBUG__INFO, “creating scene:”…psSceneName)
– check whether the scene exists
if self:getScene(psSceneName) then
error (“Scene with name :”… psSceneName … " allready exists" )
end

– create a scene object giving it an empty view and remember it in the cards table
local oScene = cDisplayCard:create(psSceneName)
self.cards[psSceneName] = oScene

return oScene
end

–*******************************************************
function cCards:purgeScene(psSceneName)
local oScene

cDebug:print(DEBUG__INFO, "purging scene: "…psSceneName)
if (psSceneName == nil) then
error (“no scene name - perhaps you did a . instead of :”)
end

– get the scene
oScene = self:getScene(psSceneName)
if oScene == nil then
error ("no scene exists with name: "… psSceneName )
end

– call listener
oScene:dispatchEvent({name=self.event.destroy})

– clean out the view
if oScene.view then
oScene.view:removeSelf()
oScene.view = nil
end

end

–*******************************************************
function cCards:gotoScene(psSceneName, psEffect, piEffectTime)
–print (“going to scene:”…psSceneName)
local sCurrent, oNewScene, oGroup

cDebug:print(DEBUG__INFO, “going to scene:”…psSceneName)

– get the new scene
oNewScene = self:getScene(psSceneName)
if oNewScene == nil then
error ("no scene exists with name: "… psSceneName )
end

– hide the current scene
sCurrent = self:getCurrentSceneName()
if sCurrent then
self:hideScene(sCurrent, psEffect, piEffectTime)
end

– create the view if it doesnt exist
if oNewScene.view == nil then
cDebug:print(DEBUG__INFO, “creating view on scene:”…psSceneName)
oNewScene.view = display.newGroup()
oNewScene:createScene()
end
oNewScene.view.isVisible = true

– enter the scene
cDebug:print(DEBUG__INFO, “entering scene:”…psSceneName)
oNewScene:dispatchEvent({name=self.event.enter})

– last thing rermember the new scene name
table.insert(self.history, psSceneName)
end

–*******************************************************
function cCards:hideScene(psSceneName, psEffect, piEffectTime)
local oScene

cDebug:print(DEBUG__INFO, “hiding scene:”…psSceneName)

oScene= self:getScene(psSceneName)
if oScene then
oScene:dispatchEvent({name=self.event.exit})
oScene.view.isVisible = false – then hide
end
end

–*******************************************************
function cCards:getCurrentSceneName()
local iLen, sSceneName

iLen = table.maxn(self.history)
if iLen > 0 then
return self.history[iLen]
else
return nil
end
end

–*******************************************************
function cCards:goBack( psEffect, piEffectTime)
local iLen, sNow, sLast, oScene

iLen = table.maxn(self.history)
if iLen < 2 then
print (“Can’t go back in storyboard history”)
return false
else
– hide the current scene
sNow= table.remove(self.history, iLen)
cDebug:print(DEBUG__INFO, “hiding scene:”…sNow)
self:hideScene(sNow, psEffect, piEffectTime)

sLast = self:getCurrentSceneName()
cDebug:print(DEBUG__INFO, “entering scene:”…sLast)
oScene = self:getScene(sLast)
oScene:dispatchEvent({name=self.event.enter})
oScene.view.isVisible = true
end
end[/lua]

and requires lib-events
[lua]cLibEvents = {}

–*******************************************************
–* call this method to add event listeners to a table
– usage dispatchEvent({name=“myevent”})
–*******************************************************
function cLibEvents:instrument(poObj)
if poObj[“addEventListener”] then
error (“cLibEvents: table allready instrumented”)
return
end

poObj.addEventListener = function(poSelf,psEvent, poListener)
cLibEvents:addEventListener(poSelf,psEvent, poListener)
end
poObj.dispatchEvent = function (poSelf,poEvent)
return cLibEvents:dispatchEvent(poSelf, poEvent)
end
end

–*******************************************************
function cLibEvents:addEventListener(poObj,psEvent, poListener)
if not poObj.EventListeners then
poObj.EventListeners = {}
end
poObj.EventListeners[psEvent] = poListener
end

–*******************************************************
function cLibEvents:dispatchEvent( poObj, poEvent)
local oListener, sEventNamSWSe, oCall

sEventName = poEvent[“name”]

if not poObj.EventListeners then
cDebug:print(DEBUG__INFO, "no event listeners for "… sEventName)
return;
end

cDebug:print(DEBUG__INFO,"dispatching event: "…sEventName)
oListener = poObj.EventListeners[sEventName]
if oListener then
if type(oListener) == “function” then
return oListener(poEvent)
else
oCall = oListener[sEventName]
if oCall then
return oCall(oListener,poEvent) --receiver only gets the last param , the first param is treated as self
else
error ("CLibEvents: method not found on listener - "…sEventName)
end
end
else
cDebug:print(DEBUG__INFO,“no Listener for event:”…sEventName)
end
end

–*******************************************************
function cLibEvents.makeEventClosure( poListener, psEvent)
local fnClosure

fnClosure = function(poEvent)
local oCall = poListener[psEvent]
return oCall(poListener, poEvent)
end

return fnClosure
end[/lua]

and lib-debug
[lua]-- VERSION
– -- This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
– -- http://creativecommons.org/licenses/by-sa/3.0/
– -- Absolutely no warranties or guarantees given or implied - use at your own risk
– -- Copyright © 2012 ChickenKatsu All Rights Reserved. http://www.chickenkatsu.co.uk/

– **********************************************************
– * LIB-DEBUG
– **********************************************************
DEBUG__NONE = 0
DEBUG__INFO = 1
DEBUG__WARN = 2
DEBUG__ERR = 3
DEBUG__DEBUG = 4

cDebug = {
DEBUG_LEVEL=DEBUG__NONE,
fileHandle=nil,
remoteURL=nil,
URLParam=“MSG”,
dateFormat="%d/%m/%Y %H:%M:%S"
}

– **********************************************************
function cDebug:print(piLevel, psText)
local sDebugMsg, sEncoded, sUrl, fnCallBack, sDate

if piLevel <= self.DEBUG_LEVEL then
sDate = os.date(self.dateFormat)

sDebugMsg = “L”…piLevel…" “…sDate…”: "…psText
print (sDebugMsg)
end
end[/lua] [import]uid: 74338 topic_id: 24822 reply_id: 100940[/import]