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

2018/12/26

Game Creation: Directional Idle, Shooting and Jumping.

3
4
5
6
7
8
9
Unlimited Unlimited

2018/12/27

#
public void moveVertically()
    {
         boolean onGround = false; // assume in air
       vSpeed += acceleration; // apply gravity
       setLocation(getX(), getY()+vSpeed); // fall
       Actor actor = getOneIntersectingObject(Collider.class);
       if (actor != null)
       { // colliding with another actor
           int vDir = (int)Math.signum(vSpeed); // vertical direction of movement
           vSpeed = 0; // kill vertical speed
           if (vDir > 0) onGround = true; // landing and not bopping head
           setLocation(getX(), actor.getY()-vDir*(actor.getImage().getHeight()+getImage().getHeight())/2); // assigning stop location
        }
        if (onGround && Greenfoot.isKeyDown("space")) vSpeed = -20; // initiate a jump
    }
danpost danpost

2018/12/27

#
On line 12 add '+1' after '/2'. Also, in horizontalMovement method, add '+1' after '/2' in line 124 (of previous code post). Hopefully, that will stop the teleporting.
Unlimited Unlimited

2018/12/27

#
That sadly Didnt Work. The character is still teleporting around.
danpost danpost

2018/12/27

#
Unlimited wrote...
That sadly Didnt Work. The character is still teleporting around.
I thought for sure that would do it. Is it possible for you to upload the scenario, with source, so it can be examined directly?
Unlimited Unlimited

2018/12/27

#
Sure though i do not know how.
danpost danpost

2018/12/27

#
Unlimited wrote...
Sure though i do not know how.
Click 'Share' at top-right of greenfoot frame. Choose tab to share at greenfoot.org. Fill in info (make sure to check the 'Publish with source' checkbox) and click the 'Share' button to upload.
Unlimited Unlimited

2018/12/27

#
Alright is up. Thats what it looks like.
danpost danpost

2018/12/27

#
Unlimited wrote...
Alright is up. Thats what it looks like.
Okay -- got it. You can remove the scenario, if you wish. Go to it while signed in and click 'delete scenario'.
Unlimited Unlimited

2018/12/27

#
Alright, Also i have the background that is relatively big and its looping i wanted to make it smaller but it would look wierd if the background loops. I wanted to prevent the background form scrolling vertically and only horizontally to be able to make it smaller but i didnt get to that yet.
danpost danpost

2018/12/27

#
Unlimited wrote...
Alright, Also i have the background that is relatively big and its looping i wanted to make it smaller but it would look wierd if the background loops. I wanted to prevent the background form scrolling vertically and only horizontally to be able to make it smaller but i didnt get to that yet.
I believe that what is happening is due to the scrolling system; but, to pin down exactly what is happening would be a difficult task. The scrolling system you are using is a bit bulky and hard to work with (as already determined). My Scrolling Tutorial scenario show how to use my Scroller class (link in description of tutorial). A demo was also uploaded -- a link to it is also in the description of the tutorial.
Unlimited Unlimited

2018/12/27

#
Well the scenario is not mine so i cannot say. I remember it used to work just some time before. It is wierd that the teleportation is taking place only when touching the platform. Though if you dont know what to do then i definetly do not. I cant really help here, what is a problem since i really need to finish this.
Unlimited Unlimited

2018/12/27

#
Oh wait i think i realiced why that happens.
public void moveVertically()
    {
         boolean onGround = false; // assume in air
       vSpeed += acceleration; // apply gravity
       setLocation(getX(), getY()+vSpeed); // fall
       Actor actor = getOneIntersectingObject(Collider.class);
       if (actor != null)
       { // colliding with another actor
           int vDir = (int)Math.signum(vSpeed); // vertical direction of movement
           vSpeed = 0; // kill vertical speed
           if (vDir > 0) onGround = true; // landing and not bopping head
           setLocation(getX(), actor.getY()-vDir*(actor.getImage().getHeight()+getImage().getHeight())/2-30); // assigning stop location
        }
        if (onGround && Greenfoot.isKeyDown("space")) vSpeed = -20; // initiate a jump
    }
Ive changed this line to -30. Now i am somewhat bouncing around but i am not teleporting until i touch the border. Meaning it does happen because the sprites overlap. There was one video that had this problem. He changed both x and y and to like + or - 3 or so to prevent that.
Unlimited Unlimited

2018/12/27

#
This is what im thinking about
public boolean canMoveLeft()
    {
       boolean canMoveLeft = true;
       
       int imageWidth = getImage().getWidth();
       int imageHeight = getImage().getHeight();
       if (getOneObjectAtOffset(imageWidth/-2 -3, imageHeight/-2, Border.class) !=null ||
       getOneObjectAtOffset(imageWidth/-2 -3, imageHeight/2, Border.class) !=null)
            canMoveLeft = false;
       
       return canMoveLeft;
        
    }
    
    public boolean canMoveRight()
    {
        boolean canMoveRight = true;
       
        int imageWidth = getImage().getWidth();
        int imageHeight = getImage().getHeight();
        if (getOneObjectAtOffset(imageWidth/2 +3, imageHeight/-2, Border.class) !=null ||
        getOneObjectAtOffset(imageWidth/2 +3, imageHeight/2, Border.class) !=null)
            canMoveRight = false;
       
        return canMoveRight;
    }
Is that helpful?
danpost danpost

2018/12/27

#
Unlimited wrote...
This is what im thinking about << Code Omitted >> Is that helpful?
Not really. You should not have those methods anymore.
Unlimited Unlimited

2018/12/28

#
No i know, i dont have them in the code. I just though the way its handeled here would be helpful. Cause without the -3s and -2s the same thing happened with this method.
There are more replies on the next page.
3
4
5
6
7
8
9