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

2015/3/19

how to add object

greenfoot_user greenfoot_user

2015/3/19

#
i want to display balloon at the end of level in my game after successful completion of level. How can i do so?
davmac davmac

2015/3/19

#
What part are you having trouble with? What have you tried?
greenfoot_user greenfoot_user

2015/3/19

#
I am having trouble with the end part. after successfully completing a stage i want to display the balloons and the congratulations image . I'm having problem with displaying the balloons after i complete the game
davmac davmac

2015/3/19

#
I'm having problem with displaying the balloons after i complete the game
But what part of that are you having problems with? What sort of problems are you having? And again: what have you tried? (To display balloons, you would need an actor class to represent the balloons, and have its image set to be the balloons. You would then create a new instance of that actor, and add it to the world. Obviously you would do this conditionally, once the game is completed. What I'm asking is, which part of that are you having problems with?)
greenfoot_user greenfoot_user

2015/3/19

#
creating the object class part
davmac davmac

2015/3/19

#
creating the object class part
You mean creating the object? "object class" doesn't make sense (not in this context anyway). You use 'new' for that - so if you have a class called 'Balloons' you would write something like:
1
2
Balloons b = new Balloons();
addObject(b, 100, 100);  // or possibly 'getWorld().addObject(b,100,100)'
Or, if you mean creating the actor class, it's just a class. Right-click on "Actor" and choose "new subclass". You must know how to do this!
greenfoot_user greenfoot_user

2015/3/20

#
After trying the solution you provided it display the error : cannot find symbol -variable object name Can you plz provide me the full coding to declare the object and use it
davmac davmac

2015/3/20

#
After trying the solution you provided it display the error : cannot find symbol -variable object name
The code I provided could not have produced that error message.
Can you plz provide me the full coding to declare the object and use it
How about you show the code that you tried, and we can help find what's wrong with it?
greenfoot_user greenfoot_user

2015/3/22

#
There was some error in my code and I finally corrected it and it worked Thanks Can i add some animations in my game which displays fire crackers displaying you won or something like that
Srax Srax

2015/3/25

#
greenfoot_user wrote...
There was some error in my code and I finally corrected it and it worked Thanks Can i add some animations in my game which displays fire crackers displaying you won or something like that
If you want to have animations (gifs) there is a very easy way to do so. What you do is, you import an actor called 'GifImage' (Press Edit --> Import Class --> GifImage --> Import) When you have imported the class, you will be able to see the code. The code is over 1.000 lines so i wont post the whole code, but what you need is at the top of the actors code. You will see a code like this just above the "Public class GifImage". The code looks like this
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
/**
 * This class can be used to read animated gif image files and extract the individual
 * images of the animation sequence.
 * <p>
 * To use GifImage in an actor, declare it as an instance variable:
 *
 * <pre>
 * {@code
 *    GifImage gifImage = new GifImage("mygif.gif");
 * }
 * </pre>
 *
 * Then, in the act() method of your actor, set the actor's image to the current image
 * from your GifImage instance:
 *
 * <pre>
 * {@code
 *     setImage(gifImage.getCurrentImage());
 * }
 * </pre>
 
 * @author Michael Berry
 * @author Neil Brown
 */
public class GifImage
{
    /** The images used in the animation. */
    private GreenfootImage[] images;
    /** The delay between each frame. */
    private int[] delay;
    /** The index of the current frame in the GIF file. */
    private int currentIndex;
    /** The time passed since the last frame in ms. */
    private long time;
    /** The GIF file that contains the animation. */
    private String file;
    /** Whether the animation is paused or not. */
    private boolean pause;
It comes with a clear instruction of what to do. Basically you change the "mygif.gif" in the "GifImage gifImage = new GifImage("mygif.gif");" code, to the name of your gif. Lets say your gif name is "wingif.gif". Then the code will look like this:
1
"GifImage gifImage = new GifImage("wingif.gif");
When thats done, you make an actor, and implement the code as it tells you in the "GifImage" actor. I made a project where it spawns a wombat, who eats a strawberry. Once the strawberry a gif saying "Winner" pops up, and a timer that restarts the game. Download it here. Enjoy.
You need to login to post a reply.