CreateOverlay and negative coordinates problem

Started by Dusk, Mon 17/05/2004 00:19:25

Previous topic - Next topic

Dusk

I have a set of room properties that define dinamically a graphic overlay that will move parallax-scrolling style...

Code: ags

int overlay,overlayX,overlayY,overlayZ;

function setParallaxObj() {  
  int startx;
  overlay = GetRoomProperty("ParallaxObj");  
  if (overlay>0) {
    overlayX = GetRoomProperty("ParallaxObjX");
    overlayY = GetRoomProperty("ParallaxObjY");
    overlayZ = GetRoomProperty("ParallaxObjZ");    
    startx = overlayX-(GetViewportX()/overlayZ);
    overlay = CreateGraphicOverlay (startx,overlayY, overlay, 1);    
   // MoveOverlay (overlay, startx, overlayY);	
  }  
}
 
function clearParallaxObj() {
  if (overlay>0) RemoveOverlay(overlay);
  overlay = 0;
}

function ParallaxScroll() {
  if(overlay>0) {	  
   MoveOverlay (overlay, overlayX-(GetViewportX()/overlayZ), overlayY);	
  }
}

function on_event(int event, int data) {
  if (event==ENTER_ROOM) { 
       //... other stuff
       setParallaxObj(); 
       //... other stuff
  }
       //... other stuff
}

function repeatedly_execute() {
 //...lots of things
 ParallaxScroll();
}


I hope the code is clear: now, the problem.
If I enter a large room from right, I have a little horrible delay before the overlay goes into the right screen position. I've tried unsuccesfully to debug it... only one idea: does createGraphicOverlay allow me to specify negative coordinates? I obviouvlsy need it because entering from right some overlays are partially offscreen... moveOverlay does the job, but it's too late. I tried to put a moveOverlay immediately after the creation (you see it commented out), but nothing. Where am I wrong? Any known walkaround/suggestion?

Thankyou for reading  ;)

Scorpiorus

One thing does worry me:Ã,  CreateGraphicOverlay() function creates and then draws an overlay onto the screen. But you call it even before the player enters room (before-fadein) event. Try putting setParallaxObj() into Player enters screen (after fadein) and see if it helps.

Dusk

Thankyou Scorpious, you got it... putting a call to setParallaoxObj()  into "Player enters screen" works...  ;)
I was trying to avoid having to put scripting in the room scripts (room preparation isn't  "my job" in the game we're making - I do the scripting), but seems that I can't solve this problem with the global script only, as I hoped to do.

By the way, if I can make a suggestion, I think that the on_event function is great, and it would be useful to have more events to use with it (such as Player enters creen aft. fade in, like this time).

Thanks again, bye  8)

Scorpiorus

Yep, having such events available to control via the on_event() could be useful because of the reasons you mentioned.

A workaround in your case would be to set a global variable from the on_event() function and then check it in the global repeatedly_execute:

int eventFlag = 0;

// put here everything you want to happen on the first
// run (after player enters screen) of repeatedly_execute()

function my_event() {

   setParallaxObj();
}


function repeatedly_execute() {

   if (eventFlag) {
      my_event();
      eventFlag = 0;
   }
}


function on_event(int event, int what) {

   if (event==ENTER_ROOM) {

      eventFlag = 1;

   }
}

Dusk

Quote from: Scorpiorus on Mon 17/05/2004 16:23:07
A workaround in your case would be to set a global variable from the on_event() function and then check it in the global repeatedly_execute:
<cut>

This is a really nice trick, but doesn't work well in this specific case... I tried, and there's a fastidious delay before the creation of the overlay, while calling setParallaxObj() in "player... before fade in" works perfectly. Patience.  By the way, I think it will come useful for other things, so thankyou again Scorpious.
I realize that I'm doing stupid errors not having completely understood the precise behaviour of the AGS engine, but things start working day after day - I hope to show you something soon.  ;)
Bye :)

Scorpiorus

Ah, you put it before fade-in and thus, probably, the delay isn't noticable. As for repeatedly_execute, yeah I believe it first starts after fade-in, so you already see what's on the screen.

You are welcome,
good luck with your project! :)

stuh505

also...

Quotedoes createGraphicOverlay allow me to specify negative coordinates?

the answer to this is yes

edmundito

This question might be related to this topic, since it deals both with overlays and paralax scrolling:

I want to have some parallax scrolling in my game but I was wondering how much it would slow it down if I have like 5 layers and a huge graphic on the very front of it all. The game is already 32-bit and is using alpha blending, but it's still 320x240 in resolution.

Pumaman

Try it and see. Slap 6 full-screen objects on top of each other and see how fast it runs. I wouldn't be too hopeful though.

SMF spam blocked by CleanTalk