Hi scratchers, first of all
i'm a frenchy guy, so please be indulgent with my so poor english ....
well one of my very first script :
http://scratch.mit.edu/projects/jose6a/2469404
is about a fish who follow my mouse ... OK ... it works fine,
but, I have a pb with the changing costume.
If you download the script, you will see that event
when i don't change direction, the script change the costume...
I would like to optimise that script by changing costume
juste once time ! only when i change direction.
So, how can i detect that changing detection ?
i have "current direction"
i have "left direction" = -90
i have "right direction" = 90
Is it possible to change costume when i change direction ?
thanks for helping !
José
Offline
jose6a wrote:
Hi scratchers, first of all
i'm a frenchy guy, so please be indulgent with my so poor english ....
well one of my very first script :
http://scratch.mit.edu/projects/jose6a/2469404
is about a fish who follow my mouse ... OK ... it works fine,
but, I have a pb with the changing costume.
If you download the script, you will see that event
when i don't change direction, the script change the costume...
I would like to optimise that script by changing costume
juste once time ! only when i change direction.
So, how can i detect that changing detection ?
i have "current direction"
i have "left direction" = -90
i have "right direction" = 90
Is it possible to change costume when i change direction ?
thanks for helping !
José
The easiest way to do this would to have costumes named:
fish1
fish-1
Then you add the script:
if <not <(direction) = (0)> > switch to costume (join [fish] (([abs v] of (direction))/(direction))) endIf it ends up being backwards, just switch the costume names around
Last edited by AtomicBawm3 (2012-04-21 16:49:58)
Offline
Hi atomicBawm3 !
wellthankx a lot for your help, I have success with
my solution, but yours is nicer and better !
but first, i'll try to understand your solution, and how it works !
please don't hesitate to comment my own solution, i'm afraid, it's
a préhistoric one !
thanks again !
José from france (so, i supose my english is préhistoric too !)
Offline
well ... that works fine, but, i have one question :
is it not timeprocess consuming switching allways the costume, even if we don't
change direction with the mouse ?
the new : http://scratch.mit.edu/projects/jose6a/2486309
thanks a lot !
José
Offline
jose6a wrote:
well ... that works fine, but, i have one question :
is it not timeprocess consuming switching allways the costume, even if we don't
change direction with the mouse ?
the new : http://scratch.mit.edu/projects/jose6a/2486309
thanks a lot !
José
Since this is only happening for 1 sprite and it's a very simple change, no it isn't time consuming...also, this is in Scratch, so any method is going to delay almost just as much as this one...however, if you only want it to change when necessary:
//first create a variable named "old" and another named "new" When gf clicked set [old v] to (round(([abs v] of (direction))/((direction)+(.001)))) forever point towards [mouse-pointer v] move (3) steps set [new v] to (round(([abs v] of (direction))/((direction)+(.001)))) if <not<(new) = (old)>> switch to costume (join [fish] (new)) set [old v] to (new) endA few things:
Last edited by AtomicBawm3 (2012-04-21 20:08:27)
Offline
AtomicBawm3 wrote:
jose6a wrote:
well ... that works fine, but, i have one question :
is it not timeprocess consuming switching allways the costume, even if we don't
change direction with the mouse ?
the new : http://scratch.mit.edu/projects/jose6a/2486309
thanks a lot !
JoséSince this is only happening for 1 sprite and it's a very simple change, no it isn't time consuming...also, this is in Scratch, so any method is going to delay almost just as much as this one...however, if you only want it to change when necessary:
//first create a variable named "old" and another named "new" When gf clicked set [old v] to (round(([abs v] of (direction))/((direction)+(.001)))) forever point towards [mouse-pointer v] move (3) steps set [new v] to (round(([abs v] of (direction))/((direction)+(.001)))) if <not<(new) = (old)>> switch to costume (join [fish] (new)) set [old v] to (new) endA few things:
--the new formula is simply so that a direction of zero won't cause an error
--the reason the formula works is because it simply gets the sign (+ or -) from the direction...in this case, it will also get 0 if direction = 0
--keep the same costumes as before.
Fixed.
Offline