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

2013/7/31

getColorAt - What am I doing wrong?

8bitcarrotjuice 8bitcarrotjuice

2013/7/31

#
First of all, this is the scenario I am working on: http://www.greenfoot.org/scenarios/9083 Secondly, if you don't want to download the source for yourself, here is what I have in the player class:
import greenfoot.*;  
import java.awt.Color;  
public class Player extends Connector
{
    boolean fall;
    boolean ready;
    double vspeed;
    double gravity=0.2;
    double exactX,exactY;
    public void act() 
    {
        detection();
        gravity();
    }    
    public void detection()
    {
        if(getOneIntersectingObject(TopPlatform.class)!=null){

            ready=true;
            vspeed=0;
        }
        if(getOneIntersectingObject(TopPlatform.class)==null){

            ready=false;
        }
}
    public void gravity()
    {
        if(Greenfoot.isKeyDown("a"))  
        {  
            setLocation(getexactX()-2,getexactY());  
        }  
        if(Greenfoot.isKeyDown("d"))  
        {  
            setLocation(getexactX()+2,getexactY());  
        }    
        if(ready==true&&Greenfoot.isKeyDown("w"))           
        {  
            vspeed=-6;   
            ready=false;  
            fall=true;
        }  
        if(fall==true)
        {
            vspeed += gravity; // add gravity to speed  
            setLocation(getexactX(), getexactY()+vspeed);
        }
        Actor tp=getOneObjectAtOffset(0,0,TopPlatform.class);
//I need help from here
        if(tp.getImage().getColorAt(getX()-getImage().getWidth()/2,getY()-getImage().getHeight()/2).equals(new Color(0,0,0,50))){
            fall=false;
        }
}
    public void setLocation(int x, int y) {    
    exactX = x;    
    exactY = y;    
    super.setLocation(x, y);    
}  
    public void setLocation(double x, double y) {    
    exactX = x;    
    exactY = y;    
    super.setLocation((int) x, (int) y);    
}    
    public double getexactX() {    
    return exactX;    
}    
    public double getexactY() {    
    return exactY;    
}    
}
I marked out where I need help. Help please?
danpost danpost

2013/7/31

#
It looks like you are trying to get coordinate for the background of the world instead of from the image of the TopPlatform object. Basically, you are missing operations dealing with the location of the TopPlatform object.
8bitcarrotjuice 8bitcarrotjuice

2013/7/31

#
ah, thanks Dan- will look into it soon!
You need to login to post a reply.