Raised This Month: $32 Target: $400
 8% 

Sprite entity animation problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-04-2011 , 10:17   Sprite entity animation problem
Reply With Quote #1

I have been playing with sprites recently and come across a problem of how to animate a sprite.
After much searching i used the following method to make it animate:
Code:
create_sprite(id) {     // Create an entity for the player     g_player_ent[id] = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_sprite"))         // Invalid entity ?     if (!pev_valid(g_player_ent[id]))         return -1;         // Set some basic properties     set_pev(g_player_ent[id], pev_takedamage, 0.0)     set_pev(g_player_ent[id], pev_solid, SOLID_NOT)     set_pev(g_player_ent[id], pev_movetype, MOVETYPE_NONE)     set_pev(g_player_ent[id], pev_owner, id)         // Set the sprite and rendering on the entity     engfunc(EngFunc_SetModel, g_player_ent[id], g_sprite_name)     fm_set_rendering(g_player_ent[id], .render = kRenderTransAlpha, .amount = 0)         // Set the sprite size     set_pev(g_player_ent[id], pev_scale, 0.05)         // Set the sprites animation time and framerate     set_pev(g_player_ent[id], pev_animtime, 0.1)     set_pev(g_player_ent[id], pev_framerate, 0.1)         // Spawn the sprite entity (necessary to play the sprite animations)     dllfunc(DLLFunc_Spawn, g_player_ent[id])     set_pev(g_player_ent[id], pev_spawnflags, SF_SPRITE_STARTON)         return g_player_ent[id]; }
However it didnt work and i got puzzled up, can someone tell me how to animate the sprite (I m also attaching it so you can see the animation (in sprite explorer) i m trying to play)
Attached Files
File Type: zip zombie_win.zip (339.3 KB, 149 views)
__________________

My Plugins For ZP

Inactive due to College and Studies

Last edited by abdul-rehman; 07-04-2011 at 10:32. Reason: Forgot to attach the sprite
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-04-2011 , 10:41   Re: Sprite entity animation problem
Reply With Quote #2

Start with

set_pev(g_player_ent[id], pev_scale, 1.0 )
set_pev(g_player_ent[id], pev_animtime, get_gametime() )
set_pev(g_player_ent[id], pev_framerate, 1.0 )
set_pev(g_player_ent[id], pev_spawnflags, SF_SPRITE_STARTON) // (doesn't make sense you set a spawnflag after you spawn the entity...)
dllfunc(DLLFunc_Spawn, g_player_ent[id])

and see what happens.

If working, adjust the value as you want.
__________________
Arkshine is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 07-04-2011 , 10:51   Re: Sprite entity animation problem
Reply With Quote #3

@abdul-rehman code is good but pev_spawnflags should be before triggering spawn.

Also, stop using fm_* stocks, that one is ok since it does exacly the same thing as engine's stock, but I'd recommend you stick to the simple natives because fm_ prefixed stocks call way more natives than a single engine/fun/cstrike/ham native.
__________________
Hunter-Digital is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-05-2011 , 04:46   Re: Sprite entity animation problem
Reply With Quote #4

@Hunter-Digital: I used fm_set_resndering becoz fun's set_user_rendering doesnt work for non-player entities
@Arkshine i set pev_animtime to get_gametime() and also fixed the pev_spawnflags issue and it worked ! however it only worked if pev_framerate is set to 1.0, if i set it to 0.1 it would animate, so what is the problem now ?
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 07-05-2011 , 05:59   Re: Sprite entity animation problem
Reply With Quote #5

Quote:
Originally Posted by abdul-rehman View Post
I used fm_set_resndering becoz fun's set_user_rendering doesnt work for non-player entities
You can use engine's set_rendering() instead.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-05-2011 , 06:24   Re: Sprite entity animation problem
Reply With Quote #6

set_rendering() is an engine stock which is basically the same as the fm_ one.

Quote:
however it only worked if pev_framerate is set to 1.0, if i set it to 0.1 it would animate
You mean NOT animate ? Anyway If I'm right the framerate is the number of frames by second, so it doesn't make really sense to try to use 0.1..
__________________
Arkshine is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-05-2011 , 15:22   Re: Sprite entity animation problem
Reply With Quote #7

Quote:
Originally Posted by Arkshine View Post
set_rendering() is an engine stock which is basically the same as the fm_ one.

You mean NOT animate ? Anyway If I'm right the framerate is the number of frames by second, so it doesn't make really sense to try to use 0.1..
Sorry, i understood it the wrong way ( i thought the it was the time for 1 frame ) i setted it to 10 (which means 10 frames per second right?) and it works fine
btw i have 2 questions can u please answer
Q1-
How can i stop the animation of the sprite at a particular frame
I tried to set the framrate to 0.0 and it did worked, however i m confused whether this is the best method to do so)
Q2-
When i set the sprite to animate, it only animates 10 frames out of the 12, when i rewrite the sprite to 8 total frames, it only animates 6 out of them! Is it a bug with AMXX or what is exactly the problem.

Btw thankyou all for clearing up my queries once again.
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-05-2011 , 16:25   Re: Sprite entity animation problem
Reply With Quote #8

Q1 : playing with animtime or framerate would work. Talking about "best method" when you have only one instruction to sent is not worth to waste your time. If it works with framerate, it's fine.

Q2 : Before saying it's the AMXX's fault, check your code/sprite. It can't be AMXX anyway because it sent only instructions directly to the engine. So, most likely your fault if it _really_ doesn't show all the frame.
__________________
Arkshine is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-05-2011 , 16:32   Re: Sprite entity animation problem
Reply With Quote #9

Well i could not catch my problem so to fix the issue i added two blank frames in every of my test sprites and it works since it doesnt play the last 2 blank ones btw thanks again.
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:27.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode