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
danpost danpost

2018/2/25

#
game_salajan wrote...
also it is named "masinutza"
Is that a class name? and where is your collision code 'isTouching' or whatever?
game_salajan game_salajan

2018/2/25

#
oh :( Thank you !
game_salajan game_salajan

2018/2/25

#
uhm , i didn't knew what to put in , i just copied your example and tried to make it :P
game_salajan game_salajan

2018/2/25

#
danpost wrote...
game_salajan wrote...
also it is named "masinutza"
Is that a class name? and where is your collision code 'isTouching' or whatever?
like i copied that one with if , and tried to replace that ones u said , and after that i placed a " setLocation " in if :/
danpost danpost

2018/2/25

#
game_salajan wrote...
uhm , i didn't knew what to put in , i just copied your example and tried to make it :P
You need some collision code to get a reference to the actor object. Something like:
Actor actor = getOneIntersectingObject(masinutza.class);
game_salajan game_salajan

2018/2/25

#
danpost wrote...
game_salajan wrote...
also it is named "masinutza"
Is that a class name? and where is your collision code 'isTouching' or whatever?
i put it ( the car "masinutza" ) as an actor :)
danpost danpost

2018/2/25

#
Wait, masinutza is the class of the car -- not the class of the intersecting object? Also, before getting the image of the 'actor', you must ensure that 'actor' has an object (that it is not 'null').
danpost danpost

2018/2/25

#
Oh. that is what you meant, by
game_salajan wrote...
also it is named "masinutza"
The collision check needs the name of the class of the object the car might intersect.
game_salajan game_salajan

2018/2/25

#
So let me explain it clearly :))) sory ... I have a map as world , created in paint with grass , road and finish being simple colors . I have a car "masinutza" , as an actor and i have also created a class named " grass " for studying the collision as you help me :) , so i just attached the car and a bit more objects to my map , and now i want to make this thing happen ( the one with overcoming the road )
game_salajan game_salajan

2018/2/25

#
I presume that i need to to some code in the " grass " ( the object the car might intersect ) too , no ?
danpost danpost

2018/2/25

#
game_salajan wrote...
So let me explain it clearly
Well, that was semi-clear. If you are checking for "road" color, which is on the background image of the world, then there is no 'actor' to get. Just get the world background and the color at which the car is located to compare with road color:
if (color1.equals(getWorld().getBackground().getColorAt(getX(), getY())))
game_salajan game_salajan

2018/2/25

#
danpost wrote...
game_salajan wrote...
So let me explain it clearly
Well, that was semi-clear. If you are checking for "road" color, which is on the background image of the world, then there is no 'actor' to get. Just get the world background and the color at which the car is located to compare with road color:
if (color1.equals(getWorld().getBackground().getColorAt(getX(), getY())))
color 1 is the green color ( of the grass ) , but this one with "equals" doesen't means that i asociate the road color with the grass color ?
danpost danpost

2018/2/25

#
You can use that line with 'color1' set to any color (color of road or grass, doesn't matter).
game_salajan game_salajan

2018/2/25

#
oh ok , Thannk you !!
game_salajan game_salajan

2018/2/25

#
Color color1 = new Color(239,228,176); if (color1.equals(getWorld().getBackground().getColorAt(460, 385))) { setLocation(106,448); } so this should work ? ( Car code ) my start point is x 106 and y 448 color 1 is road color and that one 460,385 is the green color ( grass )
There are more replies on the next page.
1
2
3
4