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

2025/1/30

Uneaven hitboxes (very desperate)

1
2
Jder2te Jder2te

2025/1/30

#
Im currently trying to create a 2d shooter. I have drawn my own obstacles with pixel studios and adjusted the image size in greenfoot. The problem is that their hitboxes seem to be nothing like the images. Nether in size nor in position. Is there any way of visualizing and ajusting them ?
Bennylit Bennylit

2025/1/30

#
You can try visualizing them by adding this:
GreenfootImage myImage = new GreenfootImage(getImage());
myImage.setColor(new Color(0,0,255,100));
myImage.fill();
setImage(myImage());
to their constructor, if they start out with the image upon creation. This code will color their entire image with a semitransparent blue, so you can visually see their entire image. If you're using PNG files with transparent pixels, collision will be a little jank because isTouching and other methods for detecting touching objects still registers as true even if it's touching an invisible pixel. If that's the problem, let me know, because there are solutions (albeit complicated) to that. Otherwise, it might be a problem with how your collision method works. But first, give the image highlight code a try to see if it helps you better visualize their entire image size.
Jder2te Jder2te

2025/1/30

#
Ok, im sorry, im just getting errors :/ Do i have to change parts of your code to fit it to the rest of the programm ? Like image names or something?
Bennylit Bennylit

2025/1/30

#
It's alright, no need to apologize. I accidentally gave you faulty code, please forgive me. I think this should be correct.
GreenfootImage myImage = new GreenfootImage(getImage());
myImage.setColor(new Color(0,0,255,100));
myImage.fill();
setImage(myImage);
I accidentally put myImage() instead of myImage, which probably made the compiler tell you "That's not a valid method.". Please forgive me, and try that code instead.
Jder2te Jder2te

2025/1/30

#
You definitely dont need to apologize. Im very thankful for you even trying to help me as i spend the last 8 hours trying to make the kollision work correctly... But im still getting errors in line 2, 3 and 4 of your code. Chances are that i made some silly mistake, but i dont realy know what it is I copyed exacly your code right after the the class opens up with "{"
Bennylit Bennylit

2025/1/30

#
Here, could you show me the entire code of your class? Maybe I could figure out how to correctly show the image.
Jder2te Jder2te

2025/1/30

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)


public class Wand1 extends Wand
{
    GreenfootImage myImage = new GreenfootImage(getImage());
    myImage.setColor(new Color(0,0,225,100));
    myImage.fill();
    setImage(myImage);
    
    
    public void act()
    {
        getImage().scale(50, 50);
        
    }
}
Jder2te Jder2te

2025/1/30

#
The Image is named W1.png
Bennylit Bennylit

2025/1/30

#
Try this:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
 
public class Wand1 extends Wand
{
    public Wand1() {
GreenfootImage myImage = new GreenfootImage(getImage());
    myImage.setColor(new Color(0,0,225,100));
    myImage.fill();
    setImage(myImage);
}
     
     
    public void act()
    {
        getImage().scale(50, 50);
         
    }
}
Jder2te Jder2te

2025/1/30

#
That kinda works. It draws a rectangel arround the obsacles but my charrakter is able to enter the painted space. The hinbox seems to be smaller.
Bennylit Bennylit

2025/1/30

#
Well the code should highlight the entire area of Wand1, which it sounds like it is doing(?). If there's still problems with hitboxes or collisions, you might consideruploading the entire scenario , or a video or photo to better show the problem.
danpost danpost

2025/1/30

#
Please note that the collision checking methods itTouching, removeTouching, getIntersectingObjects, getOneIntersectingObject and intersects use the entire rectangle of the image as the hit box. You can use these to generalize a possible hit, but more will be needed for more complex collision checking. Either a combination of these with possibly others, like getObjectsInRange. If the objects is quite complex in shape (where it is no where near anything that can be covered with these methods), you may need break the actor down into parts (also actors) where you can check for collision with the parts instead of the whole.
Bennylit Bennylit

2025/1/30

#
If you want a solution that does go based off pixels, I can offer the Devil on your shoulder solution in the form of this greenfoot actor pixel perfect isTouching method. Though, I imagine it wouldn’t be recommended by any actual professional due to the fact that has the possibility to slow your computer down significantly.
Jder2te Jder2te

2025/1/30

#
I broke some of them up into rectangles but I have some with an L like shape i will upload a picture of the scenario in a sec
Jder2te Jder2te

2025/1/30

#
i uploaded the whole scenario instead
There are more replies on the next page.
1
2