// Project: test_Tween
// Created: 2017-12-01
// v01.05
// for this you need two pictures in .png format, Sprint1.png and Sprite2.png, in project folder "media"
// Try with a picture of the Earth and the other of the Moon :)
SetScreenResolution(1280,790)
SetDisplayAspect(1.618) // golden aspect ratio
type tTweens
iSprite
iTween
endtype
Global gTweens as tTweens[0]
local idx as integer
for idx = 1 to 2 // two sprites
idSprite = CreateTween(idx, 50 + idx * 10, 1 + (idx -1) * 15, 0, 2*360 ) // create the sprite number idx, at start (50) and end (5) X positions, 2 rotations from 0º to 360º
PlayTweenSprite(gTweens[idSprite].iTween, gTweens[idSprite].iSprite,1)
next idx
repeat
UpdateAllTweens(GetFrameTime())
sync()
Until GetPointerPressed() //press any key to exit APP
end
for n = idSprite to idx step -1 // delete the created sprites and array too
DeleteSprite(gTweens[n].iSprite)
DeleteTween(gTweens[n].iTween)
gTweens.remove(n)
next n
end
// ------- End APP ---------
function CreateTween(pSprite, pX1, pX2, pA1, pA2) // we are just passing the start and end X positions for images
local newTween as tTweens
// create new sprite
newTween.iSprite = LoadSprite("Sprite"+str(pSprite)+".png")
setSpriteSize(newTween.iSprite,1,-1) // maintain the image proportion
// create new tween
newTween.iTween=CreateTweenSprite(newTween.iSprite)
SetTweenSpriteSizeX(newTween.iTween,80,0,6) // size 80 to 0, interpolation TweenEaseOut2()
SetTweenSpriteSizeY(newTween.iTween,80*GetSpriteHeight(newTween.iSprite),0,6)
SetTweenSpriteX(newTween.iTween, pX1, pX2, 6)
SetTweenSpritey(newTween.iTween, 0, 50, 6)
if pA1 <> pA2 then SetTweenSpriteAngle(newTween.iTween, pA1, pA2, 0) //rotating
SetTweenDuration(newTween.iTween, 50 )
gTweens.insert(newTween) //insert as new element in array
endfunction gTweens.length // return the sprite id
Help make AGK better by submitting an example for this command! (All examples are subject to approval)
// Project: test_Tween // Created: 2017-12-01 // v01.05 // for this you need two pictures in .png format, Sprint1.png and Sprite2.png, in project folder "media" // Try with a picture of the Earth and the other of the Moon :) SetScreenResolution(1280,790) SetDisplayAspect(1.618) // golden aspect ratio type tTweens iSprite iTween endtype Global gTweens as tTweens[0] local idx as integer for idx = 1 to 2 // two sprites idSprite = CreateTween(idx, 50 + idx * 10, 1 + (idx -1) * 15, 0, 2*360 ) // create the sprite number idx, at start (50) and end (5) X positions, 2 rotations from 0º to 360º PlayTweenSprite(gTweens[idSprite].iTween, gTweens[idSprite].iSprite,1) next idx repeat UpdateAllTweens(GetFrameTime()) sync() Until GetPointerPressed() //press any key to exit APP end for n = idSprite to idx step -1 // delete the created sprites and array too DeleteSprite(gTweens[n].iSprite) DeleteTween(gTweens[n].iTween) gTweens.remove(n) next n end // ------- End APP --------- function CreateTween(pSprite, pX1, pX2, pA1, pA2) // we are just passing the start and end X positions for images local newTween as tTweens // create new sprite newTween.iSprite = LoadSprite("Sprite"+str(pSprite)+".png") setSpriteSize(newTween.iSprite,1,-1) // maintain the image proportion // create new tween newTween.iTween=CreateTweenSprite(newTween.iSprite) SetTweenSpriteSizeX(newTween.iTween,80,0,6) // size 80 to 0, interpolation TweenEaseOut2() SetTweenSpriteSizeY(newTween.iTween,80*GetSpriteHeight(newTween.iSprite),0,6) SetTweenSpriteX(newTween.iTween, pX1, pX2, 6) SetTweenSpritey(newTween.iTween, 0, 50, 6) if pA1 <> pA2 then SetTweenSpriteAngle(newTween.iTween, pA1, pA2, 0) //rotating SetTweenDuration(newTween.iTween, 50 ) gTweens.insert(newTween) //insert as new element in array endfunction gTweens.length // return the sprite id