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

2013/6/1

Transparency

1
2
3
4
Robert2.0 Robert2.0

2013/6/2

#
danpost wrote...
I missed the 'getImage()' call in the last statement. Refer to the break-down above.
Thanks for the help, but this code didn't work. My player is still walking on the transparent platforms.
danpost danpost

2013/6/2

#
I tested it and had no problems. I did add two statements to the 'getColorAtFoot' method (but I did qualify that the foot of the player had to be on the image for the method to work). Adding the following right before the final 'return' statement will account for those situations:
if (xOff < 0 ||
    yOff < 0 ||
    xOff >= actor.getImage().getWidth())
        return 0;
if (yOff >= actor.getImage().getHeight()) return 255;
Robert2.0 Robert2.0

2013/6/2

#
danpost wrote...
I tested it and had no problems. I did add two statements to the 'getColorAtFoot' method (but I did qualify that the foot of the player had to be on the image for the method to work). Adding the following right before the final 'return' statement will account for those situations:
if (xOff < 0 ||
    yOff < 0 ||
    xOff >= actor.getImage().getWidth())
        return 0;
if (yOff >= actor.getImage().getHeight()) return 255;
it seems not allow me to go though the transparent platform. Was I suppose to put all the code in the player class. Also if possible could you email me or post on greenfoot a small scenario going through the transparent platform
danpost danpost

2013/6/2

#
Yes, it all goes in the player class. I can upload one for you to download and look at, if you wish. Let me know if that is ok; and then, if so, when you do get it downloaded, let me know you got it (so I can delete it back off the site.
Robert2.0 Robert2.0

2013/6/3

#
danpost wrote...
Yes, it all goes in the player class. I can upload one for you to download and look at, if you wish. Let me know if that is ok; and then, if so, when you do get it downloaded, let me know you got it (so I can delete it back off the site.
I can download it and then you can delete it off. Post the link.
Robert2.0 Robert2.0

2013/6/3

#
danpost wrote...
.
I download it, you can delete it
danpost danpost

2013/6/3

#
Ok, done.
Robert2.0 Robert2.0

2013/6/3

#
danpost wrote...
Ok, done.
I have another question. I editing the sample test. Now the transparency won't work. I add a some methods relating to my game. I was wonder if you could look at it and see how to fix the transparency issue. How can I send you the scenario without anyone seeing.
danpost danpost

2013/6/3

#
As long as you do not alter the 'getAlphaAtFoot' method, you should be able to get it working. The last two lines in the act method of the player class are what keeps the proper location of the player when intersecting the platform.
Solringolt Solringolt

2013/6/3

#
I used what you explain here, working nice, I'm using it for a bullet hitting an ennemy but sometimes it doesn't work properly, how can I adjust the code to make it more precise in my case?
danpost danpost

2013/6/3

#
What do you mean by more precise? show the code you need worked on.
Solringolt Solringolt

2013/6/3

#
public void act() 
    {
        setImage(imageOfShot);
        setRotation(shotDirection);
        if (!WorldOption.menuDisplayed)move(10);
        Enemy enemy = (Enemy)getOneIntersectingObject(Enemy.class);
 
        Boss1Part1 boss1Part1 = (Boss1Part1)getOneIntersectingObject(Boss1Part1.class);
        Boss1Part2 boss1Part2 = (Boss1Part2)getOneIntersectingObject(Boss1Part2.class);
        Boss1Part3 boss1Part3 = (Boss1Part3)getOneIntersectingObject(Boss1Part3.class);
        Boss1Part4 boss1Part4 = (Boss1Part4)getOneIntersectingObject(Boss1Part4.class);
        Boss1Part5 boss1Part5 = (Boss1Part5)getOneIntersectingObject(Boss1Part5.class);
        
        if (enemy != null)
        {
            enemy.hit(shotStrengh);
            getWorld().removeObject(this);
        }
        else if (boss1Part1 != null)
        {
            if (getAlphaAtFoot(boss1Part1) > 200) 
            {
                boss1Part1.hit(shotStrengh);
                getWorld().removeObject(this);
            }
        }
        else if (boss1Part2 != null)
        {
            if (getAlphaAtFoot(boss1Part2) > 200) 
            {
                boss1Part2.hit(shotStrengh);
                getWorld().removeObject(this);
            }
        }
        else if (boss1Part3 != null)
        {
            if (getAlphaAtFoot(boss1Part3) > 200) 
            {
                boss1Part3.hit(shotStrengh);
                getWorld().removeObject(this);
            }
        }
        else if (boss1Part4 != null)
        {
            if (getAlphaAtFoot(boss1Part4) > 200) 
            {
                boss1Part4.hit(shotStrengh);
                getWorld().removeObject(this);
            }
        }
        else if (boss1Part5 != null)
        {
            if (getAlphaAtFoot(boss1Part5) > 200) 
            {
                boss1Part5.hit(shotStrengh);
                getWorld().removeObject(this);
            }
        }
        else if (getX() >= 1190 || getY() >= 856 || getY() <= 0 )
        {
            getWorld().removeObject(this);
        } 
    }
    private int getAlphaAtFoot(Actor actor) // actor is the platform in your case  
    {  
        int playerX = getX(); // the x at center of player  
        int playerY = getY()+getImage().getHeight()/2; // the y at foot of player  
        int xDiff = actor.getX()-playerX; // the difference along the x-axis  
        int yDiff = actor.getY()-playerY; // and y-axis of the two actors  
      
        int xOff = actor.getImage().getWidth()/2-xDiff; // the pixel's x  
        int yOff = actor.getImage().getHeight()/2-yDiff; // and y offsets in the image  
        
        if (xOff < 0 ||  
        yOff < 0 ||  
        xOff >= actor.getImage().getWidth())  
        return 0;  
        if (yOff >= actor.getImage().getHeight()) return 255;  

        return actor.getImage().getColorAt(xOff, yOff).getAlpha(); // return the alpha of that pixel's color  
    } 
that is the code and sometimes my bullet go thru the object without affecting it (specially when it's thin)
danpost danpost

2013/6/3

#
What does your Enemy class extend? and what do your Boss1Part# classes extend?
Solringolt Solringolt

2013/6/3

#
My ennemy class extends actions, actions extends actor. All the boss part extend boss and boss extends action
danpost danpost

2013/6/3

#
Do you have other classes besides enemy and boss part that extend actions? NVM, you probably have your player extending actions also.
There are more replies on the next page.
1
2
3
4