lil boi blue
Member
|
ACTIONSCRIPT WITH ZOLTAN (good for making games) Index making dragable movie clips making objects move with keys object follows mouse making mouse a pen RPG inventory change frame when movie clips collide Making A Dragable Movie Clip 1) In flash Draw what you want to be draggable and make it a movie clip and give it a name. 2) Add this script to it to make it draggable Script-----> on (press) { startDrag(this); } on (release) { stopDrag(); } 3) Try the sucker out and if it works try to make something like mr patato head or...... stuff.... Making an object move with the keys 1) on the stage of your new flash document draw what you want to be moved by the keys make this a movie clip and give it a name 2) in the properties inspector also name the object the same name (this is crutial so make shure you do it) 3) make a new layer and ADD THIS SCRIPT TO THE NEW LAYER Script-----> *replace name with the name of your object name.onEnterFrame = function() {
if (Key.isDown(Key.UP) && Key.isDown(Key.RIGHT)) {
this._rotation = 45;
this._y -=15;
this._x +=15;
} else if (Key.isDown(Key.DOWN) && Key.isDown(Key.RIGHT)) {
this._rotation = 135;
this._y +=15;
this._x +=15;
} else if (Key.isDown(Key.UP) && Key.isDown(Key.LEFT)) {
this._rotation = -45;
this._y -=15;
this._x -=15;
} else if (Key.isDown(Key.DOWN) && Key.isDown(Key.LEFT)) {
this._rotation = -135;
this._y +=15;
this._x -=15;
} else if (Key.isDown(Key.UP)) {
this._rotation = 0;
this._y -= 30;
} else if (Key.isDown(Key.LEFT)) {
this._rotation = -90;
this._x -=30;
} else if (Key.isDown(Key.RIGHT)) {
this._rotation = 90;
this._x += 30;
} else if (Key.isDown(Key.DOWN)) {
this._rotation = 180;
this._y += 30;
}
}; And now your movie should work and you can control your movie clip and zoom it around ....... fun fun fun! Object followes mouse and you lose if it hits it 1) In a new flash document draw what you want to follow the mouse and make it a movie clip and name it, also name it in the "properties inspecter" otherwise the script wont work 2) create a new layer and give it this scipt (replace cat with the name you gave the object)---> setInterval(catchase, 5);
// call the catchase function every 5 ms
function catchase() {
// set x, y for cat closer to x, y of mouse
cat._x = cat._x + (_xmouse - cat._x)/100;
cat._y = cat._y + (_ymouse - cat._y)/100;
// test if x,y of mouse intersects cat
if (cat.hitTest(_xmouse, _ymouse, true )) {
// if it does, display a you lose message
cat.nextFrame();
// and change the name of the cat instance so
// it no longer follows the mouse
setProperty(cat, _name, "youLoseMessage");
}
// refresh screen
updateAfterEvent();
} 3) Double click on the movie clip you made and make a keyframe in the timeline, in the new frame delete the image and replace it with text saying 'you lose' 4)make a new layer and give it this script-----> stop(); making your mouse a pen thing 1) Open flash (if you dont know how to stop reading......now!) 2) add this script to flash and you done! its really easie but the final product is simple and kinda usless as well _root.onMouseMove = function() {
_root.lineStyle(1, 0xFF0000, 100);
_root.lineTo(_xmouse, _ymouse);
updateAfterEvent();
} Changing colour of the line 1) Replace the FF0000 part of the script with another colour code such as 0000CC = blue "these codes can be found when you add colours to these kind of messages"\ RPG Inventory This tutorial covers making item slots for a walkaround RPG. 1) Add this script to your first frame (you only need to put everything on one layer) ---> currentslotnum = 1;
stop ();
function addToslot (item) {
if (!item.found) {
item._x = eval ("itemSlot" + currentslotnum)._x;
item._y = eval ("itemSlot" + currentslotnum)._y;
item.found = true;
currentslotnum++;
}
} 2) On the stage draw what you want to be the items that can be picked up, make them movie clips and give them the following script ----> onClipEvent (enterFrame) {
if (_root.character.hitTest (this)) {
_root.addToslot (this);
}
} (character = The name of your character, so it can be changed depending on what you call it) 3) Draw what you want to be your character, make it a movie clip and give it the following script. Also name it in the propertey inspecter "character" ,without speech marks of corse. ----> onClipEvent (load) {
moveSpeed = 19;
}
onClipEvent (enterFrame) {
if (Key.isDown (Key.RIGHT)) {
this._x += moveSpeed;
} else if (Key.isDown (Key.UP)) {
this._y -= moveSpeed;
} else if (Key.isDown (Key.DOWN)) {
this._y += moveSpeed;
} else if (Key.isDown (Key.LEFT)) {
this._x -= moveSpeed;
}
} (This is a very very basic script but you can change the speed by altering the number in red) 4) Now draw your item 'holders' ,they could be rectangles (with no fills works best) and make them movie clips. If you hade 1 item that could be picked up only make one box but if you have two items that could be picked up make two boxes and so forth.. Now give the box(s) the names itemSlot1 changing the number for every box eg: itemSlot1, itemSlot2 ---> Dont forget to right itemSlot like this ---> itemSlot 5)And now your done! EXTRA---> Arrow keys to move and 'walk over' items to 'collect' (if you pick up 'axe' first it will go into item slot 1 but if you pick up 'sword' first it will go into item slot 1, there are no set slots for items) EG= http://haze.voodoolabs.net/inventory.swf Using a Hit Test to 'goto' Another Keyframe 1) In flash draw a image that you want to be your character and convert it to a MC (movie clip) 2) Name the character guy for now in the properties inspector and give it this script----> onClipEvent (load) { moveSpeed = 19; } onClipEvent (enterFrame) { if (Key.isDown (Key.RIGHT)) { this._x += moveSpeed; } else if (Key.isDown (Key.UP)) { this._y -= moveSpeed; } else if (Key.isDown (Key.DOWN)) { this._y += moveSpeed; } else if (Key.isDown (Key.LEFT)) { this._x -= moveSpeed; } } 3) Create the object that when it is hit by the 'guy' goes to another keyframe make it a MC and give it this script----> onClipEvent (enterFrame) { if (_parent.guy.hitTest (this)) { _parent.gotoAndStop("inn"); } }
< Message edited by lil boi blue -- 3/11/2006 22:35:46 >
|