smallbasic - Moving a shape across the screen and making it disappear -
this program have far works freezes when gets loop. have done program shapes doesnt it.
graphicswindow.height = 400 graphicswindow.width = 600 graphicswindow.title = "fairytail" graphicswindow.canresize = "false" animation() controls.buttonclicked = action sub animation graphicswindow.brushcolor = "black" firstmove = controls.addbutton("fireball", 300, 100) controls.move(firstmove, 0, 200) endsub sub action if controls.getbuttoncaption(firstmove) = "fireball" graphicswindow.brushcolor = "red" fireball = shapes.addellipse(20, 20) shapes.move(fireball, 135, 115) = 135 465 if <> 465 shapes.animate(fireball, i, 115, 1000) = + 1 program.delay(100) else shapes.remove(fireball) endif endfor endif endsub
what im trying move fireball across screen remove it. dont know how remove after animates.
there few problems program. first 1 this:
for = 135 465 if <> 465 shapes.animate(fireball, i, 115, 1000) = + 1 program.delay(100) else shapes.remove(fireball) endif endfor
if have statement closing after "i" = 465, don't need if statement.
the second problem, (and reason not running), this:
shapes.animate(fireball, i, 115, 1000)
what command does, moves shape set x , y coordinate on set time. means move shape currant position, i,115 after 1000 ms.
what need here shapes.move.
also, idea make loop execute outside subroutines. because if click button twice, try call subroutine while subroutine still running (because looping inside it) cause problems. here way make program:
graphicswindow.height = 400 graphicswindow.width = 600 graphicswindow.title = "fairytail" graphicswindow.canresize = "false" animation() controls.buttonclicked = action while 1 = 1 program.delay(10) if canmovefireball = + 1 '<--- increase position , move position shapes.move(fireball,i,115) endif if > 465 '<--- if fireball past 465 remove , ok add shapes.remove(fireball) canmovefireball = "false" endif endwhile sub animation graphicswindow.brushcolor = "black" firstmove = controls.addbutton("fireball", 300, 100) controls.move(firstmove, 0, 200) endsub sub action if controls.lastclickedbutton = firstmove if canmovefireball <> "true" '<--- make sure don't add fireball while first 1 moving graphicswindow.brushcolor = "red" fireball = shapes.addellipse(20, 20) shapes.move(fireball, 135, 115) = 135 canmovefireball = "true" '<--- tell it's ok move fireball endif endif endsub
i hope helps!!
--zock
Comments
Post a Comment