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

2012/11/19

Bug with adaption of ScrollWorld scenario

lgbrf lgbrf

2012/11/19

#
I'm trying to create an assassins creed side scroller. I'm experiencing a bug with the jumping method ive implemented. Entire Assassin Class:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Assassin here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Assassin extends ScrollActor
{
    int speed = 5;
    int gravity = 10;
    int vertSpeed;
    /**
     * Act - do whatever the Assassin wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move();
        jump();
    }    

    public void move()
    {
        if (Greenfoot.isKeyDown("right")) {
            // move the camera forwards, actor moves with the camera by default
            getWorld().moveCamera(speed);
        }
        if (Greenfoot.isKeyDown("left")) {
            // move the camera backwards, actor moves with the camera by default
            getWorld().moveCamera(-speed);
        }
    }

    public void jump()
    {
        if(onGround()){
            if(Greenfoot.isKeyDown("up") || Greenfoot.isKeyDown( "space")){
                setLocationFromCamera(getXFromCamera(), getYFromCamera() - 10*gravity);
            }            
        }
        else{
            fall();
        }
    }

    public boolean onGround(){
        Object under = getOneObjectAtOffset(0, getImage().getHeight()/2-8 , null);
        return under != null;
    }

    public void fall()
    {
        setLocationFromCamera(getXFromCamera(), getYFromCamera() + gravity);
    }
}
danpost danpost

2012/11/19

#
What is the bug? Just saying you are experiencing one does not tell us anything. What is the difference between what you want and what is actually happening?
lgbrf lgbrf

2012/11/19

#
sorry, When the assassin jumps, before he has moved out of the initial location he jumps fine. When i move him right, as he jumps, he jumpes fine, but when he falls he goes right drastically, going off the screen.
danpost danpost

2012/11/20

#
I have reproduced your problem. However, have not been able to locate the bug (as yet). This may take some time to resolve.
lgbrf lgbrf

2012/11/21

#
I'm using SPower's scrollworld/scrollactor classes if that helps.
danpost danpost

2012/11/21

#
I found the code a bit hard to follow and was not able to figure out what was going on. I just uploaded a new Support World Class for a scroller (that does not need a super scroll actor class). It is actually fairly straight-forward, well documented, and easy-to-use. It has instructions and (of course) a code example. You might give it a go -- and let me know what you think. It is here.
lgbrf lgbrf

2012/11/21

#
alright i will do, and ill post back here when ive tried it.
lgbrf lgbrf

2012/11/21

#
This setup for a scrolling world seems much more intuitive. Is it alright if i use this for my scenario?
danpost danpost

2012/11/21

#
If it works for you, that is fine. But, I do request you 'like' the scenario.
lgbrf lgbrf

2012/11/21

#
Done :) thanks
danpost danpost

2012/11/21

#
No. Thank U! (I do appreciate it)
You need to login to post a reply.