Slick Forums

Discuss the Slick 2D Library
It is currently Mon Aug 19, 2019 11:13 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sun Jul 31, 2011 1:08 pm 
Offline

Joined: Sun Jul 31, 2011 12:49 pm
Posts: 3
Hello all!
This is my first post to the forum :)
I'm new to Slick. my question just like below:
http://iphonedevelopertips.com/cocoa/how-to-mask-an-image.html

I mean, how can I use two JPG images, without alpha. how to do XOR operate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2011 2:41 am 
Offline
Oldbie
User avatar

Joined: Thu Jan 13, 2011 4:42 pm
Posts: 349
I would also love to know how to do this


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2011 3:13 am 
Offline
Regular
User avatar

Joined: Wed Apr 27, 2011 3:29 pm
Posts: 197
Location: United State of California
I'm a little short on time now so I'm just going to quote myself here and hopefully you can make sense of it:

raeleus wrote:
I've been having the same slow down problem with getGraphics() like the original poster. I've attempted Tommy's suggestion with using copyArea() from the graphics of a new image. My results seemed strange with the images being translated, invisible, or of something else I've drawn that's unrelated to what I just did. It seems copyArea() doesn't play nice when it's used from a graphics created from an image. Instead, I used the default graphics object... and it works for some reason.

The following is a basic example of this. I have a jet image and I want a procedurally generated scrap blown off of it when its destroyed. Using the following images:
Image Image
and this basic game:
Code:
import com.ray3k.game.GameController;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

public class CopyAreaTest extends GameController {

    public static void main(String[] args) {
        startGameWindowed(new CopyAreaTest(), 250, 250);
    }

    Image baseImage;
    Image outputImage;
    Image cutoutImage;
   
    @Override
    public void init(GameContainer container) throws SlickException {
        super.init(container);
        container.setVSync(false);
        container.setShowFPS(true);
        baseImage = new Image("images/jet.png");
        cutoutImage = new Image("images/cutout.png");
        outputImage = new Image(cutoutImage.getWidth(), cutoutImage.getHeight());
    }
   
    @Override
    public void update(GameContainer container, int delta) throws SlickException {
        super.update(container, delta);

        //get default Graphics and generate the image
        Graphics g = container.getGraphics();
        g.clear();
        g.drawImage(cutoutImage, 0.0f, 0.0f);
        g.setDrawMode(Graphics.MODE_COLOR_MULTIPLY);
        g.drawImage(baseImage, 0.0f, 0.0f);

        //save the result to the outputImage
        g.copyArea(outputImage, 0, 0);

        //reset the graphics
        g.setDrawMode(Graphics.MODE_NORMAL);
        g.clear();
    }

    @Override
    public void render(GameContainer container, Graphics g) throws SlickException {
        super.render(container, g);
       
        g.drawImage(baseImage, 0.0f, 0.0f);
        g.drawImage(outputImage, 0.0f, baseImage.getHeight());
    }
}


I get this with no side-effects:
Image

Is there anything wrong with using container.getGraphics() ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2011 7:30 am 
Offline

Joined: Sun Jul 31, 2011 12:49 pm
Posts: 3
thx, but your mask image is a PNG, I think the image have the alpha,
I should try it with a jpg mask image, I will have a go and get back to you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2011 7:49 am 
Offline
Regular
User avatar

Joined: Wed Apr 27, 2011 3:29 pm
Posts: 197
Location: United State of California
That link you posted also used png's. The original image can be a jpg or whatever kind of source image you want. The image that will mask or cutout this image needs to have alpha so you can define the edges.

If that's not what you're looking for, I suggest looking up alphamap blending mode on this forum. There are plenty of topics on this subject as it is sometimes used for lighting effects.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2011 2:28 pm 
Offline

Joined: Sun Jul 31, 2011 12:49 pm
Posts: 3
thanks for your help, thank you all.
I'll looking up another way. :roll:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group