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

2018/2/25

Making object return to starting position when touching a color

1
2
3
4
game_salajan game_salajan

2018/2/25

#
Hello there ! I want to make a 2D rally game on greenfoot . I made my images ( levels ) in paint , and i noticed every color's RGB . I am just trying to use some methods on the site like isTouching combined with Color and all that stuff , but i don t know how to combine them for what i want ( setLocation ( x , y )) . Please , if u can help with something , it would be great !! Thank s !
danpost danpost

2018/2/25

#
Though not specifically stated (but implied within its parameter descriptions), collision is only for Actor type objects. The class given can be used to specify a particular type of actor (or 'null' can be given to indicate any or all Actor types). You will need to get the background image of the world (presuming that is where the Color object you are checking is at), get the Color from it and compare that color to what colors are of interest.
game_salajan game_salajan

2018/2/25

#
so i should use those in this order : - getImage()
game_salajan game_salajan

2018/2/25

#
then getColor
game_salajan game_salajan

2018/2/25

#
or getColorAt :-?
game_salajan game_salajan

2018/2/25

#
Also thank you very much !
danpost danpost

2018/2/25

#
1
if (Color.BLACK.equals(actor.getImage().getColorAt(n, m)))
The above is an example. 'actor' should be replaced with the name of the referenced intersecting actor and 'm' and 'n' should be replaced with either some constants or with variable names that represent some computed values.
game_salajan game_salajan

2018/2/25

#
So , the actor should be my car and n, m coordinates where i found the specific color . But how can i put a personalized color instead of "Color.BLACK." ? it is a method which helps me to declare a found color , like asign it to a variable for example "color 1" and after simply put "Color.color1" there ?
danpost danpost

2018/2/25

#
The actor would be that which the car collides with (code in the Car class). The 'm' and 'n' are the horizontal and vertical offsets from the top-left corner of the image at which you wish to grab the color from. You can simply replace 'Color.BLACK' with 'color1', provided it is assigned the color you wish to check for.
game_salajan game_salajan

2018/2/25

#
it says that non-static method getImage() cannot be refferenced from a static content :(
danpost danpost

2018/2/25

#
game_salajan wrote...
it says that non-static method getImage() cannot be refferenced from a static content :(
Please show what code you are attempting (minimum -- the method the code is in).
game_salajan game_salajan

2018/2/25

#
this is the car code import greenfoot.*; import java.lang.String; public void act() { if ( Greenfoot.isKeyDown("up") ) { move(3); } if ( Greenfoot.isKeyDown("down") ) { move(-3); } if ( Greenfoot.isKeyDown("right") ) { turn(3); } if ( Greenfoot.isKeyDown("left") ) { turn(-3); } Color color1 = new Color(34,177,76); if (color1.equals(masinutza.getImage().getColorAt(460,385))) { setLocation(106 , 448);}} }
game_salajan game_salajan

2018/2/25

#
also it is named "masinutza"
game_salajan game_salajan

2018/2/25

#
and down after "equals" i putted "(grass.getImage() ... " grass is another class i creeated for trying to assign a color to it :/
Vercility Vercility

2018/2/25

#
You can't call getImage on a class, only on objects
There are more replies on the next page.
1
2
3
4