Browse Search Popular Register Upload Rules User list Login:
Search:
onCollide Animations Tutorial

Image:
screenshot of the scene

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:

Scene tag

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.
Please log in to rate this scene
edit
Similar scenes
Title: onCollide Scripting tutorial 1
Rating: 5.8889
Filesize: 78.45 kB
Downloads: 776
Comments: 7
Ratings: 3
Date added: 2009/12/11 01:54:47
Made with: Algodoo before v1.8.5
Rating: rated 5.9
download
Title: Material Name (OnCollide) Scripting Tutorial
Rating: 5
Filesize: 220.02 kB
Downloads: 897
Comments: 7
Ratings: 1
Date added: 2013/07/31 03:25:21
Made with: Algodoo v2.0.2 Edu
Rating: rated 5
download
Title: timing graph
Rating: 5
Filesize: 4.82 kB
Downloads: 456
Comments: 1
Ratings: 1
Date added: 2010/06/05 13:40:00
Made with: Phun
Rating: rated 5
download
Title: OnCollide bug
Rating: 5
Filesize: 23.97 kB
Downloads: 228
Comments: 0
Ratings: 1
Date added: 2009/09/23 17:55:16
Made with: Algodoo before v1.8.5
Rating: rated 5
download
Title: Snakilo box
Rating: 5
Filesize: 9.66 kB
Downloads: 602
Comments: 1
Ratings: 1
Date added: 2014/09/25 04:04:58
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: Oncollides as functions
Rating: 5
Filesize: 16.91 kB
Downloads: 586
Comments: 4
Ratings: 1
Date added: 2011/06/08 16:08:00
Made with: Algodoo before v1.8.5
Rating: rated 5
download
Thanks for the tutorial. I have a couple questions, 1-how did you add the _image1= , _image2=....etc to the script menu?
2- The alien has a transparent box yet the alien isn't transparent, how is that done?
3-What does post step do?
Last edited at 2013/12/06 16:54:04 by wild bill
Hi wild bill --
1. in the upper left corner of the menu, there is a blank text area where you can add variables or script, and you can monitor certain variables. Think of it like a window into the console. To add local variables to a geometry, simply add them in that text area. For example, to create a local variable called _image1, you simply type _image1 := "data". In this case, the data is a textureMatrix array. So, what I did was to position the texture in the circle using the texture tool, and then enter _image1 := textureMatrix. That creates the local variable "_image1". Then I repositioned the texture so that I can see a different word in the texture (which of course changes the textureMatrix) and then I created _image2 in exactly the same manner. In case you don't know, a "local variable" is one that can be read or written only within the geometry where it resides, and no other geometry can read or write it (without special script). Unlike a "scene.my." variable which is called a "global variable" because it can be read from or written to from the script menu of all geometries. Scene.my. variables are in the "root" scope, which is the console.

2. The alien started out as an animated gif. I used the free "Microsoft GIF Animator" program to divide up the animated gif into individual frames, and then I used PaintShop Pro (not free) to create a transparent background for each frame. I saved each frame in its own box (located on the right side of the scene). You must save each texture in a box (often hidden in the scene) so that Algodoo will save it with the scene. If you do not do that, then when your script uses the filename of the texture, it won't show up in the scene, and you will get a white box. This issue has bitten me in the butt a number of times!):lol:

Hope this helps.
Thanks Xray, also what does poststep do?
PostStep and update are both used for running script commands. Only the timing of each is slightly different. One executes the code during each displayed Algodoo frame, and the other executes the code during the simulation frequency timing. So, for example, if your sim.frequency is set to 100Hz, then the code will get scanned 100 times per second. If postStep is used, then the code gets scanned during each displayed frame which is adjustable with the Simulation Speed slider. Also, (and this is important for some applications), postStep only executes code while the simulation is running, and update executes code ALL the time, even when the simulation is stopped. There are some things that you might want to do before the user starts the scene, such as maybe initializingg a timer value to sim.time, etc. You can learn more about these and a lot more in the Algodoo forum. That's where I learned most everything that I know about scripting.
Last edited at 2013/12/06 20:48:02 by Xray
You are a huge help, thanks Xray!:tup:
You are very welcome!