The 2DIY script archive

A resource containing Actionscript examples for 2Simples 2DIY software.

  • ActionScript
  • Animation Script
  • Collision Script
  • Start Button Script
  • Examples
  • Ideas
  • Help/Videos
  • Discuss

Edge of screen collisions

An earlier post about making a "Pong" style game, explained how it was possible (albeit in a very long and tedious way) to create the effect of a ball bouncing of a target using many, many monster elements. Thanks to Dan at 2Simple, there is a much easier way that creates the same effect.

If you were attempting to create a bounce when an object reached the edge of the screen, firstly add a sun element and make it transparent. Any code you give the sun element will be exectuted, but the graphic will not show on screen.

Within the sun element add the following code;

_root.car._x +=_root.h_velocity;

_root.car._y +=_root.v_velocity;

if (_root.car._x > 610 ) { _root.h_velocity = -_root.h_velocity; _root.car._x = 590;}

if (_root.car._x < 30 ) { _root.h_velocity = -_root.h_velocity; _root.car._x = 50;}

if (_root.car._y > 450 ) { _root.v_velocity = -_root.v_velocity; _root.car._y = 430;}

if (_root.car._y < 30 ) {_root.v_velocity = -_root.v_velocity; _root.car._y = 50;}

The first two lines define the movement effect when the object hits the wall (h and v are horizontal and vertical speeds (v for velocity). The last four lines tell the activity to reverse the direction of velocity when the element passes a certain pixel value (in the case when the object is less than 30 or greater than 610 pixels across the screen, less than 30 or more than 450 pixels down the screen.

In addition to the sun code - you will also need to add 

var v_velocity:Number = 10;

var h_velocity:Number = 7;

to the start game code (by right clicking on the green triangle). These codes set the initial values for the velocity variables used in the sun animation code.

Posted by Xannov in Collision Actionscript | Permalink

Reblog (0) | | Digg This | Save to del.icio.us |

Create a repelling object

In a journey activity, you can make a vehicle bounce off an object when it collides.

Within a journey activity select a "monster" and create an image. Right click on it then click on the green rotation arrow below the image to view the animation options that are attached to the monster. Click on the third option (what to do during a collision) and click on the "advanced" option. In the script box that appears, enter the following code;
_root.car._rotation+=30;

When your vehicle reaches the image it will cause the vehicle to bounce off in another direction

View an example; Download Repel

Posted by Xannov in Collision Actionscript | Permalink

Reblog (0) | | Digg This | Save to del.icio.us |

Cause an Oil Slick

In a journey activity, you can make a vehicle act as if it had driven onto an oil slick on the road.

Within a journey activity select a "monster" and create an oil slick image. Right click on it then click on the green rotation arrow below the image to view the animation options that are attached to the monster. Click on the third option (what to do during a collision) and click on the "advanced" option. In the script box that appears, enter the following code;

_root.car._rotation+=Math.random()*30-15;

When your vehicle passes over the slick it will cause a collision and create a fun effect

View example; Download Oil_slick

Posted by Xannov in Collision Actionscript | Permalink

Reblog (0) | | Digg This | Save to del.icio.us |

Make a monster throw a player from a platform

In a platform activity, you can make a monster throw a character from a platform when a collision takes place.

Within a platform activity select a "monster". Right click on it then click on the green rotation arrow below the image to view the animation options that are attached to the monster. Click on the third option (what to do during a collision) and click on the "advanced" option. In the script box that appears, enter the following code;
_root.player._y+=50;

View example; Download Throw_off_platform

Posted by Xannov in Collision Actionscript | Permalink

Reblog (0) | | Digg This | Save to del.icio.us |

Teleport a character to another location

When editing an activity that includes "monsters", you can use a monster setting to create a teleport location.


Within a platform activity select a "monster", right click on it and change the image to your teleport image. Once you are happy with your image, click on the green rotation arrow below the image to view the animation options that are attached to this image. Click on the third option (what do to during a collision) and click on the "advanced" option. in the script box that appears, enter the following code;

_root.player._x=400; 
_root.player._y=20;

Where x is a value for the location horizontally on screen between 0 - 640 and y is a value for the vertical position between 0 - 480. Note that in both cases, 0 is found at the top left of the screen. Download this handy screen position guide to help;


Now when your character runs over the teleport image, your character will disappear and reappear in the designated location.

View example; Download Teleports

Posted by Xannov in Collision Actionscript | Permalink

Reblog (0) | | Digg This | Save to del.icio.us |

« Previous Articles

Search

Recent Posts

  • 2DIY with Gifted and Talented groups
  • Making characters fly (and other effects)
  • High Lawn Primary Games
  • Creative Learning
  • Gallons of Games
  • Games Pod Creations
  • Kensington Avenue Primary 'Games Pod'
  • Actionscript Tutorial No.8
  • ActionScript Tutorial No.7
  • ActionScript Tutorial No.6

Recent Comments

  • Xannov on Discuss
  • Angela Canas on Discuss
  • Xannov on Discuss
  • Angela Canas on Discuss
  • Xannov on Discuss
  • Ali on Discuss
  • Xannov on Discuss
  • Max Wainewright on Discuss

Archives

  • June 2011
  • May 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010

More...

2Simple Talk

login
Follow @xannov

| The 2DIY script archive |

Design by @xannov