Tier 1, AppGameKit 2017.9.4
I've been trying to extract a float value from some custom tweens added to a tweenchain using GetTweenCustomFloat1, GetTweenCustomFloat2 etc with no luck.
I can fake the desired behaviour using tween sprites but are custom tweens working in tween chains?
// Move a sprite using float values stored in an array.
SetWindowSize( 1200, 480, 0 )
SetVirtualResolution( 1200, 480 )
setPrintSize(24)
setErrorMode(2)
type subtypetween
ID as integer
endtype
type subtypeTweenChain
iChainID as integer
endtype
type subTypeEnt
iSpriteID as integer
iTweenID as subtypeTween[5]
tweenchain as subtypeTweenChain
endtype
type subtypeMyArray
fTime as float
fDuration as float
fX as float
fY as float
endtype
global myArray as subtypeMyArray[5]
global myEnt as subTypeEnt
global mySprite1 as integer
mySprite1 = createSprite(0)
setSpriteSize(mySprite1, 32, 32)
setSpriteColor(mySprite1, 0, 255, 0, 255)
myArray[0].fTime = 0.0
myArray[0].fX = 0
myArray[0].fY = 0
myArray[1].fTime = 0.5
myArray[1].fX = 199.5
myArray[1].fY = 225.2
myArray[2].fTime = 2.2666
myArray[2].fX = 40
myArray[2].fY = 235.6
myArray[3].fTime = 5.2
myArray[3].fX = 60
myArray[3].fY = 25.27
myArray[4].fTime = 7.25
myArray[4].fX = 232.1
myArray[4].fY = 135.27
myArray[5].fTime = 9.5
myArray[5].fX = 5.5
myArray[5].fY = 17.27
myEnt.tweenchain.iChainId = CreateTweenChain()
doSpriteTweenMethod() //this works
//doCustomTweenMethod() //this doesn't work
fStartTime = timer()
PlayTweenChain(myEnt.tweenchain.iChainId)
do
fTime# = Timer()
print("fTime#: " + str(fTime#))
print("myEnt.tweenchain.iChainId: " + str(myEnt.tweenchain.iChainId))
print("endtime: " + str(GetTweenChainEndTime(myEnt.tweenchain.iChainId ) ) )
print("playing: " + str(GetTweenChainPlaying(myEnt.tweenchain.iChainId)))
updateAllTweens(getFrameTime())
//when uncommented, this SHOULD position the sprite with floats from the Custom Tween method
/*
custX# = GetTweenCustomFloat1(myEnt.tweenchain.iChainId)
custY# = GetTweenCustomFloat2(myEnt.tweenchain.iChainId)
setSpriteX(mySprite1, custX# )
setSpriteY(mySprite1, custY#)
print("x: " + str( custX#,2))
print("y: " + str( custY#,2))
*/
sync()
loop
function doSpriteTweenMethod()
for t = 0 to myArray.length
fTotalTime# = fTotalTime# + myArray[t].fTime
iNext = t+1
if iNext > myArray.length
iNext = myArray.length
endif
endX# = myArray[t].fX
endY# = myArray[t].fY
myEnt.iTweenID[t].id = CreateTweenSprite(1.0)
SetTweenSpriteX(myEnt.iTweenID[t].id, beginX#, endX#, tweenlinear() )
SetTweenSpriteY(myEnt.iTweenID[t].id, beginY#, endY#, tweenlinear() )
myArray[t].fDuration = (myArray[t].fTime -myArray[iNext].fTime) *-1
setTweenDuration(myEnt.iTweenID[t].id, myArray[t].fDuration)
AddTweenChainSprite(myEnt.tweenchain.iChainId, myEnt.iTweenID[t].id, mySprite1, 0.0)
beginX# = endX#
beginY# = endY#
next t
endfunction
function doCustomTweenMethod()
for t = 0 to myArray.length
fTotalTime# = fTotalTime# + myArray[t].fTime
iNext = t+1
if iNext > myArray.length
iNext = myArray.length
endif
endX# = myArray[t].fX
endY# = myArray[t].fY
myEnt.iTweenID[t].id = CreateTweenCustom(1.0)
SetTweenCustomFloat1(myEnt.iTweenID[t].id, beginX#, endX#, tweenlinear() )
SetTweenCustomFloat2(myEnt.iTweenID[t].id, beginY#, endY#, tweenlinear() )
myArray[t].fDuration = (myArray[t].fTime -myArray[iNext].fTime) *-1
setTweenDuration(myEnt.iTweenID[t].id, myArray[t].fDuration)
addTweenChainCustom(myEnt.tweenchain.iChainId, myEnt.iTweenID[t].id, 0.0)
beginX# = endX#
beginY# = endY#
next t
endfunction
Problem 2: CreateTweenCustom doesn't work if its duration is set to 0. SetTweenDuration later in the code does nothing; minor but annoying to track down.
SetWindowSize( 800, 480, 0 )
SetVirtualResolution( 800, 480 )
my_tween = CreateTweenCustom(0) //custom tween doesn't work if initialised to 0. change it to 0.1 and it does work
SetTweenCustomInteger1(my_tween,0,1000,0)
do
// press left mouse button or tap screen to start
if GetPointerPressed() = 1
setTweenDuration(my_tween, 5.0)
PlayTweenCustom(my_tween,0.0)
endif
// get the tween value
tween_value = GetTweenCustomInteger1(my_tween)
print(tween_value)
UpdateAllTweens( getframetime() )
sync()
loop