Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (116)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Sprite class  (Read 6059 times)
0 Members and 1 Guest are viewing this topic.
Offline Captain Awesome

Junior Member


Medals: 2


Hi


« Posted 2010-11-24 21:03:18 »

I'm sure there are already tons of sprite-classes out there. This is however my own interpretation of a Sprite-class.
It has support for animations, pixel-perfect collissions and some other random stuff Wink

The class can be found here: http://pastebin.com/mTGx37EJ
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #1 - Posted 2010-11-24 22:07:05 »

I have to say, this is a pretty badass and fully-featured sprite class. Looks really good. I was going to harp on your pixel-perfect collision check but I was mistaken and it's actually very good (I didn't see it first that width and height were being set from the smallest of the two sprites).

Looks tried and true. What about the various classes this references, like a Logger and PixelGrabber?

See my work:
OTC Software
Online Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2010-11-24 22:28:12 »

What about the various classes this references, like a Logger and PixelGrabber?

1  
2  
import java.awt.image.PixelGrabber;
import java.util.logging.Logger;

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Captain Awesome

Junior Member


Medals: 2


Hi


« Reply #3 - Posted 2010-11-25 14:03:33 »

I have to say, this is a pretty badass and fully-featured sprite class. Looks really good. I was going to harp on your pixel-perfect collision check but I was mistaken and it's actually very good (I didn't see it first that width and height were being set from the smallest of the two sprites).

Looks tried and true. What about the various classes this references, like a Logger and PixelGrabber?

Thanks. I know that width and height stuff in that method may be a bit unclear, maybe I've should have cleaned it up a bit before releasing it?  Wink
Also, Logger and PixelGrabber (as well as all other imported classes) are part of the JDK (as Riven pointed out) Smiley
Offline gimbal

JGO Knight


Medals: 25



« Reply #4 - Posted 2010-11-25 16:38:30 »

perhaps an idea for a small optimization; in my 'pixel perfect collision detection' when I create a sprite or bob frame I create an array of booleans by inspecting the pixels. I do that only once at game startup. Then when doing the collision detections, I simply check the pre-generated boolean arrays if two overlapping pixels both hold the value true. Call it a collision mask if you will. These arrays only use up bytes, it won't even make a small dent on the memory footprint of the game.

Of course that does require a little calculating to figure out which regions of the arrays are actually overlapping, but you are doing something similar when you are copying the pixels over to the arrays you use to do the comparison.
Offline Captain Awesome

Junior Member


Medals: 2


Hi


« Reply #5 - Posted 2010-11-25 18:25:30 »

perhaps an idea for a small optimization; in my 'pixel perfect collision detection' when I create a sprite or bob frame I create an array of booleans by inspecting the pixels. I do that only once at game startup. Then when doing the collision detections, I simply check the pre-generated boolean arrays if two overlapping pixels both hold the value true. Call it a collision mask if you will. These arrays only use up bytes, it won't even make a small dent on the memory footprint of the game.

Of course that does require a little calculating to figure out which regions of the arrays are actually overlapping, but you are doing something similar when you are copying the pixels over to the arrays you use to do the comparison.

Hey, that's not a bad idea. Going to build a stress test and check which method is best, thanks Smiley
Offline pjt33
« Reply #6 - Posted 2010-11-25 20:17:43 »

You can optimise that further by using arrays of wider types and bitwise and - just need to be very careful with the boundaries.
Offline Takidoso

Innocent Bystander





« Reply #7 - Posted 2012-02-24 15:31:16 »

Hi Captain (my Captain  Cheesy) Awsome
I just came across your Sprite class and I thought to myself to give it a try.
I actually don't quite understand all your public methods, though. Do I get it right that an Image is used having tyles of the sprite animation as content?
Are there some nice coding samples how to use your class?

Best wishes

Takidoso
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (30 views)
2014-09-21 02:42:18

BurntPizza (20 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (28 views)
2014-09-20 20:14:06

BurntPizza (32 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!