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

2018/4/28

Using a GIF

1
2
Miguel.Valdez Miguel.Valdez

2018/4/28

#
So i am trying to use a GIF in my project and keep gett a error java.lang.OutOfMemoryError: Java heap space at GifImage.loadImages(GifImage.java:127) at GifImage.<init>(GifImage.java:48) at GameOv.<init>(GameOv.java:11) at Birdy.signGameOv(Birdy.java:116) at Birdy.birdDead(Birdy.java:125) at Birdy.act(Birdy.java:152) I have imported the GifImage Class & made an actor class with the gif image set to it and this being my code in it
1
2
3
4
5
6
7
8
9
10
11
12
public class GameOv extends Actor
{
    GifImage myGif = new GifImage("GameOver.gif");
    /**
     * Act - do whatever the GameO wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void GameOv()
    {
        setImage(myGif.getCurrentImage());
    }   
}
and I am trying to use it in another class as a method that i can call upon when needed, in this way:
1
2
3
4
5
6
7
8
9
10
    /**
 
any suggestions on what im doing wrong?
     *inserts gif that signals losing.
     */
    private void signGameOv()
    {
        GameOv gameOver = new GameOv();
        getWorld().addObject(gameOver, getWorld().getWidth()/2,getWorld().getHeight()/2);
    }
danpost danpost

2018/4/28

#
Sounds and images take the most toll on memory. Try to limit the number of references to these type objects. Also, if possible, try to size them down
Miguel.Valdez Miguel.Valdez

2018/4/29

#
Darn it ok... it regards to the code, was it ok?
Miguel.Valdez Miguel.Valdez

2018/4/29

#
Well, I massively recompressed the gif and got it to stop crashing. When my bird dies (as shown in the code) the GIF shows, but doesn't play the gif?
danpost danpost

2018/4/29

#
Miguel.Valdez wrote...
Well, I massively recompressed the gif and got it to stop crashing. When my bird dies (as shown in the code) the GIF shows, but doesn't play the gif?
No act method in GameOv actor to run animation.
Miguel.Valdez Miguel.Valdez

2018/4/29

#
ok so my code for the GIF image is
1
2
3
4
5
6
7
8
9
10
11
{
    GifImage myGif = new GifImage("GameOver.gif");
    /**
     * Act - do whatever the GameO wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        setImage(myGif.getCurrentImage());
    }
}
and in my bird class im using this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
 *inserts gif that signals losing.
 */
private void signGameOver()
{
    GameOver gameOver = new GameOver();
    getWorld().addObject(gameOver, getWorld().getWidth()/2,getWorld().getHeight()/2);
}   
 
public void birdDead()
{
    Greenfoot.playSound("sfx_hit.wav");
    GameMusic.stop();
    Greenfoot.playSound("MBGameOver.mp3");
    signGameOver(); //what should be animating the gif when bird dies
    Greenfoot.stop();
}
The image will pop up when bidy dies, but it will not generate throught the GIF
Yehuda Yehuda

2018/4/29

#
Is GameOver the same thing as GameOv? If it isn't then you will have to show the code for the class you are using. If it is the same then why is the class you showed called GameOv and the used Actor (in Bird) called GameOver?
Miguel.Valdez Miguel.Valdez

2018/4/30

#
In bird class
1
2
3
4
5
public void silentBirdDead()
{
    getWorld().addObject(new GameOver(), getWorld().getWidth()/2,getWorld().getHeight()/2);
    Greenfoot.stop();
}
im adding the GameOver(this is the GIF) into the world when bird dies. The image does come up when the bird dies but the GIF doesnt play. I imported the GIFImage class //as other class and then this is the code for the GameOver class that pertains to the GIF
1
2
3
4
5
6
7
8
9
10
11
12
public class GameOver extends Actor
{
    GifImage myGif = new GifImage("GameOver.gif");
    /**
     * Act - do whatever the GameO wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        setImage(myGif.getCurrentImage());
    }
}
Yehuda Yehuda

2018/4/30

#
The act method won't execute if you do Greenfoot.stop(). My last post was just commenting on the change of the class name which was GameOv but GameOver was called in Bird class.
Miguel.Valdez Miguel.Valdez

2018/4/30

#
my fault, sorry about that. so I removed the Greenfoot.stop(), but still does not play through the gif?
Yehuda Yehuda

2018/4/30

#
Do you know for sure that you have a good .gif, does it work fine regularly? If the answers are positive then show the full Bird class code.
Miguel.Valdez Miguel.Valdez

2018/4/30

#
if I right click and do new GameOver() and drag it into the world scenario then click run, the gif will work.
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
public void act()
{
    theEndGame(); // the code is beign called here
}
public void birdDead()
{
    Greenfoot.playSound("sfx_hit.wav");
    GameMusic.stop();
    Greenfoot.playSound("MBGameOver.mp3");
    getWorld().addObject(new GameOver(), getWorld().getWidth()/2,getWorld().getHeight()/2);
}
 
 public void silentBirdDead()
{
    getWorld().addObject(new GameOver(), getWorld().getWidth()/2,getWorld().getHeight()/2);
}
private void theEndGame()
{
    //Falls off the background.   
    if (getY() > getWorld().getHeight()-1)
    {
        if (!GameMusic.isPlaying())
        {
            silentBirdDead();
        }
            
        else
        {   
            birdDead();
        
   }
Yehuda Yehuda

2018/4/30

#
Miguel.Valdez wrote...
if I right click and do new GameOver() and drag it into the world scenario then click run, the gif will work. <Code Omitted><Code Omitted>
That's why I wanted to see the (FULL) code. In the Bird class press Ctrl+A (Cmd+A) to select everything then Ctrl+C (Cmd+C) to copy it. I didn't see you changed your post.
Miguel.Valdez Miguel.Valdez

2018/4/30

#
Yehuda wrote...
Miguel.Valdez wrote...
if I right click and do new GameOver() and drag it into the world scenario then click run, the gif will work. <Code Omitted><Code Omitted>
That's why I wanted to see the (FULL) code. In the Bird class press Ctrl+A (Cmd+A) to select everything then Ctrl+C (Cmd+C) to copy it. I didn't see you changed your post.
no problem, that was my fault
Miguel.Valdez Miguel.Valdez

2018/4/30

#
never mind Yehuda, im getting the out of memeory error again.... and i jsut now saw i still had a Greenfoot.stop() which i did remove.
There are more replies on the next page.
1
2