View Full Version : advanced help needed, flash example provided
jolteon77
June 1st, 2007, 01:11 AM
Hello! I registered today in hopes of talking to someone. In the following flash is everything I need guidance on of action scripts I've long since tried and failed on, or can't figure out at all. It's an rpg type thing, and, well you'll see in the flash. Any help with ANYthing will be greatly appreciated, and thanks;)
http://i3.photobucket.com/albums/y75/77jolteon77/puppytime.swf
pingnak
June 1st, 2007, 03:46 AM
Chase the mouse: _xscale=-100; when the mouse X is greater than the sprite X. However, many things don't mirror quite right. For that, you'd have to make two (or more) MovieClips of the character for however many angles it will run. It might run right at the 'camera', or away from it, for instance. That would require some more code to wrap several MovieClips with one and set which one plays according to which way the dog is facing.
I think most of the animation control problems are solvable by making a 'Dog' MovieClip class and implementing it as a collection of MovieClips to be added/removed from 'Dog', along with code to control it according to what 'Dog' is doing. Give it an attachment point on its mouth to grab things, and add/remove whatever MovieClip things to the mouth as you see fit.
The last else for 'Down' was what killed your animation for the 8-way walker. Add a flag to determine whether the dog is moving, and animate accordingly.
onClipEvent(enterFrame){
var bMoving:Boolean = false;
if(Key.isDown(Key.LEFT)){
this._rotation = -1;
this._x -= 10;
_xscale = 90;
bMoving = true;
}
if(Key.isDown(Key.RIGHT)){
this._rotation = 1;
this._x += 10;
_xscale = -90;
bMoving = true;
}
if(Key.isDown(Key.UP)){
this._y -= 10;
this._rotation = 0;
bMoving = true;
}
if(Key.isDown(Key.DOWN)){
this._y += 10;
this._rotation = 0;
bMoving = true;
}
if( bMoving )
{
this.gotoAndStop(2);
}
else
{
if(Key.isDown(Key.SHIFT)){
this.gotoAndStop(3);
}else{
this.gotoAndStop(1);
}
}
}
As far as the 'Z' or 'depth' or 'ordering' with the tree is concerned, you can move the dog to different depths by re-attaching it at different depths. Look up the relevant "Managing movie clip depths" topic in the ActionScript help.
jolteon77
June 1st, 2007, 04:52 AM
Chase the mouse: _xscale=-100; when the mouse X is greater than the sprite X. However, many things don't mirror quite right. For that, you'd have to make two (or more) MovieClips of the character for however many angles it will run. It might run right at the 'camera', or away from it, for instance. That would require some more code to wrap several MovieClips with one and set which one plays according to which way the dog is facing.
I think most of the animation control problems are solvable by making a 'Dog' MovieClip class and implementing it as a collection of MovieClips to be added/removed from 'Dog', along with code to control it according to what 'Dog' is doing. Give it an attachment point on its mouth to grab things, and add/remove whatever MovieClip things to the mouth as you see fit.
The last else for 'Down' was what killed your animation for the 8-way walker. Add a flag to determine whether the dog is moving, and animate accordingly.
onClipEvent(enterFrame){
var bMoving:Boolean = false;
if(Key.isDown(Key.LEFT)){
this._rotation = -1;
this._x -= 10;
_xscale = 90;
bMoving = true;
}
if(Key.isDown(Key.RIGHT)){
this._rotation = 1;
this._x += 10;
_xscale = -90;
bMoving = true;
}
if(Key.isDown(Key.UP)){
this._y -= 10;
this._rotation = 0;
bMoving = true;
}
if(Key.isDown(Key.DOWN)){
this._y += 10;
this._rotation = 0;
bMoving = true;
}
if( bMoving )
{
this.gotoAndStop(2);
}
else
{
if(Key.isDown(Key.SHIFT)){
this.gotoAndStop(3);
}else{
this.gotoAndStop(1);
}
}
}
As far as the 'Z' or 'depth' or 'ordering' with the tree is concerned, you can move the dog to different depths by re-attaching it at different depths. Look up the relevant "Managing movie clip depths" topic in the ActionScript help.
(Me) DEERRHHHH.......DUUUHH.......WHAT?? I understand that at about none-ty none point none percent....
Is there some ultra uber tutorial somewhere that I've been missing? It's like your speaking chinese!... WOW! Well, I am still new. I don't understand one bit of that, but boy am I glad I finally signed up to ask someone! There is no way I would've figured any of that out on my own. If I ask you to clarify anymore, we'll be here until either one of dies :), but if you don’t mind, could you please explain attachment points a little more? I tried looking that up real quick for clarification and didn’t find a single thing.
I do understand the concept of what you’re asking about chasing the mouse, but I've never heard of that before, or that extra code you put in for going 8 directions. At least now I now what I need to figure out, and what I need to look for and learn about.
Thanks for your help and setting me straight. I’ve got a lot of tutorials to find....
pingnak
June 1st, 2007, 02:47 PM
OK, sorry for talking 'techie' at you. Don't worry about it. Many people have said I am a 'poor communicator'. Also, different game programmers from different environments have completely different vocabularies.
I can tell you're more an artist than a coder so far... and I gotta say, it's a cute li'l doggy.
An attachment point is nothing more than {x,y} relative to the origin of the thing that you want to attach things (such as a bone) to the character ('Dog').
You would generally add some data and functions to your 'Dog' class with an x,y for the mouth, and a little bit of housekeeping for the thing. If you attach the MovieClip to the dog, it will stay with the dog at the same relative position wherever it goes (and scale and rotate), just as if you'd drawn it there.
// Dog.as pseudocode - not compiled or tested; for example only
class Dog extends MovieClip
{
function Dog()
{
}
// Data for carrying something around
var mouthX:Number = -32; // Point where attachments appear, relative to dog's origin
var mouthY:Number = -24;
var attached:MovieClip; // Thing the dog is carrying (probably an Inventory Item)
// Attach something to mouth, return what was previously attached (replaces it)
function attachMouth( attach:String ):MovieClip
{
var ret:MovieClip = attached;
ret.removeMovieClip();
attached = this.attachMovie("i"+attach, attach, this.getNextHighestDepth(),{_x:mouthX,_y:mouthY});
// Note, mouthX,mouthY will need to be translated, or have a table of them made
// for different orientations of dog (i.e. pointing left/right)
return ret;
}
// Detach something from mouth, return what was previously attached
function detachMouth():MovieClip
{
var ret:MovieClip = attached;
attached = null;
ret.removeMovieClip();
return ret;
}
}
In more complicated games with configurable characters, you might 'Attach' a sword, clothing items, etc. from the inventory. Then you'd have a collection of points.
Handling various things in the world (removing them from the scene, adding them to the dog, then removing them from the dog and adding them to the scene) would be easier with AS3, where you can pass around Sprite and MovieClip objects by reference, without loading them 'from scratch'.
As far as the tree, I can elaborate a little further. Once upon a time, long, long ago, I worked for Sierra On-Line and TSN, and this is what they did with depths in the class libraries for the SCI interpreters. Z was considered 'hopping' or 'flying', and subtracted an offset from screen Y, and didn't affect the depth. Notice that depth and Y are similar in a 2D presentation. You can modify the dog's Depth each cycle as Y changes (with the value of _y, if you like) to relatively match where the character will be in front of or behind things in the scene. Keep the origin (grab point) of the dog, or any character in the scene at bottom, center (at the feet). That makes tracking depth with Y much easier.
jolteon77
June 2nd, 2007, 08:20 PM
I can tell you're more an artist than a coder so far... and I gotta say, it's a cute li'l doggy.
Thanks and your 1000% correct on that one. I most definitely am more comfortable making and animating MCs than stressing out on their codes. You’re still speaking ancient Chinese to me; I have no idea on how to go about on your suggestions. I guess I just need to wait for another flash course to open up (if they give another course for flash) and keep learning the basics. Until then, I'm more comfortable just being handed the codes I need, and learning from that. So, since I know how people hate just handing out codes for free, here's another question- Can we ask to trade action script codes for fully operable character MCs? My strongest areas are creatures (griffins, dragons, or any other mythical creature, dinosaurs, all mammals, monsters *give specific details*, and I LOVE drawing wolves!), but I am getting better with humans (thank Jesus :). I’m still fresh with special effects concerning attacks (thunderbolts, fire blasts, energy stuff, etc), but I could definitely make the MC doing that stuff. I only ask that you give me credit in whatever you use it for. If anyone would like to see a sample of my work, just drop me a PM. I need code for items as specified in the above 'please help flash' the most right now. Thanks though for trying Pingnak, I need more help than I realized :)
mentega
June 3rd, 2007, 03:49 PM
im also a newb with action script so i dont know if this gonna work well... but recently i also made some interactive for my school project that requires me to have a character that can picked up an object....
what i used is a hidden hitTest box (or whatever shapes) inside the character movieclip (in your case; dog) instead of scripting it which is what pingnak telling you to do, so if you put it on the dog you'll do a hit test of if mc_dog.hitBox(hitTest(bone)) then pick it up..... something like that
and bout your "rotating" dog problem.... as far as "natural-like movement" concerned, your current mc cannot be used to follow a player (or mouse pointer) other than going left or right direction... if you want to make a dog that follows the player up then it will be something like top-down view... to the least, you need to make different animation sets that loops for walking up and walking right directoins... the left sides can be scripted using xSclae property while moving down, right-down or right-up can be done by rotating the moving-up animation
if you have no idea what xScael does, you might want to look at my project and see how the character flipped when moving right or left, it's still on early stages (i haven't even colored the other character yet lol) but i think it should gives you idea how to use xscale to flip (http://www.swfpages.com/view/105966.htm)
as for "dog chase mouse" problem, i also made a small project which i was told to develop a simple a.i similiar to yours... but i have added to the "a.i" script to also recognize how far it is from it's target so if it's still far enough it will run at full speed, at certain distance it will slow down (and i also add some conditions that allow it to either think and back off or attack you straight away) (http://www.swfpages.com/view/122200.htm)
i think you can use that to solve your "always run when chasing" problem by using the same way like mine; make if else statement to determine the speed by distance from your target, if it close enough, then tell your dog to walk
for your tree with blue bar problems.... since your dog can came in any angle including above the tree (should the player have control over it) i really think you need a big, tree sized blue box with registration point on the TOP of the box's or tree's... then on hit test, change the _y of the dog to the _y of the tree (which is the top of it because we put the registration point on the top) instead of messing with the movement speed of x or y
my best suggestion for you is to press F1 in flash and start searchign on the Action Script Book help..... my experience suggest that in practice i actually got more scripts and better understanding with my good ol FLASH HELP and try out the scripts that you found there than searchign tutorials on web which even if i found one makes me prone to copy pasting stuff and when stuck, i'll remain stuck as is... without understanding... (and possibly getting plagiarism trouble if i do that on my school project :krazy: )
pingnak
June 3rd, 2007, 04:38 PM
Reciprocal Art For Code+Credits and Code For Art+Credits
Now that's an interesting proposal. I do indeed need art.
There probably ought to be a forum here just for that. I've met precious few artists who could code, and precious few programmers who could draw.
'Programmer Art' is synonymous with 'Stick Men'. Give a five year old a box of crayons, and they'll do something approximating what you'll see a typical programmer do. Most programmers don't have the patience to do 'quality art'. It's not their thing.
And the code I've seen come out of artists... the horror... the horror.... Same deal. Most artists don't have the patience to deal with programming. It's not their thing.
It's one of the core weaknesses of independent Flash authoring, IMHO.
Anyway, what we need is an exchange contract/license. Essentially, this is a 'work for hire' agreement, and it needs to be legal and iron-clad. There can't be any misunderstandings later on if the game (beyond all expectations) becomes a 'national sensation'. Success can be the ultimate disaster if the license and contract aren't done right. Where something could have grown to the sky, litigation can destroy the value of the whole IP, and wipe out most, even ALL of the potential profit from it.
Work for hire means that each party received the 'pay' (in the form of services) for their work, and that is 100% of what is ever owed. I think 'Work for Hire' is the form of agreement that would need to be pursued. I asked for an astronaut (or bunny or whatever) and you gave me one, and I wrote code for you, and we worked out the kinks either way, and that's the end of the deal. If you get to be a zillionaire, more power to you, but you don't owe me anything but my name in the credits. Likewise, I don't owe you if I hit it big, but your name in the credits. It's the simplest arrangement and there's no quibbling about how the accounting's done. A product can be given away, marketed or sold outright with the code and/or art in it, and there's no question of ownership or where the proceeds should go.
jolteon77
June 6th, 2007, 06:01 PM
what i used is a hidden hitTest box (or whatever shapes) inside the character movieclip (in your case; dog) instead of scripting it which is what pingnak telling you to do, so if you put it on the dog you'll do a hit test of if mc_dog.hitBox(hitTest(bone)) then pick it up..... something like that
*Your little angel and little girl are very cute :)*
AAAHHH!!! I remember coming across something like that!! I understand exactly what your saying and right after I read this I JUMPED on flash to try it out...Unfortunately I am still having troubles with it..
Here's is the code
onClipEvent(enterFrame){
if(this.hitTest(_root.puppy)){
this._alpha = 0;
_root.puppy.gotoAndStop(2);
}
}
What I thought I could do is drop a 'bone' MC in the first frame, and then make it hittest to take the puppy into frame 2 of a different mc of him holding the bone. The problem is the bone dissapears just fine, but it doesn't jump him into the next frame.
Before that I went into (guessing what to do for your suggestion, still fuzzy about it) the dog MC with the frames of him running and stuff, and made a new layer and put the bone in there over his mouth so when he touched the bone in the original frame, the same bone I put IN his MC would change his alpha from 0 to 100 and the other bone's alpha would turn to 0. That didn't work either. I thought this was what you meant by a 'hidden hit test box in the MC'
THANKS FOR HELPING! For a while I thought all hope was lost for this thread
jolteon77
June 6th, 2007, 06:19 PM
for your tree with blue bar problems.... since your dog can came in any angle including above the tree (should the player have control over it) i really think you need a big, tree sized blue box with registration point on the TOP of the box's or tree's... then on hit test, change the _y of the dog to the _y of the tree (which is the top of it because we put the registration point on the top) instead of messing with the movement speed of x or y
HEY! After an all-out, knock-down, drag-out fight with action script and just plain ol' experimenting, I MADE IT WORK! Instead of making a hidden hit test box, I just put a whole new duplicate MC of the dog holding the item and turned its alpha to 0 on another layer directly on top of the dog. Both MCs got the same 'control with key board codes' so that they will always be in the same place when moved. I told the action script on the bone to hide the boneless dog MC when the bone was touched, and to bump the item MCs alpha to 100, and IT WORKED! I had also wanted to make him not hold the item forever and to 'drop' it when you pressed a button, AND I FIGURED THAT ONE TOO :)! I just put that 'else if button is pressed' in there and basically told it to reverse the item and itemless MCs alphas. I'm so glad you responded and jump started me to solve this one on my own. Now I have learned a great deal more about action script.
As for the tree and changing scales, I have no idea on how to build that because I dont know how to type that in. Could you please give an example on how to code this? Thanks.
jolteon77
June 6th, 2007, 07:07 PM
Reciprocal Art For Code+Credits and Code For Art+Credits
Now that's an interesting proposal. I do indeed need art.
There probably ought to be a forum here just for that. I've met precious few artists who could code, and precious few programmers who could draw.
'Programmer Art' is synonymous with 'Stick Men'. Give a five year old a box of crayons, and they'll do something approximating what you'll see a typical programmer do. Most programmers don't have the patience to do 'quality art'. It's not their thing.
And the code I've seen come out of artists... the horror... the horror.... Same deal. Most artists don't have the patience to deal with programming. It's not their thing.
It's one of the core weaknesses of independent Flash authoring, IMHO.
I thought there would be a forum for that. Maybe I should post a new thread talking about it and see how people respond. Maybe we could get something going, and they'll put a whole section on the board. I love how simple it would be too(thanks for explaining exchange contract/licenses and work for hire, it made everything clearer). You read me like a book talking about artist and programmers. I just figured out how to make the MC pick up stuff, and now that I think about it, I should have figured that out a LONG time ago. All that simple stuff really held back progress. What will happen when I need REALLY advanced codes in the future? I don't want people to see my game yet (not at least until Nintendo or Sony sees it first, you know?) so I don't want to have to partner up with a programmer. I'll most definitely need some quick codes for myself; there's no way I'm going to ever really learn everything behind those codes from just a forum ...
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.