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

2017/12/26

Need help with score/life

1
2
3
danpost danpost

2018/1/24

#
RevoltecX7 wrote...
Can you please explain me, what exactly this doing? << Code Omitted >> You return Actor... but what it mean? and why?
The method creates an Actor object (which is not explicitly named). The behavior of the actor is modified such that its location cannot be set using the 'setLocation' method (calling setLocation on it runs an empty code block). The Actor object is then returned to the calling statement. I use it to create the score and world text display objects, which I did not want to be pulled down by the "gravity" added to all actors by the world act method.
RevoltecX7 RevoltecX7

2018/1/25

#
So simply-> you create an actor which u return to somewhere. And this actor is a function of setLocation, what it do nothing... whaaaat. :D
RevoltecX7 RevoltecX7

2018/1/25

#
in header when u write "private static Actor scoreText". - You creating virtual Actor what (for now) doesn't exist. But next u set him some features. This "virtual" actor will get return Actor from function "getNewStillActor()"... and this function have actor what have function "public void setLocation(int x, int y)" and make nothing... How he know, how he get - informations about x/y positions? How it is connected together?
Vercility Vercility

2018/1/25

#
Every actor is affected by gravity due to code in the World class by calling setLocation on it. He removed the code from setLocation of these Actors to prevent them from falling (because of gravity) because you obviously dont want your score and text to fall.
RevoltecX7 RevoltecX7

2018/1/25

#
But there is not a command for falling down for objects. There is just something, what create showScore and that's all.
Vercility Vercility

2018/1/25

#
 /**
     * Demo act method: this can be removed or revised as needed; added to give all actors a downward pull;
     * (notice how score and level text fields are pinned in place)
     */
    public void act()
    {
        for (Object obj : getObjects(null))
        {
            Actor actor = (Actor)obj;
            actor.setLocation(actor.getX(), actor.getY()+1);
        }
RevoltecX7 RevoltecX7

2018/1/25

#
I was talking about this
public static Actor getNewStillActor()
{
        return new Actor()
        {
            public void setLocation(int x, int y){}
        };
}
In my project I will don't use that code, what u post. I don't need it.
Vercility Vercility

2018/1/25

#
Im getting the feeling u're not even reading my text. the newstillactor method just returns an actor that cant be moved by setLocation because the method is empty. He made it so that he can use those actors for score/text display because they arent affected by gravity (which calls setLocation on every object) U were just asking what it does, whether u need it or not is your concern.
RevoltecX7 RevoltecX7

2018/1/25

#
Ooooh, so maybe now i get it. So... there is 2 actors which one is making all actors falling and second is for "stay on one position" - can say like that. So then, in my project - when i have actors in the world and only my Character will be moving by me. I don't need that getnewstillactor()?
RevoltecX7 RevoltecX7

2018/1/25

#
Mmm, I get it. xD so -> scoreText is just an Actor which I put to it new Actor to the new setLocation. But what mean exactly that int x / int y in returning new Actor?
Vercility Vercility

2018/1/25

#
RevoltecX7 wrote...
Mmm, I get it. xD so -> scoreText is just an Actor which I put to it new Actor to the new setLocation. But what mean exactly that int x / int y in returning new Actor?
he just defined the method setLocation to take 2 variables but do nothing
RevoltecX7 RevoltecX7

2018/1/25

#
Vercility wrote...
he just defined the method setLocation to take 2 variables but do nothing
Then he creating actor to random position? He create setLocation function with 2 integers. He can call it somehow another? Like -> locationSet? (it isn't connected with function setLocation(x,y)? Sorry, for my stupid questions... but I want be sure as I can. :D
danpost danpost

2018/1/25

#
The Actor class has a 'setLocation(int, int)' method. The 'getNewStillActor' method creates an Actor object whereby the implementation of that Actor class method is removed (by overriding the method -- making all calls to 'setLocation(int, int)' on these actors use the overriding method instead of the one in the Actor class). The 'getNewStillActor' method creates an Actor object that is positionally locked once placed into a world.
RevoltecX7 RevoltecX7

2018/1/25

#
Um... when "getnewstillactor" returning class of actor(setLocation) .... why then we write "addObject(scoreText, positionX, positionY)". In here "addObject..." we set positions. So I still can't get, why we need to get "getNewStillActor". I understand it this how: (please, answer me to this, if I get it correctly or nope) The "scoreText" is an Actor, where we put "getNewStillActor()", because we need to inicialize it. Soo. In "getNewStillActor()" we have "return new Actor()", where we have function of something. (Now I get, we don't have to have that function... this "new Actor()" can be empty.). And after returned new Actor we've got a scoreText as new Actor. If I get it correctly I am happy to say you guys, u finaly teach me, what to create score/life in the levels/subclass. Thanks a lot of! :)
danpost danpost

2018/1/25

#
RevoltecX7 wrote...
Um... when "getnewstillactor" returning class of actor(setLocation) .... why then we write "addObject(scoreText, positionX, positionY)". In here "addObject..." we set positions. So I still can't get, why we need to get "getNewStillActor".
The method only return an Actor object that is incapable of being moved when placed into a world. It does not add it into a world.
I understand it this how: (please, answer me to this, if I get it correctly or nope) The "scoreText" is an Actor, (yes) where we put "getNewStillActor()", because we need to inicialize it (assign an actor to it, yes). Soo. In "getNewStillActor()" we have "return new Actor()", where we have function of something. (Now I get, we don't have to have that function... this "new Actor()" can be empty.).
The un-named Actor is not empty. It still has all the methods and fields supplied to it by the greenfoot.Actor and java.lang.Object classes. The only difference is that 'setLocation' no longer does anything to the actors created by the 'getNewStillActor' method.
There are more replies on the next page.
1
2
3