EragonZZZZ
Member
|
quote:
ORIGINAL: ion24 Mind adding me too? And althorne Check Your tut i asked you a Question. @Eragon: Ok, If you look at the Game i linked back on Page 9, you can see what i want to do, But first i want to know How do i Make an HP-MP Kind of Battle Bar? It's not a turn-Based Game, But like the one i linked. Uh, you can do sir Schmoopy's method if you absolutely want to. But I suggest this: Create two MCs, both rectangles. Call one 'healthbar' and one 'healthcontainer'. Decorate them if you want, then move them around so healthbar completely covers healthcontainer. then... Declare a variable 'HP' that is a number representing the player health var HP:Number = 100; and a variable called maxHP var maxHP:Number = 100; Note that the value of maxHP can be anything, as can the value of HP, but it would look nicer if the value of HP and maxHP were the same. Then do some simple mathematics:
_root.healthbar._width = 200 * (HP/maxHP); 200 should be the maximum width of the healthbar. What this code does is get the fraction of your HP remaining out of the total and sets the bar to the same fraction of the total bar width. Rather flexible code; all the numbers can be easily changed to experiment with things. so now we have (put this on the first frame of your game): 1: var HP:Number = 100;
2: var maxHP:Number = 100;
3:
4: function onEnterFrame()
5: {
6: //your code for the game here
7:
8: _root.healthbar._width = 200 * (HP/maxHP);
9:
10: //more game code here
11:} To analyze the technical aspects of this code (syntax and whatnot): Lines 1-2: These declare a variable, an allotment in memory that stores a specified value. 'var' is the declaration keyword, 'HP' is the name of the variable, and 'Number' is the type. The '=' operator sets it equal to that value. Lines 4-5: Starts a function called onEnterFrame() that runs every time that frame is entered. Similar to the 'main' method in Java. Line 6+10: Comments Line 8: '_root.healthbar' tells the Flash Player to look at the movieclip on the _root named 'healthbar'. As you can guess, '_width' accesses the movieclip's width property, in pixels. Note that brackets denote all the code that applies to the function. They are required.
|