Flash

C++, C#, Java, PHP, ect...
User avatar
Agent
Posts: 164
Joined: Tue Jul 14, 2009 5:22 am

Re: Flash

Post by Agent »

Wow okay this whole topic changed drastically from when I last looked lol.
Okay first - for the HUD yes, simply separate it in a different layer (and perhaps contain all of the elements within one single movie clip with its own layer construction and action script within.)

If you are still interested have a play around with this code to make a health bar system here is a quick layout of how it works (i will make a full tutorial later):

Place this code on the first root frame of the scene-

Code: Select all

stop(); // So that the frame does not skip/loop/or go to another frame (we want to stay on our first frame)
health = 100; // Variable defining the original amount of health
mana = 100;
onEnterFrame = function(){ //basically creating a looping check for the inside properties we set
	if(mana <= 0){ //defining laws for mana (to not allow it to pass below 0 in value)
		mana = 0;
	}
	else if(health >= 100){ // same thing as above but just not allowing health to rise above a 100
	health = 100;
	}
// The following is to a dynamic text box "health_txt" (or mana_txt) which displays the amount of health/mana the player has left. We round it and add % sign to make a percentage
	_root.health_txt = Math.round(health)+"%";
	_root.mana_txt = Math.round(mana)+"%";
//The following simply defines that if health == 0 (or you could use <= 0 if your damage varies greatly) then the loop ends and the movie goes to the next "dead" frame
	if (health == 0){
		delete onEnterFrame;
		play();
	}
}
The other critical part of all this is the actual health "bar" - the following code is located inside a separate movie clip for both health and mana which both have yet another "bar" movie clip to handle. The health "bar" inside has an instance name of 'health_bar' and 'mana_bar' for the other. These bars should have their registration points located on their absolute LEFT side in the center of the rectangle (so think the registration point to be halfway down the box in height but absolute left on the horizontal) - the box itself can be of any color size / etc but should be a regular rectangle for best effect.

Code: Select all

onEnterFrame = function(){ //again we start out with this as before
	health_bar._xscale = _root.health; // the actual movie clip for the bar you make which scales the clip horizontally in proportion to the health variable (defined with a _root.health since we have to connect to a variable outside the local movieclip).
		if(health_bar._xscale >= 100){ // we are just defining constraints so the bar does not get longer than 100% of is possible size
		health_bar._xscale = 100;
	}
}
onEnterFrame(); // once it has all been filtered we do this to update the variable info / and bar sizes 
Okay that is probably so very messy - but see how you go with it until i explain it better.

Back to your question regarding integrating with halls tutorial. Okay I have not personally gone through his tutorial series so I dont know how it works yet (this is on my agenda) - however integrating flash with it I think is difficult for still a beginner with it. - it can be done and I figure I know how to and will eventually slap a tutorial out about it. But basically -

Since I am not sure how the php/html side of this handle the variables of players etc.

Inside the flash you have to call upon the php variables / etc and handle them in there by when you select a race it sets those variables -

SO first introduce your php variables from your local php file-

Code: Select all

onEnterFrame = function() { //again we want this to happen again and again - since this is online and we want these variables to update in and out
// Assign the directory and rest according to your own set up
  loadVariables("directory/folder/filename.php", this, "GET");
}
onEnterFrame();

Then handle those introduced php variables with buttons and the such -

Code: Select all

on(release){
playerRace = $race1
}
that defines a flash variable "playerRace" to your php variable $race1 and then you can handle it further in the main update loop to tell the php file what has been selected (or even create a submit button which then submits the variable - and THEN goes on past the embedded flash file into a new page that you define ( getURL("/startgame.html") )

Not sure if this helps you much - it is extremely difficult to encapsulate it ALL like this for personal use. You really have to get used to flash before you can do this the way you probably want. But nonetheless give it a shot ... ah and i also found this - http://www.kirupa.com/developer/actions ... mysql2.htm it may help you with the flash/php business.
User avatar
Agent
Posts: 164
Joined: Tue Jul 14, 2009 5:22 am

Re: Flash

Post by Agent »

SpiritWebb wrote:Is there a way when importing into flash, to make the background transparent? I have it as a .png file. I imported a ship to use as a sprite, and can't figure out how to get rid of the background, leaving just the ship.
Easy way to do it -

Select the image on the stage: Go to Modify > Bitmap > Trace Bitmap - fiddle with the parameters to get the level of detail you want left in it ... then simply select the unwanted parts of the image such as white BG with your mouse and hit delete to get rid of them :D easy.
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Flash

Post by SpiritWebb »

neronix17 wrote:when its on the stage or when you are editing it on the stage, right click on it and there should be break apart, or something like that, then it turns into the same as the fill on a box or circle, then you can cut around the bit you want and press F8 to convert to symbol while its selected. Probably an easier way but thats the way I usually do it.
Got it too work, thanks!! I will also try Agents version as well, come later...
Image

Image
User avatar
neronix17
Posts: 317
Joined: Sat Aug 01, 2009 5:01 am

Re: Flash

Post by neronix17 »

Agent wrote:
SpiritWebb wrote:Is there a way when importing into flash, to make the background transparent? I have it as a .png file. I imported a ship to use as a sprite, and can't figure out how to get rid of the background, leaving just the ship.
Easy way to do it -

Select the image on the stage: Go to Modify > Bitmap > Trace Bitmap - fiddle with the parameters to get the level of detail you want left in it ... then simply select the unwanted parts of the image such as white BG with your mouse and hit delete to get rid of them :D easy.
yaay I was right, there is an easier way to do it :lol: I forgot you could do that :?
This isnt just a gimp mask...This is an S&M gimp mask...
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Flash

Post by SpiritWebb »

Thanks agent, will look into this a little later...as of course still not learning, but when I get to that point to add, as EVERYTHING right now is testing and playing/learning, I will add and see what happens!
Image

Image
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Flash

Post by SpiritWebb »

Im having a little problem with my ship movement. I got it to go right, left, up and down, but cannot seem to get it to go ne, sw, nw and se.

If this is my code:

Code: Select all

onClipEvent (load) {
 speed = 6;
}
onClipEvent (enterFrame) {
 if (Key.isDown(Key.RIGHT)) {
  this.gotoAndStop(2);
  this._x += speed;
 } else if (Key.isDown(Key.LEFT)) {
  this.gotoAndStop(4);
  this._x -= speed;
 }
 if (Key.isDown(Key.UP)) {
  this.gotoAndStop(1);
  this._y -= speed;
 }
 if (Key.isDown(Key.DOWN)) {
  this.gotoAndStop(3);
  this._y += speed;
 }
}
for example Key.isDown(Key.Down) makes it move south, then how would i set the "Key.Down" variable to make it say go se or sw? Same with Ne & Nw.
Image

Image
User avatar
neronix17
Posts: 317
Joined: Sat Aug 01, 2009 5:01 am

Re: Flash

Post by neronix17 »

http://thetimewarp.bounceme.net/flash/games/prometheus/

Try the flight test there, I can give you a copy of the code if you like the motion there, allows travel in every direction
This isnt just a gimp mask...This is an S&M gimp mask...
User avatar
Agent
Posts: 164
Joined: Tue Jul 14, 2009 5:22 am

Re: Flash

Post by Agent »

No worries. as for 8 way directional movement you have to assign 2 keys to be pressed same time for the movement (done with the && )

here is the code from my RPG Engine -

Code: Select all

onClipEvent(load){
speed= 5;
}
onClipEvent(enterFrame){
if(Key.isDown(Key.LEFT)&&Key.isDown(Key.UP)){
this._x-=speed;
this._y-=speed;
this._rotation=315;
}
else if(Key.isDown(Key.LEFT)&&Key.isDown(Key.DOWN)){
this._x-=speed;
this._y+=speed;
this._rotation=225;
}
else if(Key.isDown(Key.RIGHT)&&Key.isDown(Key.UP)){
this._x+=speed;
this._y-=speed;
this._rotation=45;
}
else if(Key.isDown(Key.RIGHT)&&Key.isDown(Key.DOWN)){
this._x+=speed;
this._y+=speed;
this._rotation=135;
}
else if(Key.isDown(Key.LEFT)){
this._x-=speed;
this._rotation=270;
}
else if(Key.isDown(Key.RIGHT)){
this._x+=speed;
this._rotation=90;
}
else if(Key.isDown(Key.UP)){
this._y-=speed;
this._rotation=0;
}
else if(Key.isDown(Key.DOWN)){
this._y+=speed;
this._rotation=180;
}
You will just probably want to change the rotation to how you made yours with the -= since you dont want the ship to just flip around in jerks...
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Flash

Post by SpiritWebb »

neronix17 wrote:http://thetimewarp.bounceme.net/flash/games/prometheus/

Try the flight test there, I can give you a copy of the code if you like the motion there, allows travel in every direction
I absolutely love that ship movement, exactly what I was looking for, even the moving background to travel with it! Thats awesome!
Agent wrote:No worries. as for 8 way directional movement you have to assign 2 keys to be pressed same time for the movement (done with the && )

here is the code from my RPG Engine -

Code: Select all

onClipEvent(load){
speed= 5;
}
onClipEvent(enterFrame){
if(Key.isDown(Key.LEFT)&&Key.isDown(Key.UP)){
this._x-=speed;
this._y-=speed;
this._rotation=315;
}
else if(Key.isDown(Key.LEFT)&&Key.isDown(Key.DOWN)){
this._x-=speed;
this._y+=speed;
this._rotation=225;
}
else if(Key.isDown(Key.RIGHT)&&Key.isDown(Key.UP)){
this._x+=speed;
this._y-=speed;
this._rotation=45;
}
else if(Key.isDown(Key.RIGHT)&&Key.isDown(Key.DOWN)){
this._x+=speed;
this._y+=speed;
this._rotation=135;
}
else if(Key.isDown(Key.LEFT)){
this._x-=speed;
this._rotation=270;
}
else if(Key.isDown(Key.RIGHT)){
this._x+=speed;
this._rotation=90;
}
else if(Key.isDown(Key.UP)){
this._y-=speed;
this._rotation=0;
}
else if(Key.isDown(Key.DOWN)){
this._y+=speed;
this._rotation=180;
}
You will just probably want to change the rotation to how you made yours with the -= since you dont want the ship to just flip around in jerks...
Thanks agent...I understand now. I really like the above animation, its exactly what I was looking for
Image

Image
User avatar
neronix17
Posts: 317
Joined: Sat Aug 01, 2009 5:01 am

Re: Flash

Post by neronix17 »

well, i got it from a tutorial nd just made my own graphic for the ship really so you can have the whole file to have a look at, its at

http://thetimewarp.bounceme.net/flash/g ... t_test.fla
you might need to right click and save target as...

keeping in mind that i use cs4 now, i cant remember what i used for that, it was a while ago, if you cant open it then I will make a .txt file with all of the code in it.
This isnt just a gimp mask...This is an S&M gimp mask...
Post Reply

Return to “Coding”