tirsdag 2. november 2010

Case 4

Making stuff happen.


     Finally back after too many weeks off. In this case my assignment was to write code in flash to make stuff happen. I had to take the same symbols as before into my scene, but this time I was not allowed to drag them there manually. I had to write it in Actionscript to make it happen. I also had to make my character walk left and right with the arrow keys, without it walking out of the scene, all with the help of actionscript.

     And so my life as a living question mark begins. Luckily we were shown scripts for something similar in class so that I could see roughly were to start and stop, and how certain things happened. So when I put my own symbols in the already existing script, but with the appropriate names, it actually worked in the end. 
     But that was after Flash had finally decided to work with me. First my scene went completely white when I tried to run it. The most annoying part was that it didn’t show any errors, so I couldn’t see where the mistake was. I checked that my two files (.fla & .as) were saved the same place, I checked that the .as had the right target and that the .fla had the right class and I checked if I had saved it recently, but it was in fact correct. I let it go for then, and when I decided to try again the scene was not white, but still not the way it was supposed to be.  
      My symbols were thrown all across the scene, but luckily it wasn’t anything that was not capable of fixing. It turned out that the scripts that my teacher used to place the symbols didn’t work for me because I had my center points of the symbols a different place. I would, of course, not have been able to understand that unless I had been told. I had to write the exact pixels that the point was to be placed in, but it was a whole lot more logical, not to mention easier, than what we’d been shown earlier. 

     After the symbols finally were back at ground level I realized that a background was missing. I poked my finger in my eye until I was finally told that the only mistake was that I had written something wrong one place in the script. I had one letter that was bigger than the others. I fixed it. It worked. I hate scripts. 
     When all was back at its rightful place the character could walk left and glide right at the press of the arrow keys, but it could also disappear out of the scene. Half the work was done, only the worst left.

     Since I’m clueless about scripting I tried to google what I needed, but without luck. I wrote a whole lot of stuff in my script, none of which made any difference except from a few errors now and then. 
     Friday I asked for help in class because I really did not have a clue of what I was doing, what I had done or what I was supposed to do. I asked what I had to do to make my character stop at the edge of the scene. He had to explain it to me several times, but finally I kind of got what he was talking about. I really appreciated his patience. The answer he had was annoyingly logical. “Decide between which pixels your character is to be allowed to move, and the character will stop when it gets outside of them.” I will add a screenshot at the end.

     In theory I was now done with what the assignment asked, because it did not say that the character had to turn and walk in the opposite direction when I pushed the arrows, but it said “move across the screen with the help of the right and left arrow keys” so I decided I would wait with doing stuff I didn’t know how to do until we’re asked to do it.
      I tried to make the character turn with various methods but it ended up with the character walking backwards. I tried several times with the scaleX command but most of the time nothing happened, and when it finally did, it stretched my character across the entire scene. 

     After I resigned in my attempts of a moon landing, I decided I’d try to fix something which had annoyed me for a long time. The cloud. In the script I had it showed how the cloud would move over the scene without having to control it. But it moved across the scene, out of the scene and did not come back. I almost scratched a hole in my head trying to figure out how to make my cloud loop.
      I thought about what I had been told about the character not being able to move out of the scene and figured it had to be much the same. I decided that the cloud should move across the scene until it hit 0 pixels on x. Then it was to be back at 550 pixels, which is the width of my scene, and then move on. 
It actually worked, to my great surprise. The cloud looped. 
To myself I had just invented the wheel. I’ll add a picture of my great invention of cloud looping at the end of my wall of text.
I decided to call it enough for this case, since I had done what was described in the assignment, and I wanted to stop with a good feeling about scripting. 

Now I can do anything. Mount Everest next! But first I have to figure out which way is upwards, of course.


 The coordinates are a bit off on the cloud because the center point was not where it was supposed to, but it worked :)

Ingen kommentarer:

Legg inn en kommentar