#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# A sprite Disappearing

Posts: 5

Im making a whack a bug game and i just need to make my bugs disappear after x amount of seconds. Does anyone have some code to make them disappear after x amount of seconds?

-Thanks

Tagged:

• Posts: 186

You can define a lifeTime variable for how long you want the bug to be alive and then test it against elapsedtime.

``````function makeBug()
bug = {}
bug.birthTime = elapsedTime
end

function draw()
-- remove the bug
end
end
``````
• Mod
Posts: 2,020

Or, combine those two variables into one:

``````lifetime = ElapsedTime +10
...
``````
• Mod
edited August 2015 Posts: 9,098

@Conner Here's an example.

``````displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)

function setup()
count=100
delay=.8    -- delay .8 seconds. Change value to desired delay time.
end

function draw()
background(40, 40, 50)
fill(208, 208, 208, 101)
count=count+1
if count>delay*60 then
count=0
while hold==rp do
rp=math.random(1,25)
end
hold=rp
end
pos=0
for x=1,5 do
for y=1,5 do
pos=pos+1
ellipse(x*180,y*140,130)
if pos==rp then
sprite("Planet Cute:Enemy Bug",x*180,y*140+25)
end
end
end
end
``````
• Posts: 5

• Posts: 5

@Kirl, what do you mean by --remove bug. I need help removing the bugs

• Mod
Posts: 5,396

you don't remove them - you just don't draw them

• Posts: 289

are there any ways make a sprite's apearing effects? like spinning, moving, translating

• Mod
Posts: 9,098

@firewolf You can do whatever you want with the sprite.

• Posts: 5

@lgnatz, ah. See im new to codea and lua and i thought you actually removed it. Thanks for telling me. How would you draw over it?

• Posts: 81

Codea is redrawing at up to 60 frames per second. No need to draw over it - just set the code to not draw it when necessary.

• Posts: 5

Thank you so much @iam3o5am

• Mod
Posts: 5,396

@Conner - Codea works completely differently.

I've written a lot of posts and ebooks that may help you, here.

• Posts: 289

thanks Dave，could u give a effects example？

• Mod
Posts: 5,396

Spin by rotating the sprite

Appear and disappear by altering size or by covering the sprite with a partly transparent rectangle

If you're not sure how to do any of this, you need to learn the basics of Codea graphics. See my link above, or the wiki link at the top of this page, for help with this.

• Mod
Posts: 9,098

@firewolf Here's my above program where I spin the sprite and increase its size.

``````displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)

function setup()
count=100
delay=.8    -- delay .8 seconds. Change value to desired delay time.
rot=0
end

function draw()
background(40, 40, 50)
fill(208, 208, 208, 101)
count=count+1
if count>delay*60 then
count=0
while hold==rp do
rp=math.random(1,25)
end
hold=rp
rot=0
end
pos=0
for x=1,5 do
for y=1,5 do
pos=pos+1
ellipse(x*180,y*140,130)
if pos==rp then
pushMatrix()
translate(x*180+20,y*140-10)
rot=rot+5
rotate(rot)
sprite("Planet Cute:Enemy Bug",0,0,rot/2)
popMatrix()
end
end
end
end
``````
• Posts: 289

thanks Dave，its better to give more effects

• Posts: 1,976

@Ignatz You can also use `tint()` to fade in or out an image, instead of drawing a transparent rectangle over it.