XNA Creators Club Online
Page 1 of 1 (12 items)
Sort Posts: Previous Next

blinking code not working...

Last post 6/30/2009 6:11 AM by MajorSc. 11 replies.
  • 6/27/2009 4:31 AM

    blinking code not working...

    hi. I've been trying to write a piece of code that allows the character to activate a blinking animation when idle, but i can't get it too work. can i get some help please. (=

     

     

      //blink  
            private bool isblinking;  
            private float blinktime;  
        
              
               private void Doblink()  
            { if (IsAlive && IsOnGround)  
                {  
                      
               
     
                           if (blinktime > 30.0f)  
                           {   
                           isblinking = true;  
                           }  
                           else 
                           {  
                               isblinking = false;  
                           }  
                              if (isblinking)   
                {  
                                   sprite.PlayAnimation(bilnkAnimation);  
                                   blinktime = 0.0f;  
                               }  
                            
                           else 
                           {blinktime += 1.0f;  
     
                           }  
                       }  

     

     

  • 6/27/2009 4:59 AM In reply to

    Re: blinking code not working...

    Now, after reading your post and Im going to assume that you want the character to blink when they come back from a death to symbolize invincibility or something. Here is what I would suggest doing

    private bool isblinking= false
    private float blinktime= 0.0f; 
     
    private void doBlink() 
    {    
         //only blink if the character is on the ground and is alive 
         if (IsAlive && IsOnGround) 
         { 
              if (blinktime < 30.0f) 
              { 
                 isblinking = true
                 blinktime += 1; 
              } 
              else 
              { 
                 isblinking = false
              } 
              
              if (isblinking == true
              { 
                 sprite.PlayAnimation(blinkAnimation); 
              } 
         } 



    Basically, by doing this you should only have to set blinktime to 0 and for 30 count they will blink. The way your code reads is as such that if they start to blink then they will blink maybe once then stop because your not giving the animation player time to animate the blink. With the code I have above you would only have to set blinktime = 0.0f to get the player to blink.

    I hope this helps, let me know if it works :D
  • 6/27/2009 5:05 AM In reply to

    Re: blinking code not working...

    actually, I think the original poster meant that the character is in its "idle" animation and the eyes are blinking, just as a cartoon character would do

    the response about the "invincibility" is referring to "flashing" of a character who just comes back from the dead, and is usually flashing to indicate temporary invincibility, which also allows the person to get in position without being killed immediately after coming right back.

    anyway... the "idle" animation is demonstrated in the "Platformer Starter Kit" that comes for free with the XNA GS.

    Well, the "idle" position is only 1x1 single-frame sprite sheet, so it does not really animate, but the game code has plenty of other animations for run, jump, die, etc. so you'll get the idea.

    Just replace the 1x1 sheet with a 1x4 sheet that contains a few more frames to show the blinking.

    Hope that helps.
  • 6/27/2009 5:07 AM In reply to

    Re: blinking code not working...

    p.s. also, you misspelled "bilnkAnimation" in your code above.. make sure that your animation object has a spelling that matches... :)
  • 6/27/2009 5:08 AM In reply to

    Re: blinking code not working...

    Good point, I actually misread that. Sorry original poster, I am sadly a bit tired XD After I get some sleep and Ill come back and try again :D
  • 6/27/2009 8:43 AM In reply to

    Re: blinking code not working...

    yeah its an idle character blinking animation. why i wanted to code it as opposed to stretching out an animation is because, for one i could let the time in between blinks range longer as opposed to a short range repeptitive cycle. even though im still aware thats what it  is. plus i wanted to do other  idle animations.  i tried that code, and still nothing. thanks for your time though, but yeah can anyone help please?
  • 6/27/2009 2:32 PM In reply to

    Re: blinking code not working...

    I think we're going to have to see more code and a better description then "it doesn't work". What does it do? Have you stepped through the code in the debugger to see what happens? Have you placed breakpoints to see if the blinking variable is being set to try and false correctly? Does your sprint.BlinkAnimation line ever get hit? What's calling the DoBlink method? Does DoBlink get called?

  • 6/28/2009 3:56 AM In reply to

    Re: blinking code not working...

    lol. I'm a beginner i don't know everything just yet, thats why I'm asking for help.  I don't know how to do them. no Doblink doesn't get called, how do i call it and where?. I thought the code would perform the method automatically.
  • 6/28/2009 5:42 AM In reply to

    Re: blinking code not working...

    Nope, doesn't get automatically called. Sounds like you're pretty new to programming and to C#. I'm going to recommend you check out the "Help! I'm new!" FAQ we wrote up for beginners. It's filled with great advice for people starting out and gets you pointed in the right direction.

    Trying to learn to make games using the XNA framework before you understand the basics of OO programming and the C# syntax are just going to give you headache and frustration at every turn. I would definitely take some time to focus on learning C# and programming basics first before introducing game development and the XNA framework. By doing that you'll find that learning to make games will move a lot quicker when your understanding of programming (and debugging!) techniques is more solid.

    Hope that advice doesn't discourage you. It's really meant to encourage you and help you succeed.
  • 6/28/2009 9:25 AM In reply to

    Re: blinking code not working...

    i am using the frame work. i want to add on to it. and this is how im learning to use everything, i'm not completely new to code, i get how most stuff works, just like all new stuff there's a learning curve. i just want a bit of help so i can further understand then apply it and so forth.. (=


    i got it to work but i cant get it to stop after the animation plays....

     private bool isblinking = false;  
            private float blinktime = 0.0f;  
     
            private void doBlink()  
            {  
                //only blink if the character is on the ground and is alive    
                if (IsAlive && IsOnGround)  
                {  
                    if (blinktime < 30.0f)  
                    {  
                          
                        blinktime += 1;  
                    }  
                    else 
                    {  
                        isblinking = true;  
                    }  
     
                    
                    if (isblinking)  
                    {  
                        sprite.PlayAnimation(blinkAnimation);  
                         
                        if (blinktime > 50.0f)  
                    {  
                        isblinking = false;  
                        blinktime = 0;  
     
                    }     
                      
                    }  
                    else 
                    {  
                        sprite.PlayAnimation(idleAnimation);  
                          
                    }  
     
                      
                }  
            }   
  • 6/28/2009 3:02 PM In reply to

    Re: blinking code not working...

    And I stand by my "take a couple of weeks, maybe a month to focus learning only C# and how OO works" stance. :)  Not knowing that a method doesn't just get automatically called when you write it is a HUGE obstacle to overcome. Honestly if you really focus on it (and it seems like you've been focusing great so far on writing your game!) it should only take you a couple of weeks of intense study to get the basics down so you'll be able to end up answering most of your own questions.

    You see, you're not even asking game development or framework questions. You're asking logic and debugging questions. You're not sure how to correctly write the logic because you're still new to OO and C# and you're not sure how to figure out what's going on because you're new to debugging with C#. Spend some time learning those things and you're going to be MUCH further ahead and work much faster than you are right now.

    You're overloading yourself trying to learn it all at once and you'll end up getting frustrated and giving up. I know this isn't the advice you want to hear but it's the advice I give to all new guys. The ones that listen end up sticking around and becoming members of the community (and eventually answering questions for others). The ones that don't listen keep getting stuck on their game at every turn and after a few more posts like yours disappear off onto some other thing that doesn't make them pull their hair out (and blame these forums and the XNA framework rather than themselves...).

    So since I'd LOVE for you to become a functioning, active member of this community, I'm begging and pleading with you to take the right steps. Put your game idea on a shelf for a bit and give yourself a fighting chance at actually becoming a game developer by learning the language you need ot use first.
  • 6/30/2009 6:11 AM In reply to

    Re: blinking code not working...

    George Clingerman:
    And I stand by my "take a couple of weeks, maybe a month to focus learning only C# and how OO works" stance. :) 
    ...

    So since I'd LOVE for you to become a functioning, active member of this community, I'm begging and pleading with you to take the right steps. Put your game idea on a shelf for a bit and give yourself a fighting chance at actually becoming a game developer by learning the language you need ot use first.


    +10

    I agree completely.

    Please take a few weeks to read a "Beginning C#" book and while you're at it, a "Beginning XNA" tutorial or book as well.

    Definitely come back here and feel free to ask questions about game programming once you're up to speed on the language.

    Best of luck! :-)
Page 1 of 1 (12 items) Previous Next