Hi -
please be as specific as possible with exact statements needed so that I can get beyond leaving a scene with spineboy and have it work.
What is it exactly that I need to do please list the code?
Runtime:removeEventListener on? List exact Events to remove please and the exact syntax.
Please list the exact code to do before leaving the spineboy example running in a scene.
a spineboy example in a storyboard scene is below
---
This example shows spineboy inside storyboard scene
---
need to know how to gracefully
---
---
---
---
play.lua
---
---
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
---
include Corona's "widget" library
---
local widget = require "widget"
---
---
---
BEGINNING OF YOUR IMPLEMENTATION
---
---
NOTE: Code outside of listener functions (below) will only be executed once,
---
unless storyboard.removeScene() is called.
---
---
---
Called when the scene's view does not exist:
function scene:createScene( event )
local group = self.view
---
display a background image
local background = display.newImageRect( "res/bk_default.png", display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0
---
Title
local title = display.newText("Touch to go back", 0, 0, native.systemFontBold, 16)
title:setTextColor( 255,255,255)
title.x = display.contentCenterX
title.y = display.contentCenterY
title.name = "title"
---
beginspineboycode
local spine = require "spine-corona.spine"
local json = spine.SkeletonJson.new()
json.scale = 1
local skeletonData = json:readSkeletonDataFile("examples/spineboy/spineboy.json")
local skeleton = spine.Skeleton.new(skeletonData)
function skeleton:createImage (attachment)
---
Customize where images are loaded.
return display.newImage("examples/spineboy/images/" .. attachment.name .. ".png")
end
skeleton.group.x = 150
skeleton.group.y = 325
skeleton.flipX = false
skeleton.flipY = false
skeleton.debug = true
---
Omit or set to false to not draw debug lines on top of the images.
skeleton.debugAabb = true
skeleton:setToSetupPose()
local bounds = spine.SkeletonBounds.new()
---
AnimationStateData defines crossfade durations between animations.
local stateData = spine.AnimationStateData.new(skeletonData)
stateData:setMix("walk", "jump", 0.2)
stateData:setMix("jump", "walk", 0.4)
---
AnimationState has a queue of animations and can apply them with crossfading.
local state = spine.AnimationState.new(stateData)
state:setAnimationByName(0, "drawOrder")
state:addAnimationByName(0, "jump", true, 0)
---
state:addAnimationByName(0, "walk", true, 0)
state.onStart = function (trackIndex)
print(trackIndex.." start: "..state:getCurrent(trackIndex).animation.name)
end
state.onEnd = function (trackIndex)
print(trackIndex.." end: "..state:getCurrent(trackIndex).animation.name)
end
state.onComplete = function (trackIndex, loopCount)
print(trackIndex.." complete: "..state:getCurrent(trackIndex).animation.name..", "..loopCount)
end
state.onEvent = function (trackIndex, event)
print(trackIndex.." event: "..state:getCurrent(trackIndex).animation.name..", "..event.data.name..", "..event.intValue..", "..event.floatValue..", '"..(event.stringValue or "").."'")
end
local lastTime = 0
local touchX = 999999
local touchY = 999999
local headSlot = skeleton:findSlot("head")
Runtime:addEventListener("enterFrame", function (event)
---
Compute time in seconds since last frame.
local currentTime = event.time / 1000
local delta = currentTime - lastTime
lastTime = currentTime
---
Bounding box hit detection.
bounds:update(skeleton, true)
if bounds:containsPoint(touchX, touchY) then
headSlot.g = 0;
headSlot.b = 0;
else
headSlot.g = 1;
headSlot.b = 1;
end
---
Update the state with the delta time, apply it, and update the world transforms.
state:update(delta)
state:apply(skeleton)
skeleton:updateWorldTransform()
end)
---
end
Runtime:addEventListener("touch", function (event)
if event.phase ~= "ended" and event.phase ~= "cancelled" then
---
Runtime:removeEventListener("enterFrame",updateAnimation)
---
Make the coordinates relative to the skeleton's group.
touchX = event.x - skeleton.group.x
touchY = skeleton.group.y - event.y
else
touchX = 999999
touchY = 999999
end
end)
---
end spineboy code
---
Touch to go back
local function touched ( event )
if ("ended" == event.phase) then
storyboard.gotoScene( "menu", "fade", 500 )
end
end
background:addEventListener("touch",touched)
---
all display objects must be inserted into group
group:insert( background )
group:insert( title )
end
---
Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
---
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 )
local group = self.view
---
INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
end
---
If scene's view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
Runtime:removeEventListener("enterFrame",updateAnimation)
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 whenever 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