drawsprite with time interval

ABK

Well-known member
Hey guys im trying to make traces on snow but using drawsprite to save some cpu cycles instead of using new entity for each trace.
So theres like 10 copies of the same trace image , they need to be drawn one next to another, im trying to figure out a way to do that bu so far i cant find examples how to draw multiple copies with specific delay/space between them.
So they cant be spawned all at once at the same time, they need delay like 4 or 5.
Heres what i have in script, i have facing and all working, just need to spawn copies with slight delay.Then ideally id apply drawmethod scale to shrink them and disappear after like 6 seconds.
Code:
void main()
{
	if(openborvariant("in_level"))
	
	trace();
}

void trace()
{//Simulates a "Snow" effect
    void self = getlocalvar("self");
	void tra =  loadsprite("data/sprites/font3.gif");

    float xpos = openborvariant("xpos");
    float ypos = openborvariant("ypos");
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");
    float a = getentityproperty(self, "a");
    int facing = getentityproperty(self, "direction");
	int layer = getentityproperty(self, "setlayer")+2;
    int drawn1 = getentityvar(self, "drawn1");
    int etime = openborvariant("elapsed_time");
		
	//DEBUG INFO ONLY, ERASE WHEN ALL TESTS ARE DONE
	drawstring(50, 144, 1, "tracejest___");
		drawstring(50, 244, 1,etime);
				drawstring(50, 294, 1,drawn1);
        if ( tra != NULL() && drawn1 == NULL() ) {
            if (facing == 1) facing = 0;
            else facing = 1;
            setdrawmethod(NULL(), 1, 256, 256, facing);
            drawsprite( tra, x-xpos, z-a-ypos-4, z+2);
            changedrawmethod(NULL(), "enabled", 1);
            changedrawmethod(NULL(), "reset", 1);
            setdrawmethod(NULL(), 0);
            setentityvar(self, "drawn1", 1);


		}
}
 
Honestly, I dunno how much you would save by using drawsprite. For example, you are loading the sprite in every tick.
Even the engine ignoring the load when you try to load the same sprite twice, the load routine will be made anyway and, at the end, the engine recognize the sprite and won't load it again.
But you will be wasting CPU cycles on that.

Type NONE are very much optimized, so they would work for that perfectly.
And, for your usage, it would be way easier and user friendly to use a specific entity just for that.
 
Thats what i do already but im one of these guys who has to try themselves and cmpare cpu hit, from initial finding your experience can be confirmed, its as unoptimised as several entities awith alpha effects.
I converted some stuff to fglayers like lifebars and it saves cpu so im always up for finding more ways to optimize , cause i can notice lag on octa core phone with alpha transparencyt effect on 3 fglayers which is super strange that such fast cpu cant handle 3 layers.
I wish i  had more knowledge about coding, i personally would dig into alpha and transparency code to fix this. IMO theres huge memory leak there.
 
bWWd said:
Thats what i do already but im one of these guys who has to try themselves and cmpare cpu hit



Hi, I'm one of those guys who's constantly looking for ways to optimize the games I work on as well because I mostly work on getting openbor games to run for the ps vita.

I have learned some really interesting things along the way in regards to optimization,  one of the biggest frame drops that I noticed was using fglayers. I  had to switch to make type none models instead for a certain parallax effect that I was going for.

So instead of using a pattern of trees as fglayers with their horizontal speed to create a loop,  I opted to create individual type none trees that would spawn and destroy themselves outside of the left side of the screen. The game went from 40fps to 55-60fps on the psvita.  However on my laptop you couldn't tell the difference,  so I'm not sure if this is actually a proven method to conserve some cpu and optimizing the game.

One time I discovered that if an NPC has the @cmd  clear in their idle animation,  thw psvita would chug to 8 fps unless I advanced the screen.

I actually tested this on my laptop and it did slow down the fps as well.

Anyhow,  I'm still learning a lot so perhaps none of what I mentioned applies to you or anyone else.

 
greatvinfo, can you post that @cmd clear script so i can see what magic code runs inside that steals all fps and never use it.
About fglayers, when they dont move like aprallax fx thrn threyre fine , i replaced multiple platform entities with fglayers in labirynth stage , fps improved a lot, it could of veen cause of platform code inside entities was removed or could be cayse fglayer dont move in that stage... but fglayers arw definitely cpu hitters, quad corea or octa cores, thay all suffer, its very unoptimised code.
 
Me too. Using alpha transparency requires more CPU cycles, its normal. I never hard any issue with it though.

The only time I had a problem with fglayer was when I used a very big one (5000px) with "water" distortion on it. It slowed the game down a bit in some weaker platforms.

One time I discovered that if an NPC has the @cmd  clear in their idle animation,  thw psvita would chug to 8 fps unless I advanced the screen.
PS VITA  Why are you using a clear (probably, clearL) function on idle animation? This will trigger multiple times.
 
O_Ilusionista said:
Me too. Using alpha transparency requires more CPU cycles, its normal. I never hard any issue with it though.

The only time I had a problem with fglayer was when I used a very big one (5000px) with "water" distortion on it. It slowed the game down a bit in some weaker platforms.

One time I discovered that if an NPC has the @cmd  clear in their idle animation,  thw psvita would chug to 8 fps unless I advanced the screen.
PS VITA  Why are you using a clear (probably, clearL) function on idle animation? This will trigger multiple times.

I was learning from the double dragon reloaded mod and I turned an enemy into a NPC and I couldn't figure out what was causing the game to drop to 8fps when I was a little idle or it would accumulate drops frames even if I scrolled the screen over the course of time. But I will post the original code later whenever I get a chance.

But yes ever since I removed clearL on the NPC idle animation the game ran back at 60fps (in stages were there isn't alot ot fglayers or huge sprites)

Also keep in mind that double dragon reloaded Sprites are doubled in size 200 pixels X 200 pixels :(

EDIT:

This is the original code in question of one of the enemies from double dragon reloaded :
Code:
anim idle
     loop 1
     delay 5
     offset 77 170
     bbox 60 55 40 100
     @cmd clearL
     frame data/chars/dibiase/idle.gif
     frame data/chars/dibiase/idle.gif

is the @cmd clearL properly used when the entity is an enemy vs an NPC or is it wrong to use it in both scenarios?


Edit#2

I just checked and also the players have the @cmd clearL code on their idle animations, but this didn't cause the game to drop frames after being idle for however long you if you stand there.This only happens when used it for NPCS I believe.
 
I have strong hunch that declaring clearL function in IDLE idea was copied from Crime Buster v2.5.

In that module, I used local variable for some purposes:
1. Store grabbed entity for slams/throws
2. Store grabbed status for antigrab/break free animation
3. Store running status for runspecial animation

I figure the best way to clear all local variables at once is by using that function and put it in IDLE animation.
However, lately I usually clear variable used for slams/throw at end of slam/throw animation. And since I don't have characters with antigrab/break free and runspecial animation, I never need to declare clearL in IDLE animation anymore  ::).

TLDR, if your character, NPC or enemy aren't using local variable then there's no need to declare clearL in IDLE animation.
 
Bloodbane said:
I have strong hunch that declaring clearL

TLDR, if your character, NPC or enemy aren't using local variable then there's no need to declare clearL in IDLE animation.

Nothing had ever dipped the frame so bad than using clearL in a NPC idle animation but for whatever reason this wasn't accounted for the player or enemy.

I'm just glad I discovered this sooner than later because I kept wondering what it was until I noticed that when NPCs finished fighting they would end up using their Idle animation and not move a muscle.  2 to 3 minutes later the game would drop the frame rate to like 40fps, a couple of minutes later the game would drop to like 6-8fps.

Funny enough if you scroll the screen and advance the game would recover to 50fps second but as soon as you would idle again it would dip to 8fps again.

Btw I had 3 npcs with me at the time,  so obviously this would chug the frame rate sooner.
 
Back
Top Bottom