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

2020/6/13

userinfo

1
2
Roshan123 Roshan123

2020/6/13

#
Dapost, plz go through the link i created a subclass of actor and i added it to the world So my question is that, can the user be able to see their own name in the world
danpost danpost

2020/6/13

#
Roshan123 wrote...
So my question is that, can the user be able to see their own name in the world
The linked discussion shows that the user's name can be acquired when the user is logged in. It would be simple to show it on screen (in multiple ways).
Roshan123 Roshan123

2020/6/13

#
so how will i show it on the screen plz can you write it from import
danpost danpost

2020/6/13

#
Roshan123 wrote...
so how will i show it on the screen plz can you write it from import
You can: (1) use World instance method showText (on world); (2) use GreenfootImage instance method drawString (on world's background image); or (3) create a GreenfootImage using text image constructor and (a) use GreenfootImage instance method drawImage (on world's background image), or (b) use setImage on an Actor instance in the world.
Roshan123 Roshan123

2020/6/13

#
i m not able to understand plz write the code by using 3(b) way
danpost danpost

2020/6/13

#
Roshan123 wrote...
i m not able to understand plz write the code by using 3(b) way
The basics are in the following code:
Actor name = new Actor(){};
name.setImage(new GreenfootImage(userName, 28, Color.BLACK, new Color(0, 0, 0, 0)));
addObject(name, 100, 20);
However, it is recommended that line 1 actually instantiate a subclass of Actor that is explicitly described.
Roshan123 Roshan123

2020/6/14

#
do you mean this or something else
 // i named this class as Actor(Class)
public String getNameOfUser()
{
    String username;
    if (UserInfo.isStorageAvailable())
    {
        UserInfo myInfo = UserInfo.getMyInfo();
        return myInfo.getUserName();
    }
    return "";
}
...
// in world
Actor name = new Actor(){};
name.setImage(new GreenfootImage(userName, 28, Color.BLACK, new Color(0, 0, 0, 0)));
addObject(name, 100, 20);
Roshan123 Roshan123

2020/6/14

#
// in world
Actor name = new Actor(){};
name.setImage(new GreenfootImage(userName, 28, Color.BLACK, new Color(0, 0, 0, 0)));
addObject(name, 100, 20);

public String getNameOfUser()
{
    String username;
    if (UserInfo.isStorageAvailable())
    {
        UserInfo myInfo = UserInfo.getMyInfo();
        return myInfo.getUserName();
    }
    return "";
}
Roshan123 Roshan123

2020/6/14

#
which one is correct 1st one or 2nd one
danpost danpost

2020/6/14

#
Roshan123 wrote...
this will work or not << Code Omitted >>
Remove line 4 ("String username;").
... << Code Omitted >>
Change "userName" in line 2 to "getNameOfUser()".
danpost danpost

2020/6/14

#
You may want to replace return ""; with something like return "Player"; or return "Anonymous"; so the image will have some body (pardon the pun -- somebody).
Roshan123 Roshan123

2020/6/14

#
how will fix this lag
import greenfoot.*;  
public class Win extends World
{
    User name = new User(){};
    public String getNameOfUser()
    {
        if(UserInfo.isStorageAvailable())
        {
          UserInfo myInfo = UserInfo.getMyInfo();
          return myInfo.getUserName();
        }
        return "Alien";
    }
    public Win()
    {    
        super(800, 600, 1); 
    }
    public void act()
    {
        name.setImage(new GreenfootImage(getNameOfUser()+" wins",37,Color.YELLOW,new Color(0,0,0,0)));
        addObject(name,getWidth()/2,50);
        getNameOfUser();
        Greenfoot.playSound("w.mp3");
        Greenfoot.stop();
    }
}
its my game which is lagging i added it at the end of the game but then also its lagging
Roshan123 Roshan123

2020/6/14

#
dont mind now i fixed it and thanks for helping me a lot
danpost danpost

2020/6/14

#
import greenfoot.*;

public class Win extends World
{
    public String getNameOfUser()
    {
        if(UserInfo.isStorageAvailable())
        {
          UserInfo myInfo = UserInfo.getMyInfo();
          return myInfo.getUserName();
        }
        return "Alien";
    }
    public Win()
    {    
        super(800, 600, 1); 
        User name = new User();
        name.setImage(new GreenfootImage(getNameOfUser()+" wins",37,Color.YELLOW,new Color(0,0,0,0)));
        addObject(name,getWidth()/2,50);
        Greenfoot.playSound("w.mp3");
        Greenfoot.stop();
    }
}
Roshan123 Roshan123

2020/6/14

#
danpost wrote...
will this stop the game lag
There are more replies on the next page.
1
2