I was bored of Game Guru's static prompts, so I decided to try and create something visually more akin to the old FPS Creator prompts we used to have. I've been using
an animated sprite script created by smallg to great effect to bring up prompts at the certain key moments in my level. These rely on .png image sequences I created in Adobe After Effects that are over 200 frames long. Now that I've added a few, the level loads pretty slowly as it has some 700 sprites to load already, and I'd like to do more prompts like this throughout my level.
It would be a lot easier if there was a script that simply animated one sprite to do the same movement. This is what I want the sprite to animate like:
(^ This video uses the animated sprite script smallg made, with some minor amendments)
And this is how far I've got with my script:
local spritetrigger = {}
local spr_y = {}
local delay = 10
local sprite_hold = 3000
function maths_playground_init(e)
spritetrigger = 0
spr_y = 75
prompt_wasd_img = LoadImage("gamecore\\sprites\\wasd\\wasd_30.png")
prompt_wasd_spr = CreateSprite(prompt_wasd_img)
SetSpriteSize(prompt_wasd_spr,21,-1)
SetSpritePosition(prompt_wasd_spr,200,200)
SetSpriteColor(prompt_wasd_spr,255,255,255,255)
end
function maths_playground_main(e)
if g_Entity[e]['plrinzone']==1 and spritetrigger == 0 then
StartTimer(e)
spritetrigger = 1
end
if spritetrigger == 1 then
if GetTimer(e) > delay then
StartTimer(e)
if spr_y > 65 then
spr_y = spr_y - 0.1
SetSpritePosition(prompt_wasd_spr,40,(spr_y))
elseif spr_y > 64.9 then
StartTimer(e)
spritetrigger = 2
end
end
end
if spritetrigger == 2 and GetTimer(e) > sprite_hold then
StartTimer(e)
spritetrigger = 3
end
if spritetrigger == 3 then
if GetTimer(e) > delay then
StartTimer(e)
if spr_y < 75 then
spr_y = spr_y + 0.1
SetSpritePosition(prompt_wasd_spr,40,(spr_y))
elseif spr_y == 75 then
spritetrigger = 4
Destroy(e)
end
end
end
end
This makes the sprite pop up, hold for 3 seconds, then go back down and disappear. However, whilst I know that sprite opacity
can be dynamic and controlled with a script, I don't know where to add the commands or what would be the right way to go about it. I also don't like the way the sprite currently moves, in a very linear way. As you'll see from the video above, I want the sprite to decelerate to halt smoothly, then accelerate out. I have a feeling this could be controlled with some kind of sin or cosine function but my maths knowledge isn't sufficient to know what I'm looking for (or where to put it, or how to write it).
I bow to those more learned scripters than me, and ask for your help!
AE
P.S. Sprite opacity is controlled using the SetSpriteColor (sprite name,r,g,b,a) command, with alpha having a value between 0 and 255. Any equation that returns a value outside of this will cause a runtime error.