Vertical/Diagonal auto-scrolling of bglayers

White Dragon

New member
Is it possible to obtain a vertical/diagonal auto-scrolling of bglayers?
If it is not possible... Is it possible to add this ability to openbor?
 
For now I wrote a method that simulates it drawing a sprite:

Code:
void drawOffsetShiftBg() {
	int hshift, vshift, shift;
	int t = openborvariant("elapsed_time");
	void logobg = glv("logobg");
	int refresh_time = 2.2;
	int width = 128, height = 128;
	int vres = ov("vresolution");
	int hres = ov("hresolution");
	int i,i_s, i_d, x, y, z = 1; // i_s == i di sx e rispettivamente i_d i di destra
	int t_fix = 2; // Soglia di aggiustamebto. Aggiunge un numero x di patterns

	if ( logobg ) {
        changedrawmethod(NULL(), "reset", 1);
        changedrawmethod(NULL(), "enabled", 1);
        //changedrawmethod(NULL(), "centerx", width/2); // ancoraggio
        //changedrawmethod(NULL(), "centery", height/2);

        // Dobbiamo scostare il pattern da hres a 0 e da vres a 0 ricordando che l'ancoraggio e offset(0,0)
        // Poi dopo che si è oltre vres/hres ri ricomincia dacapo (ecco perchè il modulo)
        // Facciamo ((hres/width)*width) e non semplicemente hres per cicominciare da capo nel giisto modo
        // Ovvero non dobbiamo fare solo %hres ma dobbiamo considerare la lunghezza del pattern. cioè width finchè non ricopre la hres
        hshift = (t/refresh_time)%((hres/width)*width);
        vshift = (t/refresh_time)%((vres/height)*height);
        x = hres-hshift; // posizione
        y = vres-vshift;
        //drawstring(160, 120,0,x);

        /*
         * Dobbiamo ricoprire l'intero schermo SEMPRE. Quindi quanti pattern disegnamo?
         * Vediamo la riga horizzontale a sinistra dello sprite. Sappiamo che è alla coordinata x e che è lungo width.
         * Quanti ne dobbiamo disegnare per coprire tutta la parte sinistra? Dobbiamo coprire una distanza x (da 0 a x).
         * Quindi dobbiamo disegnarme x/width + qualche altro (forse 2 ) per coprire le mezze parti.
         */
        //shift = 0;

        // Occupiamoci di riempire la parte su (e poi sx/dx)
        for (i = 0, i < (y/height)+t_fix; ++i) {
            int new_y = y-(i*height);

            drawsprite(logobg, x, new_y, z);
            for (i_s = 0, i_s < (x/width)+t_fix; ++i_s) {
                int new_x = x-(i_s*width);
                drawsprite(logobg, new_x, new_y, z);
            }
            for (i_d = 0, i_d < ((hres-x)/width)+t_fix; ++i_d) {
                int new_x = x+(i_d*width);
                drawsprite(logobg, new_x, new_y, z);
            }
        }

        // Occupiamoci di riempire la parte giù (e poi sx/dx)
        for (i = 0, i < ((vres-y)/height)+t_fix; ++i) {
            int new_y = y+(i*height);

            drawsprite(logobg, x, new_y, z);
            for (i_s = 0, i_s < (x/width)+t_fix; ++i_s) {
                int new_x = x-(i_s*width);
                drawsprite(logobg, new_x, new_y, z);
            }
            for (i_d = 0, i_d < ((hres-x)/width)+t_fix; ++i_d) {
                int new_x = x+(i_d*width);
                drawsprite(logobg, new_x, new_y, z);
            }
        }

        changedrawmethod(NULL(), "reset", 1);
        changedrawmethod(NULL(), "enabled", 0);
	}
}

void logobg = glv("logobg"); // loaded sprite
int refresh_time = 2.2; // speed
int width = 128, height = 128; // pattern resolution

 
I was thinking about another parameter of bgspeed. It sounds reasonable enough, although script solution provides more possibilities.

Your solution is good, the only thing I want to say is text entity that pauses the game. You can use openborvariant("textbox") to test if there is one and add proper delays.

Otherwise you can use a dummy entity's to animate the bg, because the entity can be paused by text entity.
 
O Ilusionista said:
Could you put the comments in english?
The only things you need are those marked before:

void logobg = glv("logobg"); // loaded sprite glv = getlocalvar. ssprite is loaded with loadsprite("path");
int refresh_time = 2.2; // speed
int width = 128, height = 128; // pattern resolution

try it OIllusionista, I'm still working on a final version.

utunnels said:
I was thinking about another parameter of bgspeed. It sounds reasonable enough, although script solution provides more possibilities.

Your solution is good, the only thing I want to say is text entity that pauses the game. You can use openborvariant("textbox") to test if there is one and add proper delays.

Otherwise you can use a dummy entity's to animate the bg, because the entity can be paused by text entity.
thank you, I'll try with openborvariant("textbox") too!
 
The problem of update.c is it is not executed with your logic update, but screen update. So it is possible a slow device has lower frame rate, so elapsed_time jumps, making it impossible to determine when EXACTLY is textbox spawned, unless you put another script in the textbox entity itself, which makes your scripts scattered and hard to manage.

That is why I prefer a dummy entity. You can use its ondrawscript to display and update/animation script to update position, change frame counter, etc.
 
I think what O Ilusionista means is that your comments in that script text are in Italian and he was asking you if you could probably interpret to him what they mean in English. Hahah!
 
maxman said:
I think what O Ilusionista means is that your comments in that script text are in Italian and he was asking you if you could probably interpret to him what they mean in English. Hahah!

Yes, that was my point. Anche se io parlo italiano, non parlo molto bene.
I just want to understand the comments, this helps to understand the code :)
 
maxman said:
I think what O Ilusionista means is that your comments in that script text are in Italian and he was asking you if you could probably interpret to him what they mean in English. Hahah!

I understand of course, but I was not sure it was the final version.
Needless to translate the comments of a code subject to change.

O Ilusionista said:
Could you put the comments in english?

Here english comments + cleaned code + sample dummy entity with ondrawscript event:
Code:
name	title_bg
type	none

ondrawscript @script
 void main() {
	if ( getlocalvar("flag") == NULL() ) {
		setlocalvar("logo", loadsprite("data/bgs/bg_pattern.gif"));
		setlocalvar("flag", 1);
	}
	if ( getlocalvar("logo") ) drawOffsetShiftBg(getlocalvar("logo"), 128, 128);
 }

void drawOffsetShiftBg(void logobg, int width, int height) {
	int hshift, vshift, shift;
	int t = openborvariant("elapsed_time");
	int refresh_time = 2.2;
	int vres = openborvariant("vresolution");
	int hres = openborvariant("hresolution");
	int i,i_s, i_d, x, y, z = 1; // i_s == i (left) and i_d the right index respectively
	int t_fix = 2; // Threshold adjustment. Adds a number of patterns x

	if ( logobg ) {
	// We need to shift the pattern from hres to 0 and from vres to 0 recalling that the anchor and offset (0,0)
        // Then after that you are over vres / hres you start at the beginning (which is why the module)
        // Let ((hres / width) * width) and not simply hres to start afresh in the right way
        // Do not limit ourselves only to %hres but we must consider the length of the pattern. that is width, until it covers the hres.
        hshift = (t/refresh_time)%((hres/width)*width);
        vshift = (t/refresh_time)%((vres/height)*height);
        x = hres-hshift; // posizione
        y = vres-vshift;

	/ *
          * We must ALWAYS fill the entire screen. So many patterns we draw?
          * Let the horizontal line to the left of the sprite. We know it is the x-coordinate and also that it is long width.
          * How many do we have to draw to cover the whole left side? We have to cover a distance x (from 0 to x).
          * So we have to draw x / width + some other (maybe 2) to cover halves.
          * /
        // Let us fill the part UP (and then left / right)
        for (i = 0, i < (y/height)+t_fix; ++i) {
            int new_y = y-(i*height);

            drawsprite(logobg, x, new_y, z);
            for (i_s = 0, i_s < (x/width)+t_fix; ++i_s) {
                int new_x = x-(i_s*width);
                drawsprite(logobg, new_x, new_y, z);
            }
            for (i_d = 0, i_d < ((hres-x)/width)+t_fix; ++i_d) {
                int new_x = x+(i_d*width);
                drawsprite(logobg, new_x, new_y, z);
            }
        }

        // Let us fill the part DOWN (and then left / right)
        for (i = 0, i < ((vres-y)/height)+t_fix; ++i) {
            int new_y = y+(i*height);

            drawsprite(logobg, x, new_y, z);
            for (i_s = 0, i_s < (x/width)+t_fix; ++i_s) {
                int new_x = x-(i_s*width);
                drawsprite(logobg, new_x, new_y, z);
            }
            for (i_d = 0, i_d < ((hres-x)/width)+t_fix; ++i_d) {
                int new_x = x+(i_d*width);
                drawsprite(logobg, new_x, new_y, z);
            }
        }
	}
}
@end_script

anim idle
	delay	1
	offset	0 0
	frame none
 
utunnels said:
Otherwise you can use a dummy entity's to animate the bg, because the entity can be paused by text entity.

I tried to make bglayer entity myself and instead of animating the bglayer, I spawned another entity to move down/up depending on how bglayer moves.
It works but there's one occasion it stops: during continue or when all lives are depleted but player hasn't continued yet. I don't understand why, maybe it's related to how enemy usually stops during this occasion too?
 
After rereading my post I think I should mention it like this:

I spawned another entity which moves down/up depending on how bglayer moves.

Anyways, here's an example:

name PWall
type none
shadow 0
antigravity 100
subject_to_wall 0
subject_to_obstacle 0
subject_to_platform 0
animationscript data/scripts/prscript.c
load    PWallM

anim spawn
delay 10
offset 1 1
        @cmd    shooter "PWallM" 0 179 0 1.28
frame data/chars/misc/empty.gif

anim idle
loop 1
delay 1
offset 1 1
frame data/chars/misc/empty.gif
delay 173
        @cmd    shooter "PWallM" 0 0 0 1.28
frame data/chars/misc/empty.gif

This entity is invisible. It spawns PWallM which is background players see and the latter moves up. This is for level with background moving up, or IOW direction down level.
 
Oh, I think shooter uses the spawn function?
If so that might be a player count loophole but I think it was fixed long time ago. Maybe I need to double check that.

What is in PWallM txt, just in case?
 
Have you tried recent version? It sounds like an old issue but I don't think player entity is necessary for spawn function anymore.
 
Back
Top Bottom