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

2016/10/19

isTouching being Private

1
2
Psychpsyo Psychpsyo

2016/10/19

#
So I wanted to check if another actor is touching something. But it turned out that I can't use isTouching of other actors cause it's private. Then I wrote this method in my second actor:
public boolean touching(Class C1) {
    return isTouching(C1);
}
But when I call it in my first actor greenfoot seems to check if the first actor touches something. Is there any way around this or am I doing something wrong?
Super_Hippo Super_Hippo

2016/10/19

#
As far as I know, it should work. Could you show the code where the other actor accesses this method?
Psychpsyo Psychpsyo

2016/10/19

#
This is what I have in the other class:
Hitbox H1 = new Hitbox(this);
getWorld().addObject(H1, getX(), getY());

if(H1.touching(Hurting.class)) {

}
(Hitbox is the second Actor)
danpost danpost

2016/10/19

#
It might appear to be checking for intersecting the first actor; but, you are placing the second actor at the same location where the first actor is. What is the size differential between the image of the first and second actors?
Super_Hippo Super_Hippo

2016/10/19

#
You have something in line 5, right? Are you sure that it checks if the first actor touches the 'Hurting'? Maybe you could try to give the hitbox an image and create it at a different position to test it.
Psychpsyo Psychpsyo

2016/10/19

#
I tested a bit more now. The code itself seems to work. What doesn't seem to work is changing the size of the Hitbox because greenfoot changes the size visually but still thinks it is higher than it should be.
danpost danpost

2016/10/19

#
Psychpsyo wrote...
I tested a bit more now. The code itself seems to work. What doesn't seem to work is changing the size of the Hitbox because greenfoot changes the size visually but still thinks it is higher than it should be.
What code is changing the image size of the hitbox? Please show.
Psychpsyo Psychpsyo

2016/10/19

#
danpost wrote...
Psychpsyo wrote...
I tested a bit more now. The code itself seems to work. What doesn't seem to work is changing the size of the Hitbox because greenfoot changes the size visually but still thinks it is higher than it should be.
What code is changing the image size of the hitbox? Please show.
The size of the hitbox is changed by it's own code in the act method, according to a variable in the first Actor:
int[] sizeX = {14, 16, 14, 16};
int[] sizeY = {31, 30, 30, 16};

public KegyHitbox(Actor1 K) {
        K1 = K;
    }

public void tick() //gets called by the act method every 0.01seconds or so 
    {
        setLocation(K1.getX(), K1.getY() + K1.getImage().getHeight() / 2 - getImage().getHeight() / 2);
        getImage().scale(sizeX[K1.getAnim()] * 2, sizeY[K1.getAnim()] * 2);
    }    
danpost danpost

2016/10/19

#
I am not sure why you are adding and subtracting those values to and from the y-location coordinate at line 10; and I cannot see how the size of the current image of the hitbox would effect its new location. Please explain what you were trying to accomplish by introducing those changes in its location.
Psychpsyo Psychpsyo

2016/10/19

#
danpost wrote...
I am not sure why you are adding and subtracting those values to and from the y-location coordinate at line 10; and I cannot see how the size of the current image of the hitbox would effect its new location. Please explain what you were trying to accomplish by introducing those changes in its location.
The code sets the hitbox to the bottom of the sprite of actor1. So it isn't always in the middle.
danpost danpost

2016/10/20

#
Psychpsyo wrote...
The code sets the hitbox to the bottom of the sprite of actor1. So it isn't always in the middle.
What is wrong with just using the current image of actor1 as the hitbox?
Psychpsyo Psychpsyo

2016/10/20

#
danpost wrote...
Psychpsyo wrote...
The code sets the hitbox to the bottom of the sprite of actor1. So it isn't always in the middle.
What is wrong with just using the current image of actor1 as the hitbox?
It's too big sometimes.
danpost danpost

2016/10/20

#
Psychpsyo wrote...
It's too big sometimes.
Do you mean one or more of the images has excess transparency around the character? or what?
Psychpsyo Psychpsyo

2016/10/20

#
danpost wrote...
Psychpsyo wrote...
It's too big sometimes.
Do you mean one or more of the images has excess transparency around the character? or what?
Yes. And sometimes the hitbox has to be smaller than the character too. So just removing the transparecy is not an option.
danpost danpost

2016/10/20

#
Psychpsyo wrote...
sometimes the hitbox has to be smaller than the character too. So just removing the transparecy is not an option.
What about using a different collision method, like 'getObjectsInRange', for example?
There are more replies on the next page.
1
2