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

2014/5/10

Reset turn

warner404 warner404

2014/5/10

#
Hello! I am making a sort of bmx game. and i want that my biker can make a wheelie but i have no clue how to make that. Can anyone help me? thanks a lot!
danpost danpost

2014/5/10

#
If you add transparency to the image of the bike so that the center of the back wheel of the bike is in the center of the image, then all you would need to do is rotate the image.
warner404 warner404

2014/5/11

#
thank you for the reply @danpost, but how do you do that?
danpost danpost

2014/5/11

#
warner404 wrote...
thank you for the reply @danpost, but how do you do that?
Either by way of an image editor that supports transparencies or programmatically with:
GreenfootImage image = new GreenfootImage("imageName.png");
int backAxleX = ??, backAxleY = ??;
int x = backAxleX;
if (x < image.getWidth()/2) x = image.getWidth()-backAxleX;
GreenfootImage image2 = new GreenfootImage(x*2, backAxleY*2)
image2.drawImage(image, x-backAxleX, 0);
setImage(image2);
You will have to replace the proper image filename in line 1 and determine the x and y coordinates of the back axle of the bike within the image for line 2. This presumes that the center of the back wheel is in the lower half of the original image. This may not be the case if you already have some excess transparency below the image of the bike itself.
warner404 warner404

2014/5/11

#
@danpost Thank you it works, but the image is cut in half and the one half is not visable any more. I'm just starting to learn program but how can i make that after the bike did the wheelie(turn), that it automaticly turns back on two wheels? thanks alot!
 
    public void act ()
    {
       // moveHorizontally();
       // moveVertically();
       // int setRotation = getRotation();
        
      
        
        if(Greenfoot.isKeyDown("down"))
        {
        turn(-3);
          GreenfootImage image = new GreenfootImage("biker.png");  
        int backAxleX = 21, backAxleY = 14;  
        int x = backAxleX;  
        if (x < image.getWidth()/2) x = image.getWidth()-backAxleX;  
        GreenfootImage image2 = new GreenfootImage(x*2, backAxleY*2);  
        image2.drawImage(image, x-backAxleX, 0);  
        setImage(image2); 
        
        
       
        } else {
         //turn(3);
         //setRotation(getRotation() + 0); 
         //turn(getRotation());
       
         
        }
        
    }
warner404 warner404

2014/5/11

#
*half of my image disappear
danpost danpost

2014/5/11

#
Please supply the size of your original "biker.png" image and about where in the image is the center of the back wheel (like 'two-thirds down and one-quarter right').
warner404 warner404

2014/5/11

#
and how must i do that?
danpost danpost

2014/5/11

#
Ok. First, insert at line 13 in the code above (after the 'GreenfootImage image = ...' line) the following line:
System.out.println("width: "+image.getWidth()+"\theight: "+image.getHeight());
compile and run, pressing the down key once. Report back what values for width and height are returned.
warner404 warner404

2014/5/11

#
width: 80 height:80
danpost danpost

2014/5/11

#
Alright, now, replace your act method with this:
public void act()
{
    if (Greenfoot.mouseClicked(this))
    {
        MouseInfo mouse = Greenfoot.getMouseInfo();
        if (mouse == null) return;
        System.out.println("BACK AXLE\tx: "+mouse.getX()-(getX()-40)+"\ty: "+mouse.getY()-(getY()-40));
    }
}
compile and run; this time click directly on the center of the back wheel and report back what are returned.
You need to login to post a reply.