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

2014/1/29

how to make animation overlap image in world?

0868626 0868626

2014/1/29

#
hello dear greenfooters i have a question: in my world i have an image and an animation (frame) but the image is hidden behind the animation is there a way to change this and show the image above the animation. here's my world's code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public Haven()
    {   
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 600, 1,false);
 
        vulHaven();
        for(int y = 80; y < 600; y += 160)
        {
            for(int x = 80; x < 800; x += 160)
            {
                WaterMo water = new WaterMo();
                addObject(water,x,y);
            }
        }
 
        setPaintOrder(Achtergrond3.class);
    }
here is the actor code of water
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
public class WaterMo extends Actor
{
 
    GreenfootImage w1 = new GreenfootImage("w1.png");
    GreenfootImage w2 = new GreenfootImage("w2.png");
    GreenfootImage w3 = new GreenfootImage("w3.png");
    GreenfootImage w4 = new GreenfootImage("w4.png");
    GreenfootImage w5 = new GreenfootImage("w5.png");
    GreenfootImage w6 = new GreenfootImage("w6.png");
    GreenfootImage w7 = new GreenfootImage("w7.png");
    GreenfootImage w8 = new GreenfootImage("w8.png");
    GreenfootImage w9 = new GreenfootImage("w9.png");
    GreenfootImage w10 = new GreenfootImage("w10.png");
 
    public int animationCount = 1;
    public int frame = 1;
    public void act()
    {
        //setLocation(getX(),getY()+1);
        ani();
    }   
 
    public void ani()
    {
        if(animationCount % 6 == 0)
        {
            animation();
        }
        animationCount += 1;
 
    }
 
    public void animation()
    {
        if(frame == 1)
        {
            setImage(w1);
            frame = 2;
        }
        else if(frame == 2)
        {
            setImage(w2);
            frame = 3;
        }
        else if(frame == 3)
        {
            setImage(w3);
            frame = 4;
        }
        else if(frame == 4)
        {
            setImage(w4);
            frame = 5;
        }
        else if(frame == 5)
        {
            setImage(w5);
            frame = 6;
        }
        else if(frame == 6)
        {
            setImage(w6);
            frame = 7;
        }
        else if(frame == 7)
        {
            setImage(w7);
            frame = 8;
        }
        else if(frame == 8)
        {
            setImage(w8);
            frame = 9;
        }
        else if(frame == 9)
        {
            setImage(w9);
            frame = 10;
        }
        else if(frame == 10)
        {
            setImage(w10);
            frame = 1;
        }
 
    }
 
}
i want the image of te world to be shown above the water
Gevater_Tod4711 Gevater_Tod4711

2014/1/29

#
The world background is always behind the actors but you could create an actor class that has the same image as the world and add this actor in front of the water object. So it would look like the world is in front of the water.
You need to login to post a reply.