Good Vibrations

Started by Baron, Wed 03/11/2010 12:47:07

Previous topic - Next topic

Baron

Basically I like to name technical threads after oldie songs to get them stuck in programmers' brains.

But my ulterior motive is to stop my NPC from vibrating.  The NPC is usually perched on the GUI, but when I have a scrolling room he vibrates when I update his coordinates using the room's repeatedly execute:

Code: ags

  if (cPlayer.Moving){
cFrog.y = GetViewportY () +488;
  }


Note -the room only scrolls vertically and the vibrations only occur vertically. 

     It appears as if the NPC's coordinates are not updated every game cycle, since he vibrates in the opposite direction of the players movement.  Thus, when the player walks down, the NPC appears to bounce upwards (anywhere from 1 to 5 pixels), then snap back into position, then immediately start moving again (technically it's the viewport moving and he is stationary, then snapping back into relative position).  When the player moves up he bounces down.  I've slowed the game speed down massively to observe this.  It's not the player.Moving condition because when I remove that the effect is unchanged.  Can it be that GetViewport is not updated every game cycle?  I suppose the viewport must be dependent on character.y, so delayed frames in the walkcycle might make it look choppy, but setting all delays to 0 makes no difference either.  Really, if the viewport is moving and the NPC is stationary momentarily, then it's repeatedly execute that might not be repeatedly executing, but that seems very unlikely.  So I'm stuck on this -anyone got any ideas?

GarageGothic

Instead of using the built-in scrolling, call SetViewport from rep_exec to scroll the screen based on player character coordinates (or use the smooth scrolling module). That should keep it in sync as long as you update the NPC coordinates *after* you've moved the viewport.

Baron

Yes, this is the pace I work at.   ::)

Anyway, thanks for the quick reply GG.  Your solution definitely keeps the NPC locked in place, but an unanticipated side-effect is that the background vibrates slightly when my main character walks at a steep angle.  I think it has to do with the uneven frame delay in the walk-cycle.  I've browsed through the module you recommended and that seems overly complex for what is the only scrolling room in my game.  I think the solution for me is going to be some combination of clever plot editing and controlled viewport panning using your method -not full scrolling.

Thanks!

SMF spam blocked by CleanTalk