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

2019/1/14

Colordetection

xandreas_1 xandreas_1

2019/1/14

#
Hi Guys, I am programming a car game at the moment and I want to use Colordetection. My problem is: How can I get an Image from Actor Class1 to use in an Actor Class2 for ColorDetection? Thx for helping
danpost danpost

2019/1/14

#
xandreas_1 wrote...
Hi Guys, I am programming a car game at the moment and I want to use Colordetection. My problem is: How can I get an Image from Actor Class1 to use in an Actor Class2 for ColorDetection?
// in Class2
Actor class1 = (Actor)getWorld().getObjects(Class1.class).get(0);
Then you can get the image, and thereafter the size of the image, and the location coordinates of the actor:
int class1x = class1.getX();
// etc.
xandreas_1 xandreas_1

2019/1/15

#
thx already I will try it later and write if it works
xandreas_1 xandreas_1

2019/1/16

#
So now I set the color to Bkack and took the image from the other Actor. Also the Location of this Actor class gets returned. But how can I now check if my Actor Wheel1 is touching a brown spot of Actor background2? public class Wheel1 extends Actor { Color color = Color.BLACK; Actor background2 = (Actor)getWorld().getObjects(background2.class).get(0); public void act() { this.getX(); this.getY(); private Color getColorAt(this.getX(), this.getY()) { }
danpost danpost

2019/1/16

#
Your code:
public class Wheel1 extends Actor
{
    Color color = Color.BLACK;
    Actor background2 = (Actor)getWorld().getObjects(background2.class).get(0);
    
    public void act() 
    {
        this.getX();
        this.getY();
        
        private Color getColorAt(this.getX(), this.getY())
        {
            
        }
So now I set the color to Bkack and took the image from the other Actor.
Line 3 only saves a color in a field -- it does not set anything. I also do not see anywhere that an image is mentioned.
Also the Location of this Actor class gets returned.
Nothing is done with the location coordinates returned with lines 8 and 9. These returned values go into nothingness (I wanted to use the world "void", but that has special meaning in java). Lines 11 through 14 looks like a method inside of another method. I think you just wanted to call a previously defined method called getColorAt and extract a pixel color from an image (which is not specified). Line 3: I do not, as yet, see any purpose for the color BLACK. Line 4: You cannot get an actor from a world that this actor is not yet in Fields are assigned there values when the actor is created, which happens before it can be placed into any world. Questions: Is there a reason you use an actor to show the background image, rather than using the world background image? If you are to continue using an actor, what are the sizes of (1) the world; and (2) the image of the background actor? and where is the background actor located?
xandreas_1 xandreas_1

2019/1/16

#
Answer for Q1: I got an scrolling Background which I programmed in an Actor class. Is there a way to get a scrolling background in the worldclass while pressing w and s for forwards and backwards? Answer for Q2: Size World(1500, 750, 1) Size Background Actor(1500px x 210px) Localisation Background Actor(750, 650) I should mentioned some facts about my game: One of my Actorclasses is my scrollingbackground(not with the color my car should drive on; it fills the whole screen). The other Actorclass is the class which Size and Localisation I mentioned and with the color the car shuld drive on.
danpost danpost

2019/1/16

#
xandreas_1 wrote...
Is there a way to get a scrolling background in the worldclass while pressing w and s for forwards and backwards?
See my Scroller Class Demos scenario.
Answer for Q2: Size World(1500, 750, 1) Size Background Actor(1500px x 210px) Localisation Background Actor(750, 650)
Would take a bit of calculating to just figure out which pixel in the background image would need to be looked at.
I should mentioned some facts about my game: One of my Actorclasses is my scrollingbackground(not with the color my car should drive on; it fills the whole screen). The other Actorclass is the class which Size and Localisation I mentioned and with the color the car shuld drive on.
Are you saying you have two actors for the "background" that move together creating an unchanging (but moving) image? If so, one can probably be drawn onto the other without creating any issues.
You need to login to post a reply.