Sprites in Mojo3D

Home Forums Monkey 2 Development Sprites in Mojo3D

Tagged: ,

This topic contains 9 replies, has 4 voices, and was last updated by  Ethernaut 3 months, 2 weeks ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #9744

    Ethernaut
    Participant

    I started diving a little more into Mojo3D, and have some questions about sprites:

    • Would it be possible to have sprites more integrated in the 3d scene and render correctly when behind 3d objects? (could be an optional thing). Currently they seem to always render on top.
    • I’m trying to implement animated sprites. That was easy in Mojo2D, since I could have an image array and just draw the correct image at the right time. As far as I understand, in Mojo an image is simply a rect contained in a Texture, so ultimately an image array could have images from the same texture, which is very efficient. SpriteMaterial.ColorTexture uses Texture instead of Image. Would it be inefficient to create a Texture array and replace the current SpriteMaterial.ColorTexture on every frame? Is there a better way?
    • How do you set the texture flags on a sprite? Setting the flags onĀ SpriteMaterial.ColorTexture didn’t have an effect.
    • Are those things planned to be implemented in the future, and should I just wait? I’m looking for things like loading sprite sheets, setting frame rate, loop behavior and frame lists, etc.
    • Bonus: it would be nice if the sprite shader had the ability to “flash” a certain color (paint all non-transparent pixels with that color) temporarily.

    Thanks!

    #9801

    Mark Sibly
    Keymaster

    Yeah, sprites are very primitive right now and there are lots of changes coming. I will definitely keep your questions in mind though and try to address them as well as I can.

    I just need to finish up the IAP mobile module this week, and then it’s back into the fun/interesting stuff!

    #9802

    Playniax
    Participant

    I just need to finish up the IAP mobile module this week

    I guess I have to be careful of what I wish for in the future šŸ™‚

    #9917

    Mark Sibly
    Keymaster

    Just having a play with sprites…

    How do you set the texture flags on a sprite? Setting the flags onĀ SpriteMaterial.ColorTexture didnā€™t have an effect.

    This should work, which flags were you trying to use.

    #9918

    Ethernaut
    Participant

    I’m trying to set the flags after creating the material, like this:

    #9919

    Mark Sibly
    Keymaster

    Ok, cheers, turns out Texture.Flags setter was completely borked – getting some nice ‘outrun’ style pixels now!

    I’ll also add a textureFlags param to SpriteMaterial.Load, but being able to modify flags is way cool.

    #9958

    Mark Sibly
    Keymaster

    Just pushed some fixes and changs to develop branch.

    Sprites should now use depth buffer properly, and Texture.Flags setter now works.

    Also, as a bit of an experiment, I added a TextureRect property to Sprite. This defaults to new Rectf( 0,0,1,1 ) and describes the 4 ‘texture coordinate’ corners of the sprite, ie: you could theoretically use this to pick frames out of an atlas. A better approach might be to add the rects to the material, but this is would involve coming up with a ‘SpriteFrames’ class and/or ‘SpriteAnimations’ class etc. Have to think about this a bit more!

    #9964

    cocon
    Participant

    AreĀ 3D sprites same as a 3D object?

    However you will have to apply a rotation to look at the camera all the time.

    #9978

    Mark Sibly
    Keymaster

    Have a look at the sprites test.

    #10030

    Ethernaut
    Participant

    Thanks Mark!

    If you decide to add a SpriteFrames class or similar I’ll update my stuff, but for now I made an “AnimSprite” class that extends Sprite and stores the coordinates internally. I also have an “AnimationClip” class that simply stores a named frame sequence, so you refer to it by name and “grab” different frames from the same sprite sheet.

    Here’s the class, complete with Json file loading for animation clips (use example attached at the bottom). This is more or less super untested! šŸ™‚

    And here’s an example use, with a little animated explosion sprite!
    http://monkeycoder.co.nz/wp-content/uploads/2017/08/animSprite-1.zip

    Only thing missing now is a way to “flash” a color on the sprite!
    Cheers.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.