Object moves only if chatacter is blocked

Started by AnasAbdin, Sun 07/08/2011 15:57:09

Previous topic - Next topic

AnasAbdin

frustrated...
I only want to move an object around the room (a cloud)... it works great as long as it's eBlock :S I tried eNoBlock but it just stood still...

I tried setting a timer and move the cloud pixel by pixel according to the timer... still...

here's my code:
Code: ags
function room_RepExec()
{
  SetTimer(1, 20);
  while ( object[0].X > 10 && IsTimerExpired(1))
  {
    object[0].X--;
    if ( object[0].X == 10 )
    {
      object[0].X = 420;
    }
  }
}


I wanted this from the first place:
Code: ags
function room_RepExec()
{
  if ( object[0].X < 420 )
  {
    object[0].Move(18, 90, 10, eNoBlock, eAnywhere);
       if ( object[0].X == 18 )
         {
           object[0].X = 421;
         }
  }
}


it works only when I use eBlock....

Khris

That function is executed 40 times per second so you're starting the timer over and over again.

Something like this should work:

Code: ags
function room_RepExec() {

  if (IsTimerExpired(1)) {
    oCloud.X--;
    if (oCloud.X <= 10) oCloud.X = 420;
    SetTimer(1, 20);
  }
}


Now put another "SetTimer(1, 20);" in the room's before or after fadein.

Another way:
Code: ags
function room_RepExec() {

  if (oCloud.X == 420) {
    oCloud.X = 419;
    oCloud.Move(18, 90, 10, eNoBlock, eAnywhere);
  }
  else if (oCloud.X == 18) oCloud.X = 420;
}


I used oCloud instead of object[0]; in room scripts, you can use an object's script name.

AnasAbdin

thanx man, the trick was here

Code: ags
 oCloud.X = 419;


however, the clouds move fast even that the object speed is 1... which is the slowest but not slow enough... I'd like the speed to be much much less than that....

Gilbert

Since AGS V2.72 you can use negative numbers for move speeds (applies to characters and I think it applies to objects as well).
For example, -2 means 1/2 speed (every 2 frames), -3 means 1/3 speed, etc.

Khris

I assume you've used the second way. If you use the Timer instead, you can adjust the speed even more precisely.

AnasAbdin

Quote from: Khris on Mon 08/08/2011 15:00:22
I assume you've used the second way. If you use the Timer instead, you can adjust the speed even more precisely.

Yes, and yes.
I wanted them to move just slowly.. no need for nano precision here  ;)

AnasAbdin

I didn't wanna start another topic for this since it is the same deal...

trying to move an object but I keep getting an error that AGS cannot set the object position while it's moving...

Code: ags
function room_RepExec()
{
if (object[0].X == 250) 
{
  object[0].X = 251;
  object[0].Move(660, 220, -2, eNoBlock, eAnywhere);
}
}


now what's going on? I used the same code in another room ( but moving the object to the other direction) and it worked:
Code: ags
function room_RepExec()
{
if (object[0].X == 250) 
{
  object[0].X = 249;
  object[0].Move(-10, 220, -2, eNoBlock, eAnywhere);
}
}


???

Khris

Try 252 instead of 251.

251 might get "rounded down" to 250 (because the object is placed at 251/2 internally, which is the same as 250/2 = 125), so the first line is called again when the object is already moving.

In the other room it works because 249/2 is 124 and thus not 250/2.

The problem is the way AGS handles the coordinates in your game; recent versions of AGS started supporting native, pixel-perfect coordinates throughout the game, but highres games used to use lowres coords internally so e.g. an Object could only be placed at even coordinates.

AnasAbdin

worked like a charm :)
Khris... Sie sind DER Mann...  :D

SMF spam blocked by CleanTalk