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

2020/12/6

Can I create GUI for my game?

Honza Honza

2020/12/6

#
Hi, I was wondering if it's possible to create GUI for my game. I am new to Greenfoot so I hope anyone can help me with this or redirect me to it, Thank you in advance.
danpost danpost

2020/12/6

#
Honza wrote...
I was wondering if it's possible to create GUI for my game. I am new to Greenfoot so I hope anyone can help me with this or redirect me to it,
Of course it is possible. What all exactly are you wanting to implement?
Honza Honza

2020/12/7

#
I am working with my friend on a school project and our goal is to create a functional board game. We were wondering if it's possible to create a title screen with buttons like "Start", "Exit". If start is clicked then game starts.
danpost danpost

2020/12/7

#
Honza wrote...
I am working with my friend on a school project and our goal is to create a functional board game. We were wondering if it's possible to create a title screen with buttons like "Start", "Exit". If start is clicked then game starts.
In short, it would be like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import greenfoot.*;
 
public class TitleScreen extends World
{
    Actor btnExit, btnStart;
     
    public TitleScreen()
    {
        super(800, 600,, 1);
        btnExit = new Button("Exit");
        addObject(btnExit, 400, 500);
        btnStart = new Button("Start");
        addObject(btnStarrt, 400, 400);
    }
     
    public void act()
    {
        if (Greenfoot.mouseClicked(btnStart)) Greenfoot.setWorld(new GameWorld());
        if (Greenfoot.mouseClicked(btnExit)) Greenfoot.stop();
    }
}
The Button class should only contain imaging codes -- nothing more.
Honza Honza

2020/12/7

#
Thank you very much!!
RcCookie RcCookie

2020/12/8

#
You may be interested in this: Project: UI by RcCookie
danpost danpost

2020/12/11

#
mik. wrote...
Instead of passing string what should i do to make shapes
Everything before line 8 is pretty much junk. However, except for the fact that you never create a GreenfootImage object, the rest looks spot on.
danpost danpost

2020/12/11

#
mik. wrote...
Ohhh sorry GreenfootImage img=getBackground ();
No. ... = new Greenfootimage(50, 50);
danpost danpost

2020/12/11

#
mik. wrote...
Ok but how will it give output I mean If mouse clicks img then show text vxhdhs //GreenfootImage img=Greenfootimage(50, 50);
Complete gibberish. What "output"? img is created before button. Button is clicked only after put in world. Actors are clicked on -- not images (although, the image of the actor does determine where a click on an actor would be considered valid).
Roshan123 Roshan123

2020/12/11

#
@ mik, I downloaded ur scenario and got to know the problem..... U can write something like this Note- sorry, I m not sure that its related to ur topic or not, but I think this may help u out
1
2
3
4
5
MouseInfo mouse=Greenfoot.getMouseInfo () ;
if (Greenfoot . mousePressed (null) )
int x = mouse.getX();
int y = mouse.getY();
if (x> 100 && x<150 && y>100 && y<150) showText("exit",300,300);
Paste it in world
Roshan123 Roshan123

2020/12/12

#
mik. wrote...
And what for blue Its not working
Ohhhh.... It will never work becaz i never gave u the code for blue button If u have further more doubts then creat ur own discussion
You need to login to post a reply.