In need of help. Powerups!

Subscribe to In need of help. Powerups! 12 posts, 4 voices

Sign in to reply


 
avatar for XplittR XplittR 8 posts
Flag Post

Well, I have been following the tutorials, and made it work really good, with a few adjustments. One of them being that at the top I have a bar so that you can at all times see what kinds of powerups you have. For now I have only added two long-lasting powerups, which is shield and “three shots at once”. It works fine, when I pick up a powerupmovieclip, the shield (in this example) gets turned on (blue glow around my ship) and the bar gets activated (simply _root.skjoldgrey.skjoldfarge gets visible to “true”, as in the tutorial. The “skjoldfarge” is a layer inside the movieclip “skjoldgrey”). Well, that works. and the alpha drops down to zero after some time, but the effect (not getting hurt) never stops… So if you pick up an powerup, it lasts forever. I have been struggeling with this for a while, but now I hope that someone of you professionals can help me out. :)

Here is the code for the shield in the “PowerUps”-class:

			if (type == 3)
			{
				_root.ship.shield._visible = true;
				_root.skjoldgrey.skjoldfarge._visible = true;
			}

And here is my code for the shield-deactivation in the “Ships”-class:

			if(_root.skjoldgrey.skjoldfarge._visible == true)
			{
				_root.ship.shield._alpha -= .333;//10 sekund, 100/(sekund*30)
				_root.skjoldgrey.skjoldfarge._alpha -= .333;//10 sekund, 100/(sekund*30)
				if(_root.skjoldgrey.skjoldfarge._alpha < 0)
				{
					_root.ship.shield._visible = false;
					_root.ship.shield._alpha = 100;
					_root.skjoldgrey.skjoldfarge._visible = false;
					_root.skjoldgrey.skjoldfarge._alpha = 100;
				}
			}

If you can help me out, or atleast try, I would greatly appreciate that! :)

-Sincerely, XplittR

 
avatar for Cervello Cervello 76 posts
Flag Post

How do you activate the shield?
If I recall correctly the Shootorials use a pointer to the Shield movieclip and check to see if it’s non-null, so the activation should involve setting a variable in Ship equal to an instance of the Shield movieclip.

If so, simply set that same variable to “null” (without quotes, it’ll appear blue) in the deactivation code.

Oh, and I suggest using more logical names than skjoldgrey.skjoldfarge (like powerupDisplay.shieldIcon), it’ll help prevent typos and such, and helps people read your code when they want to help you. Also, capitalization like skjOldGrey or underscores like skj_old_grey will make it more readable.

 
avatar for Draco18s Draco18s 2331 posts
Flag Post

Cervello: Are you talking about the AS2 or the AS3 version? In the AS2 version it doesn’t check for null because the movie clip always exists.

XplitteR: Are you sure it lasts forever, and not just a mite longer than it’s cleanly visible? An alpha of less than 5% is very hard to see. In any case, I’d revert to the Shootorial code (if shield._visible == true, then blah blah) and just set your movieclip’s alpha and visibility along with it, rather than relying on it.

Also: if you wanted to better indicate that the powerup was still active, I wouldn’t use alpha gradiations, I’d use a bar, like the health bar: even the last moment the shield still works you can tell without squinting.

 
avatar for XplittR XplittR 8 posts
Flag Post

Cervello, I think that you are talking about AS3, as I cannot remember anythying about set the variable to null, just as Draco18s said. And about the names, they make sense to me, as I am Norwegian(skjold = shield), and I have checked several times for typos. But Draco, I do have the same code as the shootorial, exept I use if(_root.skjoldgrey.skjoldfarge._visible == true)
instead of if(_root.ship.shield._visible == true)

Well, that is how I have chosen to do it though, and as far as I can see, it should be working. Also, yeah, 30 seconds after activating the shield, I still take no damage (But I do before activating it). Also, after I have activated the shield, and I pick up another shield, then the new shield does not glow Blue, but the effect is still there (from the last shield probably).

Help!

 
avatar for Cervello Cervello 76 posts
Flag Post

I see, forgive me for my language-ignorance :< (I should have figured that out with the //10 sekund, 100/(sekund*30))

That said, your problem with the shield image not reappearing after obtaining it a second time may be because you set the alpha to 100 while it’s not visible. I suggest moving the _alpha=100; parts to the activation code, on the line after setting _visible=true;, because visibility can interfere with changing alpha and tint and other such things.


Well, after you change the above, I suggest trying:
Adding a trace statement inside the if(_root.skjoldgrey.skjoldfarge._alpha < 0) conditional to see if it ever triggers. (like trace("setting invisible again");)

If the trace doesn’t trigger I’d suggest trying stuff like changing if(_root.skjoldgrey.skjoldfarge._alpha < 0) to if(_root.skjoldgrey.skjoldfarge._alpha < 1) or if(_root.skjoldgrey.skjoldfarge._alpha < 5), or using -=.5, just to see if Flash is stopping you from having negative _alpha.

If the trace triggers but the shield still works past 10 seconds, I’m clueless for now. Try if(_root.ship.shield._visible) instead of if(_root.skjoldgrey.skjoldfarge._visible == true) just in case, and check your other code to see if something else may be affecting the _alpha or _visible of those objects.


Another pointless note, when you use if() to test Boolean (true/false) variables like _visible you don’t need the ==true, you can just use if(_root.skjoldgrey.skjoldfarge._visible) for ==true, or if(!_root.skjoldgrey.skjoldfarge._visible) for ==false.

 
avatar for mrcheeseytw mrcheeseytw 8 posts
Flag Post

ok this has nothing to do with this topic but i really need help before i end up giving up becuase ive been spending the whole blooming day looking for the answer!!!!!

ive been following the tutorials but i cnt do it!

here is wat it says when i try to test it but i (am a noob) cant find out wats wrong :S

“The class or interface ‘ship’ could not be loaded”

can someone explain wat i did wrong?

 
avatar for Cervello Cervello 76 posts
Flag Post

ok this has nothing to do with this topic

Then make your own topic.
Compiler errors like that tell you the line that’s wrong, so look there. If you still can’t figure it out, post that code in a new topic if you can’t figure it out.
You probably put your files in the wrong place, didn’t import properly or typed “ship” instead of “Ship”.

 
avatar for mrcheeseytw mrcheeseytw 8 posts
Flag Post

dam they are all capital S’s
and i made the picture i did import it?

 
avatar for mrcheeseytw mrcheeseytw 8 posts
Flag Post

hmm

 
avatar for Draco18s Draco18s 2331 posts
Flag Post

if(root.skjoldgrey.skjoldfarge.alpha < 1)

I bet that would do it. Now that I think about it he’s setting alpha changes at 0.333, which would leave a positive value less than 0.333 but greater than 0 and I believe flash will ignore any commands that drop alpha below 0. Try subtracting (1/3) instead.

 
avatar for XplittR XplittR 8 posts
Flag Post

Thanks people!

The error was:
The alpha dropped down to 0.001, and then tried to drop further down, but as alpha cannot go into an negative value, It wouldnt get reduced any further, and therefor never get below 0 (in if(root.skjoldgrey.skjoldfarge._alpha < 0).

So I changed to reduce by (1/3), but neither did that work (as then it would drop down to 0.000(unlimited 0’s)1, which is still above 0).

So solution:

if(root.skjoldgrey.skjoldfarge.alpha < 1)
or something like < 0.002

Thanks people! :D You really helped me out! :D

 
avatar for Draco18s Draco18s 2331 posts
Flag Post

Nod

I didn’t quite expect (1/3) to work, as it’s an “irrational” value, as far as binary is concerned (double of 0.0101010101… or something like that), but I’m glad you got it working.

Sign in to reply


Click Here