Ads keep us online. Without them, we wouldn't exist. We don't have paywalls or sell mods - we never will. But every month we have large bills and running ads is our only way to cover them. Please consider unblocking us. Thank you from GameBanana <3

How to move the game window Psych LUA - A Tutorial for Friday Night Funkin'.

Updates

AdditionAdded skopdev credits
OverhaulRevamped the code with help from skop! Now it will run smoothly instead of moving on a step basis
FeatureMade the dancing easier to toggle with a local variable.
AdjustmentProbably something else, idk

AdjustmentChanged a curStep to a 1000

Wait, you can do that?

This tutorial will teach you how to make your window dance, like this!



If you have any questions, please ask them in the comments so other people can read and learn.

I would not have been able to make this effect as smooths as it is without skopdev!

SETUP

So first off, you will need to set up your script file.

You can put this as a song script (recommended) or something else like an event or a script (in scripts folder).

Now that you have your lua file, you can start coding!

Before we code anything, we need to define two local variables.
These variables being:
local WindowDance = false
local SineElap = 0

Put these on the top of the document.
These will be very important later.

Now we're going to do some "actual" code. We will be coding an onStepHit function. This is so you can decide when the window will dance.
This is coded as:
function onStepHit()
end

This is where you define when this is going to happen. This step is optional but recommended.
Type this inside of the function.
if curStep >= Starting Step and curStep <= Ending Step then
end
Replace Starting Step and Ending Step with the step number you want the window dance to start and stop respectively.
Keep in mind that the ending step is the last step it will be active, not the step it will end on


MOVEMENT

Now it's time for the window movement!
Up to this point your code should look something like this.
function onStepHit()
    if curStep >= Starting Step and curStep <= Ending Step then
    end
end

(It looks like this cause if I were to use a code block it will loop and cause confusion)

First, you should learn how to move the window.
You do this by writing:
setPropertyFromClass('openfl.Lib', 'application.window.x', number)

This code will move the window to somewhere on the x axis (left and right)

Replace number with a number, like 100. We won't keep this number but it's a start to your window dancing journey.

If you replace the x in application.window.x to a y, you can move the window up and down!

Now, remember the local variables we set up?
You are going to make WindowDance true inside of your start and end times like this:
function onStepHit()
    if curStep >= Starting Step and curStep <= Ending Step then
        WindowDance = true
    end
end


To make the window dance stop, you will need to add another if statement under the one we already have.

It will look like this when you're done:
function onStepHit()
    if curStep >= Starting Step and curStep <= Ending Step then
        WindowDance = true
    end
    if curStep == Ending Step + 1 then
        WindowDance = false
    end
end

Now, ending step + 1 isn't what you're going to write. You will however look at the previous if statements ending step and add one onto that and write THAT number into the end.

You will now make an onUpdatePost function with elapsed inside (idk how it works, skop did this part), like this:
function onUpdatePost(elapsed)
end


Inside of this you will put:
SineElap = SineElap + (elapsed * 3)

There is still more code needed in here but we'll come back to it later

You do this by coding:
setPropertyFromClass('openfl.Lib', 'application.window.x', number)

Now, what this will do is that it will set the windows X position to the number you set (number). However, this will just make the window move to one spot. We will fix this later on with some trigonometry. (Don't worry, it's actually pretty simple)

Now, repeat the previous step but replace application.window.x with application.window.y. This will make the window move on the Y axis instead of X.

IMPORTANT

This is an important step for this to work! Do not skip it!
Define an onCreate function like you did earlier with the onStepHit.

Inside of this function, add two variables called windowx and windowy

Now, to define these, you will (inside of the onCreate function) type these lines of code:

windowy = getPropertyFromClass("openfl.Lib", "application.window.y")

windowx = getPropertyFromClass("openfl.Lib", "application.window.x")


I know this might seem pretty advanced so far but I will answer as many questions as I can!


TRIGONOMETRY

Here's the fun part! Trigonometry time!
This is the most advanced part if you don't know how it works but I will guide you though it. (I don't understand how trigonometry works so I can't help you with that)

Now, inside of the onUpdatePost(elapsed) function, you need to code:

if WindowDance == true then
    setPropertyFromClass('openfl.Lib', 'application.window.y', 1000*math.sin(SineElap)/10+windowy)
    setPropertyFromClass('openfl.Lib', 'application.window.x', 1000*math.cos(SineElap)/5+windowx)
end


The 1000 is there to increase the effect, you can change this amount but this is what I use

What this will do is that it takes how long the song has been going on for and transforms the sine wave (math.sin) accordingly. The +windowy and +windowx is to make the window move around it's start position.

FINAL NOTES

Now, the basics are done!
You can modify this code to fit what you want and you don't need to credit, as long as you learnt something, I'm happy!

If you want to see other window modifications you can go to the openFL website.
https://www.openfl.org/learn/npm/api/pages/lime/ui/Window.html

Have fun making people hate you!

If people want, I will post the finished code as a tool.

If there are any grammar mistakes, please tell me
Login or Sign up to access this!
Login or Sign up to access this!

Comments

No comments yet!

Embed

Share banner
Image URL
HTML embed code
BB embed code
Markdown embed code

Credits

Creator
OfficialCB uPic
Coder
Contributor
skopdev
Additional Code

Author

OfficialCB uPicCreator
Login or Sign up to access this!
Login or Sign up to access this!
Login or Sign up to access this!

Game

Login or Sign up to access this!

Category

Sub-category
Coding
Super-category
Modding iconModding

Tags

Details

Difficulty Level
Advanced

Share

  • 28
  • 20.6k
  • 18
Login or Sign up to access this!

More WiPs from Submitter

More Coding Tutorials

arrow_back