Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Animating textures?
Topic Started: Jun 20 2014, 10:35 AM (364 Views)
clumps
Newbie
[ * ]
I want to use animated sprites in Ultimate3d. I've tried loading a spritesheet as a texture and changing the texx1, texx2 variables mid-game, but it never changes. It works if I change the texture itself, but I don't want to have separate textures for every subimage unless there's no other possible way. The only thing that seems to work is destroying and recreating the billboard every step, but then for some reason it's only visible when it's moving, and there's constantly another instance of the same billboard visible in the top right corner.

So that's odd. Does anyone know how to fix it?
Offline Profile Quote Post Goto Top
 
luenardi
Member Avatar
Cofee Machines Rock
[ *  *  *  *  *  * ]
clumps
Jun 20 2014, 10:35 AM
I want to use animated sprites in Ultimate3d. I've tried loading a spritesheet as a texture and changing the texx1, texx2 variables mid-game, but it never changes. It works if I change the texture itself, but I don't want to have separate textures for every subimage unless there's no other possible way. The only thing that seems to work is destroying and recreating the billboard every step, but then for some reason it's only visible when it's moving, and there's constantly another instance of the same billboard visible in the top right corner.

So that's odd. Does anyone know how to fix it?
Do you call step() after changing it?
Posted Image

For your perception no.
But my universe has no such limits.


www.recall.co.nr
Offline Profile Quote Post Goto Top
 
clumps
Newbie
[ * ]
luenardi
Jun 20 2014, 10:38 AM
clumps
Jun 20 2014, 10:35 AM
I want to use animated sprites in Ultimate3d. I've tried loading a spritesheet as a texture and changing the texx1, texx2 variables mid-game, but it never changes. It works if I change the texture itself, but I don't want to have separate textures for every subimage unless there's no other possible way. The only thing that seems to work is destroying and recreating the billboard every step, but then for some reason it's only visible when it's moving, and there's constantly another instance of the same billboard visible in the top right corner.

So that's odd. Does anyone know how to fix it?
Do you call step() after changing it?
I did, yeah. I probably should post the code I'm using:

Quote:
 
animate_sprite(86,100,10)
//Create2D()
Step();


if I un-comment Create2D(), I put Destroy() in End Step

And this is what's in the animate_sprite script:

Quote:
 
//0=width, 1=height, 2=number of subimgs

texx1=(argument0*floor(subimg))/(argument0*argument2)
texy1=0
texx2=argument0*floor(subimg+1)/(argument0*argument2)
texy2=1
subimg+=image_speed
if subimg>=argument2 subimg=0;


Can you see anything I've done wrong?
Edited by clumps, Jun 20 2014, 10:49 AM.
Offline Profile Quote Post Goto Top
 
Despellanion
Member Avatar
Forum God
[ *  *  *  *  *  * ]
clumps
Jun 20 2014, 10:47 AM
luenardi
Jun 20 2014, 10:38 AM
clumps
Jun 20 2014, 10:35 AM
I want to use animated sprites in Ultimate3d. I've tried loading a spritesheet as a texture and changing the texx1, texx2 variables mid-game, but it never changes. It works if I change the texture itself, but I don't want to have separate textures for every subimage unless there's no other possible way. The only thing that seems to work is destroying and recreating the billboard every step, but then for some reason it's only visible when it's moving, and there's constantly another instance of the same billboard visible in the top right corner.

So that's odd. Does anyone know how to fix it?
Do you call step() after changing it?
I did, yeah. I probably should post the code I'm using:

Quote:
 
animate_sprite(86,100,10)
//Create2D()
Step();


if I un-comment Create2D(), I put Destroy() in End Step

And this is what's in the animate_sprite script:

Quote:
 
//0=width, 1=height, 2=number of subimgs

texx1=(argument0*floor(subimg))/(argument0*argument2)
texy1=0
texx2=argument0*floor(subimg+1)/(argument0*argument2)
texy2=1
subimg+=image_speed
if subimg>=argument2 subimg=0;


Can you see anything I've done wrong?
I don't get that code at all. Why are you resetting texy1/texy2 right after you set it? Step() won't know that you've set new coordinates.

Code:
 

texx1=(argument0*floor(subimg))/(argument0*argument2)
texy1=0 //<-- Why?
texx2=argument0*floor(subimg+1)/(argument0*argument2)
texy2=1 //<-- Why?
Offline Profile Quote Post Goto Top
 
clumps
Newbie
[ * ]
The y coordinates are always the same, the spritesheet only goes from left to right. I suppose it'd be more efficient to just set them in the create event, but since the code wasn't working anyway I wasn't really thinking about making it more efficient.
Offline Profile Quote Post Goto Top
 
Despellanion
Member Avatar
Forum God
[ *  *  *  *  *  * ]
From the manual
Manual
 

Updating primitive objects

You already know that you can change the transformation of a primitive after its creation using the variables x, y, z, rotx/y/z, scalx/y/z. The same can be done with the texture. It can be changed at any time. But what about the other properties of a primitive? For example, if you want to animate a texture by changing texx1, texy1, texx2 and texy2? If you change these variables after creating the primitive, the object does not change. For this reason there's the function RecreatePrimitive(). It does exactly what the name says. It destroys the primitive and recreates it with the new data of the variables.
Edited by Despellanion, Jun 20 2014, 03:25 PM.
Offline Profile Quote Post Goto Top
 
clumps
Newbie
[ * ]
Aaaaah. I missed that bit.

Thanks.
Offline Profile Quote Post Goto Top
 
Animaster78900
Member Avatar
Forum Reaper(Highest Ranked)
[ *  *  *  *  *  * ]
all I do for animated textures is a thing in the step function like

tex += 1
if tex >=5{tex=0}

and in the draw function

if tex = 0 {draw texture related crap I forgot}
if tex = 1 {draw texture related crap I forgot}
if tex = 2 {draw texture related crap I forgot}
if tex = 3 {draw texture related crap I forgot}
if tex = 4 {draw texture related crap I forgot}
if tex = 5 {draw texture related crap I forgot}

Just make it switch through the things for as many frames that are for the animation.
Posted Image
Current Projects: Hack Attack, Red Lion, X-Falcon: Redux
Offline Profile Quote Post Goto Top
 
zelda4evr
Member Avatar
Forum God
[ *  *  *  *  *  * ]
if you wanted a different sprite file for each frame couldn't you do something similar to this(off the top of my head):

create:
Code:
 
tex=0;
texture[0]="c:/texturepath";
texture[1]="c:/texturepath";
texture[2]="c:/texturepath";
texture[3]="c:/texturepath";


step:
Code:
 

tex+=1;
if(tex>=3)
{
tex=0;
}
texture=texture[tex];


Posted Image
Offline Profile Quote Post Goto Top
 
Despellanion
Member Avatar
Forum God
[ *  *  *  *  *  * ]
Code:
 

for(tex=0; tex<textures.length; tex++)
{
texture = textures[tex];
}

Get some sleep, guys :P
Offline Profile Quote Post Goto Top
 
« Previous Topic · Questions about Ultimate 3D · Next Topic »
Add Reply