|
Post by atomose on Jan 5, 2023 6:36:34 GMT -5
hi,
how is it possible to slow down the animation of a sprite in a loop? Let me explain: when using cyclesprite the cycle is done at each loop. if you have low timers, you have a sprite that cycles way too fast. the solution I found is to add frames in the cycle. for example instead of doing
"addsprite name1 sprite sprite"
I do
"addsprite name1 sprite sprite sprite sprite sprite sprite"
it allows to have a slower cycle but it remains a visual illusion ... is there not another possibility to control the speed of the cycle while keeping the loop timer constant?
thx
|
|
|
Post by Rod on Jan 5, 2023 8:37:41 GMT -5
You can move the image animation yourself with spriteimage command instead of cyclesprite.
So you might have a counter that clocks from one to four. Some sprites move image if counter is >1 or every cycle, some sprites move image if counter is =2, half speed some sprites move image if counter =4, quarter speed. Then counter gets reset.
So in each cycle only certain sprites move image. If you have im1 im2 im3 you can keep a counter for each sprite image and cycle round the images
|
|
|
Post by atomose on Jan 5, 2023 10:29:55 GMT -5
Won't that slow down the loop? the interest of the cyclesprite is that it takes 1 order ^^
|
|
|
Post by Rod on Jan 5, 2023 14:25:19 GMT -5
The loop still runs full speed though the counter checking will add a little time. The sprites are still redrawn every loop but the clocked ones just don’t change image until the second or fourth cycle.
Cyclesprite is automatic but it redraws every sprite image every loop, spriteimage only redraws (changes) the sprite image occasionally so saving a little time. But this is blitter time, very very fast.
If you have your sprites in groups, fast, slow, slower then the counter manages whole groups, if your sprites are all eight images then a single image counter manages a group of sprites to. So too the xy movement can be fast, slow, slower as well as the image cycling.
However, half speed and quarter speed are very noticeable differences. A hero that buzzes about and enemies that plod about might not be what you want. Changes in the xy movement offer more subtle differences
|
|
|
Post by atomose on Jan 5, 2023 16:15:58 GMT -5
well i tried spriteimage but i have crash everytime ... can you show me with simple code example pls ^^ thx
|
|
|
Post by Rod on Jan 5, 2023 16:57:09 GMT -5
Away from home but will do an example in a day or so.
|
|
|
Post by Rod on Jan 7, 2023 6:42:43 GMT -5
OK, this shows four sprites that have a four image animation. They get random movement deltas. You might need to run it a few times to see what is going on. The animation (cycle) is slowed down for sprite 3 (half speed) and 4 (quarter speed) but sprites 1 and 2 cycle at full speed. The demo shows me that xy movement is just as important as cycle speed.
'get the sprite images and background loadbmp "s1", "sprites\smiley1.bmp" loadbmp "s2", "sprites\smiley2.bmp" loadbmp "s3", "sprites\smiley3.bmp" loadbmp "s4", "sprites\smiley4.bmp" loadbmp "landscape", "sprites\bg1.bmp"
'open a window and graphicbox nomainwin WindowHeight = 300 WindowWidth = 400 graphicbox #w.g, 0, 0, 400, 300 open "sprite test" for window_nf as #w #w "trapclose [quit]"
'add a background #w.g "background landscape" 'add sprite info dim si(4,5) global sx,sy,sxd,syd,si sx=1 sy=2 sxd=3 syd=4 si=5 for n = 1 to 4 #w.g "addsprite s";n; " s1 s2 s3 s4" si(n,sx)=int(rnd(0)*300) si(n,sy)=int(rnd(0)*200) si(n,sxd)=int(rnd(0)*4) si(n,syd)=int(2-rnd(0)*4) si(n,si)=1 #w.g "spritexy s";n;" ";si(n,sx);" ";si(n,sy) next #w.g "drawsprites"
[cycle] timer 0 'sprites 1-2 move every cycle n=move(1) n=move(2) 'sprite 3 moves half speed if counter=2 or counter=4 then n=move(3) 'sprite 4 moves quarter speed if counter=4 then n=move(4) counter=counter+1 if counter=5 then counter=1 #w.g "drawsprites" timer 50,[cycle] wait
[quit] timer 0 close #w end
function move(n) 'move xy si(n,sx)=si(n,sx)+si(n,sxd) si(n,sy)=si(n,sy)+si(n,syd) 'roll round screen if si(n,sx)<0 then si(n,sx)=si(n,sx)+400 if si(n,sx)>400 then si(n,sx)=si(n,sx)-400 if si(n,sy)<0 then si(n,sy)=si(n,sy)+300 if si(n,sy)>300 then si(n,sy)=si(n,sy)-300 #w.g "spritexy s";n;" ";si(n,sx);" ";si(n,sy) 'roll round image #w.g "spriteimage s";n;" s";si(n,si) si(n,si)=si(n,si)+1 if si(n,si)=5 then si(n,si)=1 end function
|
|
|
Post by atomose on Jan 7, 2023 12:58:24 GMT -5
I'm totally lost but thanks for the example I'll try to understand ^^
|
|
|
Post by Rod on Jan 7, 2023 14:52:31 GMT -5
It’s fairly easy. Sprites move and cycle their image at your command. So you can have sprites that cycle slowly and or move slowly. But visually, small movements are just as effective as slow cycles. Small movements are easier to code, so I would forget about slowing the cycle.
|
|