A Help With Transparency/if statements

Non-platform specific questions.

A Help With Transparency/if statements

Postby happyjustbecause » Tue Dec 11, 2012 2:32 am

Hello again everyone. One of the powers used by the player of my game is available to use after a variable reaches a certain number. Once this variable hits 1000 an icon's transparency turns from .9 to 0. I want to make it so that the transparency of the icon goes down while the AvailableHologramTimer varaible goes up. How can I do this? Rather than doing something like this:

Code: Select all
if(AvailableHologramTimer==125)
{
    transp=.8;
}
if(AvailableHologramTimer==250)
{
    transp=.7;
}


Is there some kind of formula that I can have so that the transparency goes down when the variable goes up.
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: A Help With Transparency/if statements

Postby skydereign » Tue Dec 11, 2012 3:06 am

happyjustbecause wrote:Is there some kind of formula that I can have so that the transparency goes down when the variable goes up.

Subtracting the number works just like that.
Code: Select all
transp = (1000.0-AvailableHologramTimer)/1000.0;

Of course you'll need to set the min max to fit your use case.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: A Help With Transparency/if statements

Postby happyjustbecause » Tue Dec 11, 2012 3:21 am

Well I just tried that code and it seems to be working when I added this:

Code: Select all
switch(AvailableHologramTimer)
{
    case 0:
    transp = (1000.0-AvailableHologramTimer)/1000.0;
    break;

    case 1:
    transp=0;
    break;
}


I added the switch just to prevent any problems with the hologram being available and the transparency not being 0. I only noticed this because I have a key down event which makes all the powers available without setting the timer to 1000.
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: A Help With Transparency/if statements

Postby skydereign » Tue Dec 11, 2012 3:25 am

You sure that is what you want? That code is the same thing as doing this.
Code: Select all
switch(AvailableHologramTimer)
{
    case 0:
    transp = 1;
    break;

    case 1:
    transp=0;
    break;
}

Which is the same as just doing this.
Code: Select all
transp = AvailableHologramTimer==0;

Which I'm pretty sure isn't what you wanted.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: A Help With Transparency/if statements

Postby happyjustbecause » Tue Dec 11, 2012 3:29 am

Umm I don't really know what:

Code: Select all
transp = AvailableHologramTimer==0;


means. But it seems the code I just added is working, the hologram's icon goes down in transparency as the power is getting closer for availability.
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: A Help With Transparency/if statements

Postby skydereign » Tue Dec 11, 2012 3:33 am

Ok, then you must be using different code (switched a variable name). Because the code you said you are using is exactly like I mentioned in my last post. The switch statement only triggers code if the variable is 0 or 1. In the case of 0, the variable is 0, so that transp = ... bit is the same thing as saying transp = 1000/1000 which is 1.

happyjustbecause wrote:Umm I don't really know what:

Code: Select all
transp = AvailableHologramTimer==0;


means. But it seems the code I just added is working, the hologram's icon goes down in transparency as the power is getting closer for availability.

This is that boolean math I mentioned to you a while ago. var==0 returns a 1 if the statement is true, and a 0 if it is false. And that happens to be exactly what the code you posted does.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: A Help With Transparency/if statements

Postby happyjustbecause » Tue Dec 11, 2012 8:49 pm

Hmm... Well I thought the code meant that essentially 1 unit of transparency equals 1000 of the AvailableHolgramTimer. I didn't really look at the actual code to think this, just what I saw the game do with it. Here's a video I just made showing the code and the gameplay doing what apparently shouldn't be happening.

For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: A Help With Transparency/if statements

Postby skydereign » Tue Dec 11, 2012 8:59 pm

Yeah, as I thought. The code in game is different than the one you posted. This is what you had.
Code: Select all
switch(AvailableHologramTimer)
{
    case 0:
    transp = (1000.0-AvailableHologramTimer)/1000.0;
    break;

    case 1:
    transp=0;
    break;
}

And this is what you have in game.
Code: Select all
switch(AvailableHologram)
{
    case 0:
    transp = (1000.0-AvailableHologramTimer)/1000.0;
    break;

    case 1:
    transp=0;
    break;
}

They are very different, and that explains why it works properly.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: A Help With Transparency/if statements

Postby happyjustbecause » Tue Dec 11, 2012 9:28 pm

Ohhh... I thought there would be something different, I was paying attention to the transp = (1000.0...)

sorry about that. Thank you for the help again!
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron