This site requires JavaScript, please enable it in your browser!
Greenfoot back
craeXD
craeXD wrote ...

2015/4/14

Animation frames

craeXD craeXD

2015/4/14

#
Hi, i´m new at this forum. I´m a german student at a school...i think the British equivalent are the A-Levels. Well, i got a little bit knowledge about Java (with Greefoot) in the subject "Technology/IT" and now everyone should make a little game-project. And obviously i have a problem. I wanted to animate my boss with this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
GreenfootImage[] images = new GreenfootImage[241];
   int imageNumber;
    
    
   public Boss()
    {
        for( int i=1; i<images.length; i++ ) images[i] = new GreenfootImage( "" + i + ".png" );
        setImage( images[imageNumber] );
         
           
    }
   public void act()
    {
        
       {
        java.util.List<Player/**Name Objekt**/> playersInWorld = getWorld().getObjects(Player.class);
        if (!playersInWorld.isEmpty())
        {
            Player varplayer = playersInWorld.get(0);
             
            SchauzuSpieler(varplayer);
            moveToPlayer(varplayer);
            UmWand();
            Health();
        }
       }
       animation();
        
    }
     
   public void animation()
    {
        imageNumber = ( imageNumber + 1 ) % images.length;
        setImage( images[imageNumber] );;
   
         
    }
The problem is, that there are moments where no frame is shown. In the animations this results in flickering. I tried to handle this problem by adding more frames/images and it got better, but this doesn´t work very well. Thanks to the inventors of Greenfoot and for this forum and sorry for my English^^ alex
davmac davmac

2015/4/14

#
I would guess that some of your image files are missing, empty, or incorrectly named.
davmac davmac

2015/4/14

#
Actually, one problem is that you have no images, because your initialisation loop starts at 1:
1
for( int i=1; i<images.length; i++ ) images[i] = new GreenfootImage( "" + i + ".png" );
However, 'imageNumber' may become 0 due to line 33. In this case it will set a null image. Maybe that is what causes your flickering.
craeXD craeXD

2015/4/14

#
Thanks for the fast answer :D Mhh...the thing is, that i also tested this with gifX, and there wasn´t flickering. Plus i copied everything from 5 frames up to now 240. If an image would be broken, the flickering-effect shoulnt be better now. Instead it should be worser now. alex
craeXD craeXD

2015/4/14

#
Sorry didn´t red the second anser...i test this. e: +1, works excellent. Thank you.
You need to login to post a reply.