RSS

Forum

January 4th, 2010 • Uncategorized
You must be logged in to post Login Register

Search Forums:


 






Creating a Sprite or MasterSprite from a TImage without a file?

No Tags
UserPost

9:18 pm
March 2, 2010


thaaks

Germany

Member

posts 97

I create TImages within my code for space ships for example.
Now I want to create a Sprite using this TImage without writing the image to a file first.
Additionally I want to set xhandle and yhandle and blendmode in the source code without writing a sprite.txt file for a sprite file that doesn't even exist Wink

So I miss some creation way for a Sprite with just a TImage.
And I miss the setters for xhandle, yhandle and blendmode.

9:43 pm
March 2, 2010


matibee

Admin

posts 104

What are you doing? Procedurally generated content or splitting a larger TImage into smaller sprites? Or something else?

I'm looking over the source and I can't see an elegant way to handle this. The frameworks task is to load MasterSprites for you and you don't "create" Sprites directly, you merely create instances of a MasterSprite.

If your sprites don't fit in that system then perhaps you should a) handle them yourself (as I am for my tile-based game), or b) make them work in a way the framework expects.

Tell me more about what you want to do.

9:57 pm
March 2, 2010


thaaks

Germany

Member

posts 97

I'm procedurally generating content (nearly all the involved graphical elements are generated within the code).

I have no problem handling this stuff on my own - I just thought it might be an enhancement of your Sprite code.

I think the setters for xhandle, yhandle and blendmode should be added anyway.

10:20 pm
March 2, 2010


matibee

Admin

posts 104

I'll look to see if procedural content can be managed gracefully by the current MasterSprite/Sprite/SpriteList system. I assume you will want instances of these sprites too? So it would be good for the framework to handle them.

I think the setters for xhandle, yhandle and blendmode should be added anyway.

I'm not convinced. I think hard-coded manipulation of these values goes against the "data driven" paradigm. Of course you have access to the members anyway but the fact you have no setters sends a clear signal you shouldn't be changing them through code. I've provided DrawDirectEx which ignores the sprites own renderstates but there's nothing for manipulating the handles.

I think I can add support for procedurally generated MasterSprites. I will test it out Smile

9:53 am
March 3, 2010


thaaks

Germany

Member

posts 97

matibee said:
I'll look to see if procedural content can be managed gracefully by the current MasterSprite/Sprite/SpriteList system. I assume you will want instances of these sprites too? So it would be good for the framework to handle them.

That would be great! And yes, for some Sprites I would want to have instances, for others I will require a bunch of master sprites.

I'm not convinced. I think hard-coded manipulation of these values goes against the "data driven" paradigm. Of course you have access to the members anyway but the fact you have no setters sends a clear signal you shouldn't be changing them through code. I've provided DrawDirectEx which ignores the sprites own renderstates but there's nothing for manipulating the handles.

I think I can add support for procedurally generated MasterSprites. I will test it out Smile

But for MasterSprites that are created from code by passing an image you would need a way to specify xhandle, yhandle and blendmode as they are required in the sprite code. If you do that with a Create function I'm fine Smile

Thanks for considering this code change Wink

10:15 am
March 3, 2010


matibee

Admin

posts 104

Here's what I have in mind. It fits well with the current system and you'll do it in the "LoadResources" method (so you can update the loading screen if you want to - especially if there are lots of them to create).

' assume img is your local TImage, however you created it..
local script$ = "xhandle=20~n"
script$ :+ "yhandle=20~n"
script$ :+ "blendmode=1"
AddMasterSprite( "blob01", img, script$ )

You're then free to GetSprite, CreateInstance etc on the MasterSprite called "blob01″. You could code the script as I did above, or load from a file.

I guess it would need a method for inserting animation frames too. I think I know how that will work.

Thanks for considering this code change

No problem! Here's the deal — give me some assets to test with, and I will code it Wink Your assets are safe and secure in my hands or you may just give me placeholders.

8:53 am
March 5, 2010


thaaks

Germany

Member

posts 97

That approach looks good - converting a String to a Stream and thus faking a file Wink

Do you still need some assets? What do you need? Should I send you the code to generate a spaceship image? Or should I send you some png files? Not sure. Or do you need some simple routine to create an image, draw something on it and then return that? I'd bet you can code that faster than I can say "thingamadoo" Laugh

So can I help you and if so, how?

Cheers,
Thomas

9:12 am
March 5, 2010


matibee

Admin

posts 104

I was thinking that if you're generating sprites in a special way then I would use your code and assets as a test case. But I don't think it's necessary now. Thanks anyway, and watch this space!

7:28 pm
March 5, 2010


matibee

Admin

posts 104

Post edited 7:29 pm - March 5, 2010 by matibee


Tis done!

It takes three steps…

    1. Create a new managed bitmap for each frame, and let the system look after it in the same way it does with the ref-counted bitmaps loaded from disk.
    2. Create an empty MasterSprite object.
    3. Add all your frames to your MasterSprite by refering to each frame by the managed bitmap name.

A fourth and optional step is to apply an animation script as in the string example above.

It's coded, quite thoroughly tested and comes with a new example. I'll work on a new release ASAP.

9:30 pm
March 5, 2010


thaaks

Germany

Member

posts 97

Perfect!
Take your time - I'm pretty busy this weekend with real life Laugh

No Tags

About the Matt Bennett: CAD & Code forum

Most Users Ever Online:

11


Currently Online:

2 Guests

Forum Stats:

Groups: 4

Forums: 7

Topics: 58

Posts: 265

Membership:

There are 26 Members

There has been 1 Guest

There is 1 Admin

There are 0 Moderators

Top Posters:

thaaks - 97

Amiga Man - 53

Dabz - 5

niek - 4

semar - 2

Administrators: matibee (104 Posts)