thank you bourne, but I don't care, when he uploads one of my demo-scenarios without the source code. :)
I already got an email from the greenfoot-team. :)
I've been trying to use the touch method, but it will not allow me and says
"method touch in class Block cannot be applied to given types;
required: java.lang.class
found: greefoot.Actor"
All I did was copy this code:
public boolean touch(Class clss)
{
List<Actor> list =
getWorld().getObjects(clss),
list2 = new ArrayList();
for(Actor A : list)
if(intersects(A)&&touch(A))
return true;
return false;
}
And I got this error that doesn't seem to be a problem for your program. Do you know why this could be happening?
@hoyaduyin, there are two 'touch' methods in the project. The one listed above iterates through the actors of the given class. If any of these actors are found to intersect this object, the other 'touch' method is called to check for non-transparent collision between the two objects.
@hoyaduyin, I cannot be sure what the first part (deciding which image should be 'a_big' or 'a_small') is for or even if it matters. However, the rest is pretty straight-forward. Copy the images only a image base large enough to rotate them without losing any of the image, rotating them to the rotation of the actor the image belongs to and comparing the pixels that overlay each other to see if any set compared are both non-transparent.
@hoyaduyin, it is a bit hard to explain. Basically, the image itself needs to be rotated to the rotation of the actor to determine where each pixel of the image resides in the world. Only those parts of the image that are inside the largest circle you can draw within the frame of the image are guaranteed to remain within the frame of the image when rotating it. Therefore, the image needs to be drawn onto a larger frame before rotating it to avoid loss of image. That larger frame is what I called the 'image base'.
Hey Dan, so im a highschool student in pennsylvania and im taking this intro to programming class. The teacher teaches us the basics but other than that, we are on our own to problem solve and what not. I go on this website all the time for answers, and all the time i see your answers to peoples questions! and you didnt even go to college for this, im so impressed haha if it means anything. i made this account just to ask you for help personally. if you could email me at cruzsam00000@gmail.com id appreciate it. or if theres a private message thing on here, i dont know
I don't really understand the touch method but I like it anyway (I knew that I liked this scenario already but for some reason I hadn't clicked "Do I like this").
(I didn't comment until now is because the last comment on this scenario is about 15 months ago so I supposed that it was "abandoned" but now I see that Busch2207 is a little bit back so I can comment on his scenarios and say that it seems that his specialty is dealing with colors and pixels.)
Well, in the end it is not so complicated. First I check, if the rectangles of the actors collide at all. Then I create an image, wich I rotate like the two original images are rotated. Then I check the overlapping parts of the images for pixels that are colliding.
I changed the three getWorld().getObjects(... in your methods to getIntersectingObjects(... since that was the only way I can use your methods for collision checking between two actors of the same class. It works just fine, since there is no reason why it shouldn't but I'm just wondering why you did what you did? Maybe there is a reason that I should use getObjects as opposed to getIntersectingObjects.
I forgot to mention (I posted the other comments) that I changed the touch(Class clss) method to just be
getOneTouchedObject(clss) != null
as all the code for it instead of having all the code there twice (not exactly the same code but does the same thing).
Well, I used 'getWorld().getObjects()', because getIntersectingObjects() also iterates over all Objects in the World-class, checks whether they intersect and then returns the list. So there's no affect to the running-time. In the 'getOneTouchedObject'-method it could also save some time, if one of the first objects in the list touches it... So the 'intersect'-method don't have to be called on all actors...
A new version of this scenario was uploaded on 2017-05-09 19:48:47 UTC
Latest Greenfoot-Version...
But with using getWorld().getObjects(), I ran into problems when I tried to check if one instance of a class is touching a different instance of the same class, so I changed it (and if you leave it alone, other people can/will have the same problem).
I got the idea of changing the touch method, from the greenfoot.Actor class which did that.
"Well, I used 'getWorld().getObjects()', because getIntersectingObjects() also iterates over all Objects in the World-class, checks whether they intersect and then returns the list. So there's no affect to the running-time" - this is not correct. The collision checking in Greenfoot is sophisticated and maintains a dynamic space partition tree to make intersection checks very fast.
2013/11/9
2013/11/9
2013/12/3
2013/12/11
2013/12/11
2015/5/4
2015/11/24
2015/11/24
2015/11/24
2015/11/24
2015/11/25
2015/11/25
2015/12/12
2015/12/12
2015/12/12
2017/3/2
2017/3/4
2017/3/5
2017/3/17
2017/5/3
2017/5/9
2017/5/10
2017/5/10
2017/5/10
2017/5/11
2017/7/29
2017/8/4
2020/2/5