Discuss Scratch

DrDoe
Scratcher
46 posts

Cycle Through Certain Costumes?

I've asked this before but I have a weapon sprite with 8 different weapon animations each animation is 24 frames, how do i cycle through each sprite when the gun is selected
souleymane2
Scratcher
100+ posts

Cycle Through Certain Costumes?

make a repeat loop with a wait block and the next costume block
dimitrip
Scratcher
500+ posts

Cycle Through Certain Costumes?

Hi,

Instead of using next costume or the costume nr, I'd use the costume name.
Assume you have a Tommy gun, a Laser and a Bazooka.
Set
  • all frames for Tommy naming each costume T1 to T24
  • all frames for Laser naming each costume L1 to L24
  • all frames for Bazooka naming each costume B1 to B24
Then for your animation, use a variable Weapon (possible values “T”, “L” or “B”) and loop with a variable FrameNr that values 1 then 2 then … and finally 24.

And of course, set costume name acordingly:
switch costume to (join (Weapon) (FrameNr))

Greetz,
D.
DrDoe
Scratcher
46 posts

Cycle Through Certain Costumes?

dimitrip wrote:

Hi,

Instead of using next costume or the costume nr, I'd use the costume name.
Assume you have a Tommy gun, a Laser and a Bazooka.
Set
  • all frames for Tommy naming each costume T1 to T24
  • all frames for Laser naming each costume L1 to L24
  • all frames for Bazooka naming each costume B1 to B24
Then for your animation, use a variable Weapon (possible values “T”, “L” or “B”) and loop with a variable FrameNr that values 1 then 2 then … and finally 24.

And of course, set costume name acordingly:
switch costume to (join (Weapon) (FrameNr))

Greetz,
D.
Would you mind taking a look at the project
DrDoe
Scratcher
46 posts

Cycle Through Certain Costumes?

TheAnomalousPseudo
Scratcher
1000+ posts

Cycle Through Certain Costumes?

First thing would be to name them all jumping1, jumping2, jumping3, rolling1, rolling2, rolling3. This helps you keep track of which one is which without switching to the costume tab. Also make sure they are arranged in the correct order.

Then, each time you need to trigger the animation, use broadcast blocks. Also make a variable “animation.” Then, if nothing is pressed, set animation to 1. This will trigger the idle animation. Then make sure it sets the variable animation to 0 for 0.1 seconds every time it switches.

when green flag clicked
forever
if <(animation) = [1]> then
broadcast [idle v] and wait
end
if <(animation) = [2]> then
broadcast [running v] and wait
end
if <(animation) = [0]> then
stop [this script v]
end
end

Then, underneath each broadcast, first set costume to costume animation1. Count the total costumes, make a loop that brings you to the last costume, and repeat.

when I receive [idle v]
switch costume to [idle1 v]
repeat (#) //here put the number of costumes of this animation -1
next costume
wait (a) secs //depending on how many fps
end
dimitrip
Scratcher
500+ posts

Cycle Through Certain Costumes?

Nice graphics and nice world!
Did 24-frames-cycling for you here: https://scratch.mit.edu/projects/528355978/
Also added handling of changing weapon. Type “W”.
Greetz,
D.

Last edited by dimitrip (May 10, 2021 16:17:47)

dimitrip
Scratcher
500+ posts

Cycle Through Certain Costumes?

.. sorry, wrong URL. Here it is: https://scratch.mit.edu/projects/528355978/
WereWolf_Malfoy
Scratcher
6 posts

Cycle Through Certain Costumes?

forever
change [Costume #] by (1)
if <[Costume #] > [whatever costume # the walk cycle ends in]> then
set [Costume #] to [start of the cycle costume #]
end
if <<however you want the player to go right> or <however you want the player to go left>> then
switch costume to [Costume #]
end
end
dimitrip
Scratcher
500+ posts

Cycle Through Certain Costumes?

Ure welcome

Powered by DjangoBB