Skip to main content

News

Topic: Camera Moving (Read 3668 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
Camera Moving
Have everything set up, just can't seem to get the camera to slowly move into position.
Instead it wants to jump right to the coordinates, rather than slide to them.

Code: (javascript) [Select]
 for (var i = 0; i < 24;){SetCameraY(GetCameraY()-1); while(TimeCatch + 100 > GetTime()){ ++i;}} 


To me, this reads:
1.) For as long as i = 0, then keep performing the for-loop until i is no longer less than 24 pixels
2.) As long as i is less than 24, Set the Camera -1 in pixels every 100ms
3.) While 100ms in time is added, i is added a +1.

Meaning: the Camera should move -1 on the Y-axis every 100msecs, correct?
Instead it only moves -1 once, then stops.
For all the other scripts I implemented, the camera just instantly jumps 24 pixels

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: Camera Moving
Reply #1
If that is intended to run real-time in an update script you can't use blocking code. And you need to reset the clock like so:

Code: (javascript) [Select]

// an if causes this to merely be checked rather than wait for it to be true
if (TimeCatch + 100 < GetTime()) {
    ++i;
    TimeCatch = GetTime(); // so it can get ready for the next 100 ms.
}


Once you have that working you might want to upgrade to a tweening library which is used to move stuff around over time or some delta.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: Camera Moving
Reply #2
Quote from: Radnen link=topic=173.msg2018#msg2018 date=
Once you have that working you might want to upgrade to a tweening library which is used to move stuff around over time or some delta.
[/quote


Scenario has a tweener built in, just putting that out there. :)
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub