-
[CS3] Help With Simple Game ActionScript
Hey,
I'm new to action script and have just started making animations using Flash CS4.
Today I decided I wanted to make a game, The concept of the game is you have to find certain objects in a scene, once you've clicked on all the objects in that scene you move onto the next, a sort of "I SPY" game.
EG: scene 1 one you need to find and click on: A red shoe, A toy car and a blue cap, once you've done that a button appears down the bottom saying continue.
Now I think I known the script for the button, but tell me if I'm wrong:
Code:
on (release) { gotoandstop(FRAME NUMBER); }
But what AS do I put on the objects so that once all have been clicked once, the CONTINUE BUTTON shows up?
Thanks,
-Spree
P.S The action script needs to be AS 2.0
-
OK As 2 my faverate and a nice start to the morning.
you are correct with the button part though you want to make the format easier to read. like so
Code:
on (release){
gotoAndStop (frame);
}
but what you need to do is add an instance name to all the items
I have used the following below
car
cap
shoe
The button is a movieclip instead as this means all the As is on one frame
Code:
stop();
carvar = 0;
capvar = 0;
shoevar = 0;
mybutton._visible = false;
car.onPress = function(){
carvar = 1;
}
cap.onPress = function(){
capvar = 1;
}
shoe.onPress = function(){
shoevar = 1;
}
function mytimer (){
if (carvar == 1 && capvar == 1 && shoevar == 1) {
mybutton._visible = true;
}
}
mybutton.onPress = function (){
gotoAndPlay (framehere)
}
thetimer = setInterval(mytimer, 10);
I have uploaded an example swf and the source fla for you the images are quick and only for examples the button also wont go anywhere as theres no frame number indicated just replace it with what you need.
Example file
http://www.hobo-town.com/Flashkit/ispy.swf
Source
http://www.hobo-town.com/Flashkit/ispy.fla
If your question have all be answer please go to thread tool and mark and resolved, this is so we can get round the questions quicker and more efficiently.
Thank you
Mr Wabbit
Trust my code, and not my english.
-
Additional Element
Thanks, for that, Ill test it in Flash in just a second.
But just before I do there is one other element that would be great.
What script to I need to add so that when an item is clicked a red circle goes around it?
Or a tick comes up next to it.
That way the player knows that they've chosen the right thing
-
You can either use another movieclip which become visible when you click the item or you can add a second frame state and have the item change to frame 2 when clicked.
I will make the change to the example and source with the second frame state as this method is the one which is less likily to confuse you.
Trust my code, and not my english.
-
OK updated file complete I have even commented the entire document for you
everyline of code is explained for you, all the code is on one frame this is to keep things neat and tidy for easy editing for you
I have also added a counter to the side for you so you know how many items have been found.
Just the code
PHP Code:
//Stops the Timeline here stop();
//The varible 0 means its not been found while 1 means its been found 2 mean it counts towards the button carvar = 0; capvar = 0; shoevar = 0;
//Starts number of items found at 0 fnd = 0;
//This is the total number of items to be found total = 3
//starts the items without the ring round them car.gotoAndStop (1); cap.gotoAndStop (1); shoe.gotoAndStop (1);
//Keeps track of the number found shown in button right corner while played var found = fnd + "/" + total;
//Tells the button to start off hiden mybutton._visible = false;
//Top Car, function (button) car.onPress = function(){ //If the item has not been found yet if (carvar == 0){ //Tells flash the car has been found carvar = 1; //Adds one to the number of items found fnd += 1; //2nd frame with the circle state car.gotoAndStop (2); //Adds 1 to the number of items found (secure Check) } }
//Blue cap, function (button) cap.onPress = function(){ //If the item has not been found yet if (capvar == 0){ //Tells flash the blue cap has been found capvar = 1; //Adds one to the number of items found fnd += 1; //2nd frame with the circle state cap.gotoAndStop (2); //Adds 1 to the number of items found (secure Check) } }
//Shoe, Function (button) shoe.onPress = function(){ //If the item has not been found yet if (shoevar == 0){ //Tells flash the blue cap has been found shoevar = 1; //Adds one to the number of items found fnd += 1; //2nd frame with the circle state shoe.gotoAndStop (2); //Adds 1 to the number of items found (secure Check) } }
//Use function Timer this checks to see if all items have been found function mytimer (){ found = fnd + "/" + total; //Check to make sure car, cap and shoe have all been found if (fnd == 3) { //If all were found then the button appears mybutton._visible = true; } }
// The movieclip mybutton when pressed use the function mybutton.onPress = function (){ //go to and play the frame in the brakets gotoAndPlay (framehere) }
//Tells the function mytimer to recheck 100 times per second thetimer = setInterval(mytimer, 10);
The Example File
http://www.hobo-town.com/Flashkit/ispy2.swf
The Source File
http://www.hobo-town.com/Flashkit/ispy2.fla
If your question have all be answer please go to thread tool and mark and resolved, this is so we can get round the questions quicker and more efficiently.
Thank you
Mr Wabbit
programmer for www.hobo-town.com
Last edited by Mr Wabbit; 01-09-2009 at 08:45 AM.
Trust my code, and not my english.
-
Thank you very much
Seeing as you've helped me so much, I was wondering if you'd like to be credited in the resulting game.
It will posted on so if your a member I can Co-Author you or if not I can just credit you in the comments section, and in the credits for the game.
Thanks for all you help.
-Caleb
P.S you posted the .swf twice and left out the .fla, but don't worry , ill copy the script off of the thread
P.P.S If you are a member of newgrounds, you can PM me here:
Code:
http://45percent.newgrounds.com/
-
Thank you,
I have updated the post above to have the correct source url it was online just forgot to change the .swf in the link to .fla
I am a member on NG, under the name hobo-town
I will send you a mail and thank you very much
We currently dont have anything on NG yet though I started working on our first game on monday I dont have a lot of spare time, but I make sure I get it done and I can easily start work 6pm after work and keep going till 2 in the morning, get it done and currently has over 800 lines of code over 2 frames. The I have a version online which is a little behind where I am but shows of some the content.
http://www.hobo-town.com/Flashkit/Quest_Script_16.swf
Take a look and see what you think I do about 4-5 versions a day, none of the images are the final images bear that in mind all are placehold made quickly like the file I did for you.
I appicent the offer to co-author me in on NG, and would like that.
If you have anything else feel free to post or email me at ben [at] hobo-town.com
Make sure you send me a copy before you upload and I will bug check and tell you anything I think needs improving and can then show you how.
Thanks
Ben
Trust my code, and not my english.
-
Preloader help
I made a pre-loader that loads and then once loaded plays the game by following a tutorial.
Here's the script:
Code:
stop();
loadingBar._xscale = 1;
var loadingCall:Number = setInterval(preloadSite, 50);
function preloadSite():Void {
var siteLoaded:Number = _root.getBytesLoaded();
var siteTotal:Number = _root.getBytesTotal();
var percentage:Number = Math.round(siteLoaded/siteTotal*100);
loadingBar._xscale = percentage;
percentClip.percentDisplay.text = percentage + "%";
percentClip._x = loadingBar._x + loadingBar._width;
bytesDisplay.text = "loaded " + siteLoaded + " of " + siteTotal + " bytes";
if (siteLoaded >= siteTotal) {
clearInterval(loadingCall);
gotoAndStop(3);
}
}
What needs to be edited in the script so that once loaded it will display a play button with the instance name: GO
Also in some scenes I need more than three objects how do I edit the script you gave me before so that multiple objects can be added or removed.
EG: one scene you need to find 3 objects in another 5 and in another only 2.
Please Help,
-Caleb
-
Disreard part of the last request
Don't worry about the adding and removal of the objects in a scene, I figured out the code my self :P
I still need help with the preloader play button though.
And also how do you link to a URL with AS 2.0?
-Caleb
Last edited by ++SPREE++; 01-10-2009 at 02:21 AM.
-
OK lets start with the preloader the type of preloader you are currently using is a simple bar loader not the most interesting type of preloader my favorite type of preloader is a 100 frame preloader this is because it offers you the chance to make the most interesting preloader you can.
To create a 100 frame loader create a movie clip on the first frame of you time line it does not matter what you call it though I would advice something simple to remember like preloaderMC.
On this movieclip you want the following code
Code:
//runs the function on loading
onClipEvent (load) {
//Gets the total size of the swf
total = _root.getBytesTotal();
//runs MC functions
} onClipEvent (enterFrame) {
//Get the bytes Loaded
loaded = _root.getBytesLoaded();
//Calculate the percentage by the amount loaded over total times 100
percent = int(loaded/total*100);
//You don't need the next line of code by if you want to have the percentage loaded keep it, the text box with var percen101 spans all 100 frames
percen101 = ""+percent+"%";
//goes to the frame on the MC equal to the percentage loaded hence 100 frames you need on the MC
gotoAndStop(percent);
//If the swf has fully loaded do the function below
if (loaded == total) {
//If you want the movie to automatically play switch stop to play
_root.stop();
}
}
on frame 100 you will have your button
I have uploaded the source and a preview as per normal for you.
Preview
http://www.hobo-town.com/Flashkit/100frame.swf
Source
http://www.hobo-town.com/Flashkit/100frame.fla
Glad you figured out how to change the number of object I tried to make things so you could change them easily.
As for the URL
Code:
mybutton.onPress = function (){
//get the URL you can type a url or use the folders and go /myfolder ect to drop level
// the _parent can be change depends how you want to open it. list under code on what you can have and what they do.
getURL ("www.hobo-town.com", _parent);
}
Using target="_top"
target="_top" within a link tag causes the new page to load in the full body of the window, which is useful if you ever want to break out of the frameset you have created and have a frameless page.
_blank loads in a new window
_self loads in the same window
There are more though there the main ones people use. Just search Flash URL buttons or something if you need more
Trust my code, and not my english.
-
Menu game error
Once you've played the menu game the action script stays there and so the game remains on the screen.
Is there a piece code that I can use so that when I press the exit button i made it just cancels all the menu games action script?
BTW the exit button just has the script on it:
Code:
on (release) {
GotoAndStop(26);
}
Thanks
-Caleb
-
Can you send me the file and I will sort it out, just im also interested to see where it is and would like to do some AS cleanup for you, as you want to avoid buttons class items if you noticed all the stuff I gave you had no buttons at all, but were movieclips imitating buttons. The reasoning for this is all the AS stays on a few frames and thats it, for instance my game codenamed Quest has over 1100 lines of code in it of which 1 frame is the preloader (20 lines)
Section (150 Lines) Main (1000 Lines) There is no buttons,
Also I can do some bug testing as its likely theres a few then I can fix them up for you.
My email ben [at] hobo-town.com
Trust my code, and not my english.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|