HScript: Creating and adding sprites - SlightlySimple/FNF-Restructure-Engine GitHub Wiki
A "sprite" is any type of graphic that appears on the screen, whether it be a simple image, an animation, or a solid block of color. If you want to make something appear in one or a few songs only, make an in-game cutscene like the ones in Week 7, or make your own custom menus, you will be working with sprites.
Sprite Adding Functions
CreateSprite(asset)will create a sprite for you to use.assetis the path, starting in the "images" folder, to an image or spritesheet to be used for your sprite. You will want to assign your sprite to a variable, for examplemySprite = CreateSprite("myImage"). This function also takes optional x and y arguments after theassetargument. These control the position on screen that the sprite starts at.add(sprite)will place the sprite in the stage.spriteis the variable name of the sprite you want to add, so for the example above, you would typeadd(mySprite). By default, this will place the sprite on top of the entire stage including the characters, so you may want to use the next function instead.insert(index, sprite)will place the sprite in the stage, at a specific location in the order of sprites. If, for example, you wanted the sprite to be behind Boyfriend, you would typeinsert(game.members.indexOf(game.player1), mySprite).remove(sprite)will remove the sprite from the stage. Usually, this will leave the slot the sprite was in vacant, so you may want to doremove(mySprite, true)to ensure the slot is completely cleared. Otherwise,addmay try to fill this slot the next time you use it.
These functions won't always use the variable game. They may use this for scripted sprite groups (such as the dialogue box) or FlxG.state for custom menus.
Sprite Variables and Functions
These variables and functions are meant to be ran on the sprites themselves. For example, by doing mySprite.alpha = 0.5 or mySprite.updateHitbox()
xandyare the top-left corner of the sprite. They can both be set at once with the functionsetPosition(x, y).widthandheightare how wide and tall the sprite is, in pixels. They should not be set directly, but can be controlled with the functionsetGraphicSize(width, height).scaleis how much the sprite is stretched or squashed.scale.xcontrols the horizontal stretching, andscale.ycontrols the vertical stretching. They can both be set at once with the functionscale.set(x, y).updateHitbox()updates the sprite's hitbox, fixing it's position and size to account for scaling. It is highly recommended to run this after changing a sprite's scale.scrollFactoris how closely the sprite follows the camera's movement.scrollFactor.xcontrols the horizontal factor, andscrollFactor.ycontrols the vertical factor. They can both be set at once with the functionscrollFactor.set(x, y). You can also type this function as justscrollFactor.set()if you want the sprite to follow the camera perfectly.screenCenterwill place the sprite in the center of the stage. This can also bescreenCenter(X)orscreenCenter(Y)to only center the sprite along one axis.angleis how much a sprite is rotated. Usually, a sprite will be rotated around it's center.coloris what color a sprite is. This can either be aFlxColorentry such asFlxColor.REDor a hexadecimal number such asoxFFFF0000.alphais how transparent, or see-through, a sprite is. It is a range between 0 and 1. 0 means the sprite is invisible.visibleis whether or not the sprite can be seen. It can either betrueorfalse.
Animated Sprite Variables and Functions
These variables and functions pertain specifically to spritesheets that are meant to be animated.
addAnim(name, prefix, fps, loop)will add an animation to the sprite.nameis the animation name as the game recognizes it.prefixis the animation name as it's written in the xml file.fpsis the speed of the animation, in frames per second.loopcontrols whether or not the animation loops infinitely. This function also takes an optional fifth argument, which is a list of numbers controlling which frames of the animation to use.addOffsets(name, offsets)will tell the sprite to use the specific offsets when playing the animation.nameis the name of the animation to affect.offsetsis an array of two numbers that control the x and y offsets of the sprite when playing this animation.playAnim(name)will make the sprite play an animation as defined earlier. This function has the three optional argumentsforce, reverse, frame. Ifforceis true, the animation will return to the beginning even if the sprite is already in the middle of playing it. Ifreverseis true, the animation will play backwards. Ifframeis present, it is a number controlling which frame of the animation to start on.idlesis a list of animations to cycle through on every beat of the song.danceSpeedis how many beats to wait between idles. IfdanceSpeedis 2, the sprite will idle every other beat, for example.