Tuesday 1 November 2011

Game Help

 Scrolling Background Tutorial


http://www.kongregate.com/games/Kongregate/shootorial-2








Create a Time Counter Bar

 onClipEvent(load) {
    timeCounter = 100; // set default width
    timeSpeed = 0.5; // set decrement rate
}

onClipEvent(enterFrame) {
    this._xscale = timeCounter; // set width of rectangle to equal % of counter left
  
    if (timeCounter>=timeSpeed) { // check if rectangle is still larger than 0 + decrement rate
        timeCounter -= timeSpeed; // reduce with of rectangle
    }
  
    if (timeCounter < 10) { // check if only 10% of bar left
        var colorful = new Color(this); // create new variable for colour of selected object
        colorful.setRGB(0xff0000); // set color to red
    }
}




Import sound effects to your game

  1. Import sound file (.mp3) to your Flash library
  2. Right-click on the file in your library and view Properties
  3. Check 'Export for Actionscript' and give the 'Identifier' field a name that you will reference in the AS code.  The example below has an Identifier of 'blast'
  4. Insert the following code on the event that you want the sound to play (eg crash sound should go on the hitTest event):
variableName = new Sound(this);  // Create variable that represents a sound associated with this movieClip object
variableName.attachSound("blast");  // Attach sound from our library with identifier of 'blast' to the new sound variable
variableName.start();  // Play the sound!
You can also specify a start frame and loop timeout for background music. 
variableName.start(0,99);  // Play sound from frame 0 (start of clip). Loop 99 times before stopping
Resources: 
http://www.kirupa.com/developer/actionscript/sound.htm
http://www.gotoandlearnforum.com/viewtopic.php?f=28&t=26222




Create a Barrier to stop your hero character flying out of the screen

Place the following code on your hero Movie Clip:

onClipEvent (enterFrame) { // every time the frame runs
if (Key.isDown(Key.UP)) { // when the UP key is pressed
if (_y>30)  // check if the center of the object is within 30px from the top of the stage
_y -=5;  // move the object up 5 pixels
}  //stop checking if the UP key is pressed
} // stop checking every time the frame runs




Respawn objects

Watch the following tutorial on how to randomly spawn enemies (eg Asteroids):





Random Colours for your spawned objects:

onClipEvent(load) {
rndColor = Math.round( Math.random()*0xFFFFFF );  // generate a random color coloredObject = new Color (this);  // colour of this object will be called 'coloredObject' coloredObject.setRGB(rndColor);  // set colour of this object to be the random colour
}



Random Sizes for your spawned objects:

onClipEvent(load) {
randomSize=random(80); // pick a number between 1 and 80 this._xscale=randomSize; // set width to equal random number this._yscale=randomSize; // set height to equal same random number
}



Random Rotation for your spawned objects:

onClipEvent(load) {
this._rotation= random(360); // set rotate angle starting position rotationRate=random(5); // set random rotation speed between 1 and 5 degrees per frame
}

onClipEvent(enterFrame) {
this._rotation+=rotationRate; // rotate frame by same value(speed) each frame
}

No comments:

Post a Comment