Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 10th, 2006, 6:35 AM   #1
Flint50
Newbie
 
Join Date: Apr 2006
Posts: 1
Rep Power: 0 Flint50 is on a distinguished road
Blank images from CreateImages with animation cells

I'm working on a casual game with a few people which requires animations of sprites. The problem I am having is with cutting up the images. Some images are cut, while others are not, and it's seemingly random.

The demo can be found here which shows the problem: http://www.stirkenheimer.com/panicst...demo/Test.html .

Each image is loaded with a ImageLoader class, which opens the picture, adds it to a MediaTracker, and then displays the image to the applet. When any animated object is created, I use an ImageStrip class to cut it up. This will also display the image if it worked.

Sometimes, it will cut the images and sometiems not. I've found from the console debugging that it does find the size of the image, but for some reason creates a blank image after cropping out the cells. Here's the code i use to cut the images:

    public void createCells(Applet app, Image img, int cellWidth, int cellHeight,
            int extentTopX, int extentTopY, int extentBottomX, int extentBottomY)
    {
        int FramesAcross = ((img.getWidth(null) - extentTopX - (img.getWidth(null) - extentBottomX)) / cellWidth);
        int FramesHigh = ((img.getHeight(null) - extentTopY - (img.getHeight(null) - extentBottomY)) / cellHeight);
        
        System.out.println(FramesAcross + "  " + FramesHigh);

        if(frames != null)
        {
            frames.clear();
            numFrames = 0;
        }
        frames = new LinkedList();

        try
        {
            for(int i = 0; i < FramesAcross; i++)
            {
                for(int j = 0; j < FramesHigh; j++)
                {
                    Image cell = app.createImage(new FilteredImageSource(img.getSource(),
                            new CropImageFilter((i * cellWidth) + extentTopX, (j * cellHeight) + extentTopY,
                            cellWidth , cellHeight)));

                    // Wait for image
                    MediaTracker mt = new MediaTracker(app);
                    mt.addImage(cell, 0);
                    try {
                        do {
                            mt.waitForAll();
                        } while (!mt.checkAll());
                    } catch (InterruptedException e) { System.out.println("Image is not loaded."); }
                    
                    app.getGraphics().drawImage(cell, 0, 0, app);
                    
                    // Return
                    addFrame(cell);
                }
            }
        }
        catch (Exception e){}
    }

What I'm looking for is any suggestions as to what the problem may be, or if there is a better way to cut up the images to store as seperate pictures to quickly animate with. Thanks.
Flint50 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:00 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC