Page 1 of 1

RenderSprite

Posted: Mon Oct 26, 2009 10:06 pm
by y offs et
How about invertX, invertY?
Looking at sprite animation from one large texture, many frames can be just another frame inverted. This would keep the overall size down, or, allow more space for more animations.

Or do you think this could be done from code?
Or, we have draw backface on material and could render backface.

In the added example, this is what can go wrong. The solders sash would be angled the wrong way if the frames were inverted.

Posted: Tue Oct 27, 2009 1:02 am
by Kjell
:idea:

There are a number of solutions for this kind of situation. Let me name a few.

- Use TextureWrapMode "mirror" and set the TextureX to the negative equivalent of the desired frame ( the old-skool way ).

- Use ModelDefined Texture Coordinates and either adjust the UV in realtime ( RenderNet is the only Component with this feature ), or toggle between two sprite meshes.

- Use a ShaderVariable to determine when a sprite needs to be flipped and simply invert the coordinates in a vertex shader.

Go with whatever you find most convenient :wink:

K

Posted: Tue Oct 27, 2009 2:33 am
by y offs et
Easy for you to write.

Anyway,
(1) doesn't seem to do anything,
(2)&(3) are beyond my competence at this time.

My aim is forethought in laying out the texture to eliminate the need for higher math. I envision say a 1028x1028 texture with 100 images, and working with image #33.

Somewhere in the pipeline between getting the image and rendering it, I want to be able to flip it (easily). If possible, I can cut the number of images down to, say 70.

Posted: Tue Oct 27, 2009 3:30 am
by Kjell
Hmm,

The second method is probably the easiest .. switching between a mesh identical to a Sprite and another with flipped UV coordinates ( you'll have to import them from a external 3D application ).

Anyway, here's a sample project ( exe and source ) showing the first two methods I mentioned, with the second method using the RenderNet Component. The left instance is the normal animation, middle uses mirror, right uses uv. As you can see you don't need to do anything fancy .. although I agree there's room to make it even easier :)

Don't hesitate to ask away when you need further assistance.

K

Posted: Tue Oct 27, 2009 1:51 pm
by jph_wacheski
you can also just add the facing vlaure to the animation equation like here;

Code: Select all

ZZDC<?xml version="1.0" encoding="iso-8859-1" ?>
<Model Name="Model1">
  <Definitions>
    <DefineVariable Name="frame"/>
    <DefineVariable Name="facing"/>
  </Definitions>
  <OnRender>
    <UseMaterial Material="Material1"/>
    <RenderSprite/>
  </OnRender>
  <OnUpdate>
    <KeyPress Comment="<" Keys="<">
      <OnPressed>
        <ZExpression Expression="facing=-1;"/>
      </OnPressed>
    </KeyPress>
    <KeyPress Comment=">" Keys=">">
      <OnPressed>
        <ZExpression Expression="facing=0;"/>
      </OnPressed>
    </KeyPress>
    <ZExpression>
      <Expression>
<![CDATA[// Increment & reset image frame

Frame += App.DeltaTime*8;

if(Frame > 4)Frame = 0;

// Calculate texture offset

w.TextureX = (-.25+(floor(Frame)*0.25))+facing;]]>
      </Expression>
    </ZExpression>
  </OnUpdate>
</Model>
just past him in, and use left and right arrows to face him.

Posted: Tue Oct 27, 2009 4:14 pm
by y offs et
Thanks guys. I learned about four different things here.
:o