Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: stoping frame after 3 slides

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default stoping frame after 3 slides

    this code below this line is looping though 3 pictures. so it will display pic 1, 2, 3, 1, 2, 3,... and so on. but i want it do stop when it picture is 3.

    float frame = 0;                
    	double frame_speed = 0.1;   //how fast to loop through pictures
    	int pictures = 0;                  //how many pictures to loop from
     
    public void animation_player()
    		{	
    			int tester = (int)(frame + frame_speed);   
    			if(tester < pictures) 
    			{
    				frame += frame_speed;
    			}
    			else
    			{
    				frame = 0;
    			}
    		}




    public void paint(Graphics g)
    		{
    			Graphics2D g2d = (Graphics2D) g;
     
    							pictures = 3; //6 picture on sheet
    							g2d.drawImage(player_image, x, y, x+width, y+height, 
    									50*(int)frame, 147, 50*(int)frame+50, 189 ,Sprite_Sheet.m1);
    }



    iam thinging in if statment may be add another else if(tester == 3)...


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: stoping frame after 3 slides

    Quote Originally Posted by hwoarang69 View Post
    this code below this line is looping though 3 pictures...
    I don't see a loop any where.

  3. #3
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: stoping frame after 3 slides

    1st block of code is in a main game loop.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: stoping frame after 3 slides

    Can you post the code with the loop?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: stoping frame after 3 slides

    sure,

    main.java

    public void run()
    {
    while(player_class.isDEAD() == false) //if player is not dead keep going
    {
    player_class.PLAYER_MOVE(this, ground_class); //player moves
    }
    }

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: stoping frame after 3 slides

    Looks like the loop will stop when the isDEAD() method returns true. Change the code so it returns true when you want the loop to stop.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Image without a frame, is it possible?
    By knightmetal in forum AWT / Java Swing
    Replies: 5
    Last Post: August 15th, 2012, 03:52 AM
  2. Frame not becoming invisible
    By sbjibo in forum What's Wrong With My Code?
    Replies: 14
    Last Post: June 27th, 2012, 11:58 PM
  3. frame deactivation
    By deependeroracle in forum AWT / Java Swing
    Replies: 5
    Last Post: May 13th, 2012, 07:37 AM
  4. Replies: 1
    Last Post: January 19th, 2012, 03:44 PM
  5. How to display ppt slides through java????
    By jj_crazy_1 in forum Java Theory & Questions
    Replies: 0
    Last Post: April 5th, 2010, 10:52 PM