Image:
Author: Xray Group: Default Filesize: 182.59 kB Date added: 2013-12-06 Rating: 5.6 Downloads: 1289 Views: 417 Comments: 6 Ratings: 2 Times favored: 1 Made with: Algodoo v2.1.0 Tags:
|
This scene shows a couple of ways that you can make a collision between two objects display different textures. There are two examples as follows:
Example #1 is a jumping alien. Each time the alien bounces off the floor, a sequence of five images are shown which make it look like the alien jumps. The script is fairly simple, but it may be confusing if you have never worked with arrays. There is only one geometry (a box) which contains an array of five images. If you look at the script menu, you will see _imageArray = ["alien_jumping1.gif',"alien_jumping2.gif'..... and the last is "alien_jumping5.gif'] When each image gets shown in sequence with a short time delay between each one, it becomes animated and looks like the alien is jumping. You can substitute the five alien images with any other "gif" type of images to make any other animation each time the box hits the floor.
Example #2 works differently, and does not use an array. It has only one texture image that is made up of a bunch of small images. You can see the actual full image of the texture if you pan over to the far right of the scene. The script in the circle randomly picks a different texture matrix (1 of 9) which will display a different location on the texture. Think of it like a map. You can zoom out and see all of the cities in a large area, or you can zoom in to look at only one city and ignore all the others. Well, this scene works kind of like that. There are nine texture matrixes, and each one is focused on a different image on the texture. So, one textureMatrix will focus on "Zonk!" and another textureMatrix will focus on "WoW-Wow". The script uses the random function (rand.uniform01) to get a random number between 0 and 1. We need an integer between 1 and 9, and so we need to do a little math on the random number. It gets multiplied by 10, and the decimal portion of the result gets thrown away with the math.toint function. The resulting numbers then randomly pick a texturematrix each time the circle collides with the floor, and that will display a different portion of the texture.
I hope all this makes sense. If not, then please ask questions in the comments. |