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
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
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
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
Uploaded it here if you wouldny mind taking a look...
http://scratch.mit.edu/projects/Gunstar_Red/5978
Offline
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
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
Offline
Look under numbers
Offline
Done that but it's still playing those extra frames, new version here...
http://scratch.mit.edu/projects/Gunstar_Red/6012
Offline
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
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
Yep that works, cheers guys.
Offline