Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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 practical question...  (Read 1119 times)
0 Members and 1 Guest are viewing this topic.
Offline scr4tchy

Junior Newbie





« Posted 2011-12-06 11:35:06 »

Hello,

First at all, thanks to this forum to being there =)

I'm not new at all in Java Programming but totally new in Java Game Dev.
I just try to create a simple game with a Yoshi & a world with the libgdx lib (jogl)

But I've a problem.

So I've some sprites in a texture file to make an animation.
For ex, I use 64*64 sprites in two 512*64 textures for the walk animation. In each 64*64, I've a sprite with Yoshi in a certain position. Each time the game advance, we choose the next sprite... (as described into the libgdx game). I've a texture to Walk from left to right and a texture to Walk from right to left. Why ? Because I didn't centered the sprites but aligned them at the bot-right position. So I can't flip them. I think it's not a good solution.. but it works.

But my problem is that I want the Yoshi to "stuck out his tongue" (I call this "Slurp") to right & to left. For the left slurp, it's ok because the sprite is aligned at the bot-right corner. But to the right... It cause the Yoshi to go back.
I thought about putting the Yoshi in the middle of the sprite but Yoshi+tongue take more than 32pix.. That I can't get him in the middle to be able to use symmetry or...

I don't know if I can be understood.. Sorry ^^

And I don't really want to expand all my sprites to 128*128 ? Its a bit dirty no? Please throw a light on that ^^

PS: I wanted to put an offset on the drawing method but Jogl have strange axis/scale.. Failed to find how to put a PixelOffset.

=> imageshack.us/photo/my-images/577/yoshislurpleft.png
=> imageshack.us/photo/my-images/834/yoshislurpright.png

Here is my class if you want to but I think you won't need it.. And it's a bit unclean cause it's tests : pastebin.com/dHwhGha6
Thanks !
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #1 - Posted 2011-12-06 17:00:26 »

I would expand all your sprites to be large enough for all animations, then use libgdx's TexturePacker to pack the sprites with whitespace stripping. This way the sprites are packed to take up as little space as possible, but will be drawn as if they still had their whitespace. Flipping the whitespace stripped images is supported.

Offline scr4tchy

Junior Newbie





« Reply #2 - Posted 2011-12-06 17:21:27 »

Hello,

Thanks for your answer.
You mean, I should separate all my yoshi sprites into single files (ie yoshi_walk_1 yoshi_walk_2 etc....).
Then all this files to a folder (yoshi/) and use a texture packer?

That what I did manually but thanks, I now know that we can do that dynamically.

I'll try that in few hours.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline scr4tchy

Junior Newbie





« Reply #3 - Posted 2011-12-06 20:27:06 »

Hello,

Thanks. I used TexturePacker and adapted my code.
I divided all my sprites to single files (yoshi-slurp_1, yoshi-slurp-2... etc) then used TexturePacker.

I define only one the images (ie, slurp to the right img) and use .flip to get it to the left. flip makes a symmetry.. Since I've centered the foots of my yoshi, that shouldn't cause any problems. That doesn't seems to cause problem with walk action but with tongue stuck action..

When WhitespaceStrip is False, That's works, I can get my yoshi walks.. stucks his tongue in both direction.
When WhitespaceStrip is True, That doesn't work. My yoshi walks in both direction but he can't stuck his tongue in a direction correctly..

I don't know why...
Maybe because AtlasRegion store the whitespace informations but don't apply it then the cast to TextureRegion can't be done..
But Animation takes TextureRegion constructor parameter only.

Packed stripped: http://imageshack.us/photo/my-images/849/game1copie.png/
Packed nonstripped: http://imageshack.us/photo/my-images/836/game1le.png/
Source: http://pastebin.com/00CgtrC6

I can provide you the entire sources if needed..

Thanks!
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #4 - Posted 2011-12-06 20:46:19 »

Maybe because AtlasRegion store the whitespace informations but don't apply it then the cast to TextureRegion can't be done..
But Animation takes TextureRegion constructor parameter only.
That is correct. You must use sprites that you get from TextureAtlas to draw your yoshi. The Sprite you get will be an AtlasSprite, which handles drawing the whitespace stripped image. Animation is only a few lines of code, copy and paste it and adapt to use Sprite. Most games need their own Animation class anyway, so not much time has been spent on a fancy one for libgdx.

Offline scr4tchy

Junior Newbie





« Reply #5 - Posted 2011-12-06 20:58:58 »

Thanks for all Grin

See you !
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.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36

Riven (45 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

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

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

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
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!