Pixi.js: how is scrolling done on flashvhtml.com?
How is page scrolling created on flashvhtml.com ? How is scrolling triggered by the links at the top, and how are the other "below animation" events related to the scrolling background?
source to share
This is what I was able to put together:
- Listeners for interaction are added to the file
Trackpad.js
. Listeners for events such as mouse drag, keyboard events, touch, etc. All of which evaluate to a variablevalue
. - This variable is
value
Trackpad.js
then used to set the positioncamera
in theupdate
main.js
file method . - There are 3 main types that are displayed, if I understand it correctly:
ScrollView
,ScaleView
,RocketView
. All of those are initiated inside the methodinit
main.js
. But they are all defined in the filefvh.js
. - Each of these three views has an
updatePosition
acceptorcamera.y
ormainScrollPosition
as a parameter. These methodsupdatePosition
are called inside the same fileupdate
methodmain.js
. -
Then there is
ScrollMap.js
one that contains loads of position data for all 3 views, for example. it contains dataScrollView
in the format:mcxxx:{view:'nameofelement',depth:xx,startFrame:xxx,endFrame:xxx,position:[xxx,...]}
etc. -
There is also a variable
sectionLandPositions
defined in the filemain.js
, which is also very interesting because this is what is then used inside a methodonMenuItemPressed
in the same file for the tween and brings a specific section into view. -
So the magic mostly happens in the methods
updatePosition
for each view and how the value is calculated inTrackpad.js
. And here I leave you to further debug and take it home. :)
Under the control files: Trackpad.js
, fvh.js
, ScrollMap.js
, main.js
. I hope you find all of this useful.
PS Kudos to Waste-Creative for creating this informative and engaging website.
T
source to share
An easy way to do this is by adding tweens and then using the scroll / drag tab and links to move around the timeline.
- Tween one: Couples Camera slowly down.
- Tween two: Wait for x, sprite in unset state y disappears, sprites disappear, ..
Make sure you don't play animations after creating them, but adjust the timing manually (depending on the scroll position).
There are several tweeing schemes you can use for pixi: Greensocks , Impact , tween.js And there was a discussion on the html5gamedevs forum .
source to share