This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-05-22 09:27:15

Gunstar_Red
Scratcher
Registered: 2007-05-22
Posts: 6

Mutiple costumes for same sprite?

Hi, just messing around making a little simple game. Have a character walking left and right with 12 walking frames. I want to add 3 more frames to make the character stop and look up when space bar is pressed.

However when I import the 3 look up frames they get included in the walk anim and played at the end of the walking frames.

Is there a way to stop Scratch from doing this, maybe sets of costumes?

Offline

 

#2 2007-05-22 10:22:18

weissjd
Scratcher
Registered: 2007-05-16
Posts: 64

Re: Mutiple costumes for same sprite?

I assume you're using "nextcostume" to switch costumes. One thing you could do is set a variable that would keep track of which costume you're on. Make sure you set the costume to the first costume and the variable to one when the script starts. Then add one to the variable every time you go to the next costume. Then put the nextcostume in an if-then-else. If the variable=12, switch to the first costume and set the variable back to one, otherwise do nextcostume and add one to the variable. That way you'll skip the three costumes that aren't part of the walking animation.

Depending on exactly what you're doing you may need to change this a bit, but that's the general idea.

Good luck with it,

Josh

Offline

 

#3 2007-05-22 11:26:52

Gunstar_Red
Scratcher
Registered: 2007-05-22
Posts: 6

Re: Mutiple costumes for same sprite?

At the moment I have the character so when you hold down left or right it cycle thru the animation, I have tried to work out how to use varibles and the nextcostume routine but it seems to mess up the timing of my anim.

Can I upload what I have already done any you could have a quick look at it?

Offline

 

#4 2007-05-22 11:37:33

weissjd
Scratcher
Registered: 2007-05-16
Posts: 64

Re: Mutiple costumes for same sprite?

Sure!

Offline

 

#5 2007-05-22 13:03:51

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Mutiple costumes for same sprite?

You do need a variable  (say "costume number")

Try

repeat 50
    change costume number by 1
    if costume number > max_costume
          set costume number to min_costume
    switch to costume costume number
    wait 0.1 sec

Offline

 

#6 2007-05-22 13:28:25

Gunstar_Red
Scratcher
Registered: 2007-05-22
Posts: 6

Re: Mutiple costumes for same sprite?

Uploaded it here if you wouldny mind taking a look...

http://scratch.mit.edu/projects/Gunstar_Red/5978

Offline

 

#7 2007-05-22 13:45:38

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Mutiple costumes for same sprite?

Make a variable  "cat_costume" for this sprite only

replace the next_costume on the arrow keys with

set cat_costume to (cat_costume+1)mod 16
switch to costume cat_costume

(This will always start with the first costume and do the first 16 costumes.
To pick a different range, you can use the if statement I mentioned above.)

Offline

 

#8 2007-05-22 14:09:19

Gunstar_Red
Scratcher
Registered: 2007-05-22
Posts: 6

Re: Mutiple costumes for same sprite?

Cheers Kevin.

The only bit I dont get is the (cat_costume+1)mod 16, where are those commands?

Sorry if I am being stupid  tongue

Offline

 

#9 2007-05-22 15:19:19

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Mutiple costumes for same sprite?

Look under numbers

Offline

 

#10 2007-05-22 16:25:36

Gunstar_Red
Scratcher
Registered: 2007-05-22
Posts: 6

Re: Mutiple costumes for same sprite?

Done that but it's still playing those extra frames, new version here...

http://scratch.mit.edu/projects/Gunstar_Red/6012

Offline

 

#11 2007-05-22 22:36:17

weissjd
Scratcher
Registered: 2007-05-16
Posts: 64

Re: Mutiple costumes for same sprite?

Ok, you're really close. If you go back to Kevin's post you'll see that he parentheses around cat_costume + 1. This means that it will add one before it mods by 16. You're doing the mod, then adding.

You need to rearrange that code so that you have a ( ) + ( ) block with cat_costume and 1 in the spaces. Then take a ( ) mod ( ) block, put the + block on the left and 16 on the right. It looks almost the same, but executes in a different order which is key.

The other problem is that once you've made that change your variable will range between 0 and 15 but you need 1 to 16. So in your "switch costume to" block you need to change it to switch to cat_costume + 1.

Then you should be good. Let me know if that works.

Josh

Offline

 

#12 2007-05-22 23:41:59

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Mutiple costumes for same sprite?

oops---I thought that the first costume was numbered 0, so that mod operators would work correctly.  Instead they have started the numbering at 1.  But specifying an out-of-range number for a costume works.

The costumes seem to be numbered starting at 1, with a number interpreted as
   (round(number) mod number_of_costumes) +1

Offline

 

#13 2007-05-23 01:39:59

Gunstar_Red
Scratcher
Registered: 2007-05-22
Posts: 6

Re: Mutiple costumes for same sprite?

Yep that works, cheers guys.

Offline

 

Board footer