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
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
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.lifeTime = 10
bug.birthTime = elapsedTime
end
function draw()
if elapsedTime-bug.birthTime > bug.lifeTime then
-- remove the bug
end
end
Or, combine those two variables into one:
lifetime = ElapsedTime +10
...
if ElapsedTime>lifetime then
@Conner Here’s an example.
EDIT: Added circles.
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
Thank you for all your advice
you don’t remove them - you just don’t draw them
are there any ways make a sprite’s apearing effects? like spinning, moving, translating
@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?
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.
@Conner - Codea works completely differently.
I’ve written a lot of posts and ebooks that may help you, here.
thanks Dave?could u give a effects example?
Spin by rotating the sprite
Appear and disappear by altering size or by covering the sprite with a partly transparent rectangle
Tweens can add special effects
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.
@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
thanks Dave?its better to give more effects
@Ignatz You can also use tint()
to fade in or out an image, instead of drawing a transparent rectangle over it.