Post Reply  Post Thread 
PNG rendering and basic sprite animation
Author Message
Malkavian
Newbie
*


Posts: 2
Group: Registered
Joined: Mar 2010
Status: Offline
Reputation: 0
Last seen online:
11-03-2010, 07:25 PM
Post: #1
PNG rendering and basic sprite animation

Hi,
I am very new with game programing and gtge and I find the whole idea behind GTGE to be very good. I have two questions:

1) If I create a sprite and initialize it with a png image, the image borders look very bad although the image itself is ok. I attached the png I am using and a screenshot with the rendered sprite in the game window.
The code I am using is this one:

Code:
package test;

import com.golden.gamedev.Game;
import com.golden.gamedev.GameLoader;
import com.golden.gamedev.object.Sprite;
import java.awt.Dimension;
import java.awt.Graphics2D;

public class MyGame extends Game{
    public static void main(String[] args) {
        GameLoader loader = new GameLoader();
        loader.setup(new MyGame(), new Dimension(400, 300), false);
        loader.start();
    }

    Sprite hero;

    @Override
    public void initResources() {
        hero = new Sprite(getImage("media/Char1.png"), 100, 10);
    }

    @Override
    public void update(long elapsedTime) {
        hero.update(elapsedTime);
    }

    @Override
    public void render(Graphics2D g) {
        hero.render(g);
    }
}


I have tested this code in Kubuntu and Ubuntu (Karmic), with and without desktop effects enabled and I always get this bad rendered image. I created the image with Inkscape and exported it to png with Inkscape itself.

2) I want to make this sprite move, like when I type the down key, the sprite should move down and so on. I succeeded in doing this by following the tutorial. Now I want my sprite to change animation depending on the direction it is moving. I would use for this a selfmade png-spritesheet with say 12 images on it (3 for every direction). The sprite should stay still if the user doesn't type any arrow key and should animate according to the pushed key.
My question is how do I do that: animate while some key is pushed and stop animation on keyboard idle.



Attached File(s) Thumbnail(s)
       
10-03-2010 11:51 PM
Find all posts by this user Quote this message in a reply
Malkavian
Newbie
*


Posts: 2
Group: Registered
Joined: Mar 2010
Status: Offline
Reputation: 0
Last seen online:
11-03-2010, 07:25 PM
Post: #2
RE: PNG rendering and basic sprite animation

I managed to move the sprite by downloading the sourse of Warlok (which is a great game) and looking at the code. Thanks for opensourceing the code!

Does anyone have the afore mentioned problem with png Graphics? In pure swing aplications my pictures are shown with clear borders, only when I load them into a gtge Game class they have bad borders which make the game look terrible.


software is math and you can't patent math
11-03-2010 06:43 PM
Find all posts by this user Quote this message in a reply
samueleric
Newbie
*


Posts: 4
Group: Registered
Joined: Mar 2010
Status: Offline
Reputation: 0
Last seen online:
18-03-2010, 05:48 PM
Post: #3
RE: PNG rendering and basic sprite animation

It is possible to do palette-swapping, but not especially easy. If you have indexed-colour images, your best bet is probably to load the file into memory, alter the PLTE chunk, and then re-load the image. If you want to get fancy you can try making a packed binary file with PNG chunks that you mix-and-match into a well-formed PNG file within a scrap byte[] and then pass to the loading routine. You can even edit colours at runtime, but then you will also need to calculate some checksums.


m3 zero
12-03-2010 01:42 PM
Find all posts by this user Quote this message in a reply
Kenkron
Newbie
*


Posts: 27
Group: Registered
Joined: Nov 2009
Status: Offline
Reputation: 0
Last seen online:
Today, 07:07 PM
Post: #4
RE: PNG rendering and basic sprite animation

Some images use semitransparency along edges to keep them from looking jagged. It appears that your image does this.

   

      However, GTGE does not automatically support this (for performance, I think), so when the image is loaded, the border goes back to being jagged.

to load an image with transparency, use the getImages or getImage method in the Image Util class.

example:
ImageUtil.getImages(bsIO.getURL("resources/xplosion.png"), 8, 1, Transparency.TRANSLUCENT);


Why do I have a sixteen gigabyte SD card
but my flash drive can only hold 2 gigabytes?
13-03-2010 09:43 AM
Find all posts by this user Quote this message in a reply
Rian
Newbie
*


Posts: 28
Group: Registered
Joined: Aug 2010
Status: Offline
Reputation: -1
Last seen online:
04-08-2010, 08:11 AM
Post: #5
RE: PNG rendering and basic sprite animation

she got used to carrying a louis vuitton speedy with her,meless yet resolutely modern, this Croco Louis Vuitton Seasonal Collection louis vuitton neverfull handbag is ideal both for traveling.Designer Inspired Black louis vuitton evidence Sunglasses These Designer Inspired Black .Learn about the hottest pradaaccessories of the season. Visit our active Prada Forum!

04-08-2010 08:03 AM
Find all posts by this user Quote this message in a reply
thewall
Newbie
*


Posts: 8
Group: Registered
Joined: Jul 2010
Status: Offline
Reputation: 0
Last seen online:
05-09-2010, 10:00 PM
Post: #6
RE: PNG rendering and basic sprite animation

Same problem here with PNG. I tried Kenkron's solution, but without success...

04-08-2010 05:34 PM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Cut scene animation, possible? Walker 9 1,584 31-08-2010 02:01 PM
Last Post: ugggs
  Sprite sets and tile sets anywhere? St3v3 2 1,877 16-08-2010 10:06 AM
Last Post: hongchaguan
  Sprite animation Kell 2 396 30-07-2010 06:29 PM
Last Post: jwright
  Collisions with a non-rectangular sprite thewall 1 228 25-07-2010 08:03 PM
Last Post: MetroidFan2002
  Sprite rotating? asherwolf 4 386 24-06-2010 09:43 AM
Last Post: asherwolf

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: