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

2015/6/9

Solid object who moves

sehoch sehoch

2015/6/9

#
I'm creating a game and I have clouds who go from right to left (setLocation(getX()-speed, getY());), the problem is that I can't make my clouds "solid" so my actor keeps falling to the ground. I would like to make them "solid". I would really appreciate your help. Thanks!
danpost danpost

2015/6/9

#
There are several methods included in the Actor class that can be used to determine where another type of object is with respect to the actor. Create conditions using tests on their returned values to control when the actor moves.
sehoch sehoch

2015/6/9

#
Okay thanks but how can I get the cloud's position to use it in the mover method, I tried to create a variable in the cloud's method to get his position but I can't call it from the mover's method because it's not static. I don't know if it's understandable :/
danpost danpost

2015/6/9

#
sehoch wrote...
Okay thanks but how can I get the cloud's position to use it in the mover method, I tried to create a variable in the cloud's method to get his position but I can't call it from the mover's method because it's not static. I don't know if it's understandable :/
You need to show the code around which you are trying to do this.
sehoch sehoch

2015/6/10

#
Now I have this and it doesn't work at all but I'm realizing that's really not an accurate code. it is in my hero's code.
if (isTouching(Platform.class) && ySpeed >= 0)
         {
             yFixe = getY() + 10;
             setLocation(getX()-Platform.speed, getY());
         }
danpost danpost

2015/6/10

#
First, I do not understand what 'yFixe' is tracking. Then, I do not see why you would use 'Platform.speed' as the amount to move the hero. Finally, I do not understand why you would move the hero horizontally after checking the vertical speed. You have the following conditions: * if falling -- ySpeed >= 0 * if touching platform -- isTouching(Platform.class) which is fine. But, what is it that needs to be done when these conditions are both true? The hero is to: * stop on platform * lose vertical speed To get the hero to stop on the platform, it must be moved up until it no longer touches that platform. So:
// vertical movement
setLocation(getX(), getY()+ySpeed); // fall or rise
while (ySpeed >= 0 && isTouching(Platform.class))
{
    setLocation(getX(), getY()-1);
    ySpeed = 0;
}
Using 'while' here will raise the hero until it is just above, and not on, the platform (or standing on it). For future jump code, a boolean variable can be declared before the loop initialized to false and set to true within the loop so that jumps can be limited to when standing on a platform.
sehoch sehoch

2015/6/12

#
We have succeed thanks !
You need to login to post a reply.