-
[help] health system jump to frame
Hi, I'm working on a game that has a health bar with different "art" on each frame. I can't use the "_xscale" for this one because it's art and it will distort it. I need the MC to watch the score and jump to a frame. I thought I had it looking right, but it's not reacting to the score.
My score field is called "opponentScore"
at one point I had an MC with this code on it:
Code:
if(_root.opponentScore == 90){
_root.opponentHealth.gotoAndStop("90");
}
also 80 to "80, 70 to "70" etc.
Then the "opponentHealth" MC is on a stop and has 10 frames, each labeled with "100", "90", "80", etc.
I tried adding the "watcher" code to one frame in the main animation on the way to get to the next stop frame, but it didn't work.
Thanks for thinking about this one. I'm sure it's a simple solution, and the game works without it, I just thought it would be cool to have the art be different at every score...sort of like a scaling bar, but not quite.
jorge
-
Script kiddie
_root.opponentHealth.gotoAndStop(String(_root.oppo nentScore));
(Remove the space in the middle of the code; FK added it for some reason)
I think that oughta do it?
-
OK, well, I added it like this:
Code:
if(_root.opponentScore == 100){
_root.opponentHealth.gotoAndStop(String(_root.opponentScore));
}
if(_root.opponentScore == 90){
_root.opponentHealth.gotoAndStop(String(_root.opponentScore));
}
if(_root.opponentScore == 80){
_root.opponentHealth.gotoAndStop(String(_root.opponentScore));
}
if(_root.opponentScore == 70){
_root.opponentHealth.gotoAndStop(String(_root.opponentScore));
}
if(_root.opponentScore == 60){
_root.opponentHealth.gotoAndStop(String(_root.opponentScore));
}
if(_root.opponentScore == 50){
_root.opponentHealth.gotoAndStop(String(_root.opponentScore));
}
if(_root.opponentScore == 40){
_root.opponentHealth.gotoAndStop(String(_root.opponentScore));
}
if(_root.opponentScore == 30){
_root.opponentHealth.gotoAndStop(String(_root.opponentScore));
}
if(_root.opponentScore == 20){
_root.opponentHealth.gotoAndStop(String(_root.opponentScore));
}
if(_root.opponentScore == 10){
_root.opponentHealth.gotoAndStop(String(_root.opponentScore));
}
if(_root.opponentScore <= 0) {
_root.gotoAndStop("win");
}
but it's not working. Can you explain to me what the (String(_root)); does? Will it actually know to go to the right frame label?
thanks for your time...
jorge
-
The "gotoAndStop("win"); is working, so I know the code is being seen.
Hmm.
-
Pumpkin Carving 2008
I think this was what V was getting at:
PHP Code:
if (_root.opponentScore != 0) { frameNum = int(_root.opponentScore/10); _root.opponentHealth.gotoAndStop(frameNum); } else { _root.opponentHealth.gotoAndStop("win"); }
This takes the score, say, 80, converts it to 8, and sends the health bar clip to frame 8. the int() is used to get a whole number (since something like 8.5 isn't a frame ). This is all run if the score isn't 0. If it is, it sends it to the win frame. This means you don't have to label your frames, just put them in order (where a score of 10 is frame 1, 20 is frame 2, etc).
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
Script kiddie
You don't need any ifs... just one line will do.
_root.opponentHealth.gotoAndStop(String(_root.oppo nentScore));
String() converts a variable to the type String. So 123 becomes "123".
Could it be that you're not running the script continuously (ie, in an enterFrame event)? Have you actually initialized the variable opponentScore?
-
Imprisoned pride, thanks. I'll give that a shot too.
Vengeance, talk to me more about "not running the script continuously". Right now I've got it on one frame that it hits as the play head passes...just on one frame. Should I put it on an MC that's playing the whole time? I'll try that next.
-
OK, well, I put this code:
Code:
_root.opponentHealth.gotoAndStop(String(_root.opponentScore));
if(_root.opponentScore <= 0) {
_root.gotoAndStop("win");
}
on the main timeline, and what happens now is that instead of stopping on the right frame (with it's label) it goes all the way to the last frame of the MC.
So, like the score is 80, and the bar instead of going to the "80" position, it goes to the "10" position. I'm going to try a gotoAndPlay (instead of a gotoAndStop) and put a stop on the frame inside the MC.
jorge
thanks again for all your help. It's getting there...it's actually moving...that's one step closer.
-
How confusing. With the gotoAndPlay, it does a little split second view of frame "10" and then goes back to it's original stop at 100 percent.
jorge
-
OK, I'm wondering if using numbers as frame labels is the problem here.
So, I used Imprisoned code, and it works:
Code:
onClipEvent (enterFrame) {
if (_root.opponentScore != 0) {
frameNum = int(_root.opponentScore/10);
_root.opponentHealth.gotoAndStop(frameNum);
} else {
_root.gotoAndStop("win");
}
}
Except for one thing, this code above means that the score has to equal "0" for the play head to goto "win".
How do make it if the score is "<=0" (less than or equal to zero)
I'll be testing.
thanks again for the help.
jorge
-
Pumpkin Carving 2008
ummm.... you could try
Code:
...
if (_root.opponentScore <= 0) {
...
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
You guys rock. Just wanted to thank you and sho you what Iwas working on:
http://board.flashkit.com/board/show...37#post3988637
Thanks so much for all your help.
jorge
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
|