RenderSprite

If there is something important you think is missing in the current version of ZGameEditor then you can post a feature request here!

Moderator: Moderators

Post Reply
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

RenderSprite

Post 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.
Attachments
walkAngle.zip
(6.26 KiB) Downloaded 501 times
User avatar
Kjell
Posts: 1881
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post 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.
User avatar
Kjell
Posts: 1881
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
Attachments
Zero.zip
(50.24 KiB) Downloaded 533 times
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post 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.
iterationGAMES.com
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post by y offs et »

Thanks guys. I learned about four different things here.
:o
Post Reply