Features

Coding convention.

EasySprite.js use camelCase for identifier names (variables and functions).
The variables in [] are optional.

Screen.

openScreen (id, x, y, width, height)
Opens a new screen according to the specified Width, Height.
Example: OpenScreen ("game", 0, 0,800, 600);

clearScreen(color)
Clear the whole screen with the specified color..
Example: ClearScreen('#000000');

screenWidth()
Returns the current screen width.
Example: var width = screenWidth();

screenHeight()
Returns the current screen height.
Example: var height = screenHeight();

Sprite.

createSprite(width, height, color, [onReady], [onClick])
Create new sprite.
Example: var square = createSprite(300, 200, "rgba(255, 255, 255, 1)", onLoadSuccess);

loadSprite(fileName, [onReady], [onClick])
Load the specified sprite.
Example: background = LoadSprite("assets/image/blur1.jpg", onLoadSuccess);

copySprite(sprite)
Copy the sprite1 to sprite2.
Example: sprite2 = copySprite(sprite1);

clipSprite (sprite, x, y, width, height)
Adds a clip zone to the specified sprite.

rotateSprite (sprite, angle, loop)
Rotates the specified sprite to the given angle
Example: rotateSprite(logo, 1, true)

opacitySprite(sprite, opacity)
Set the opacity of a sprite. Between 0.0 and 1.0
Example: opacity(Player, 0.5);

flipSprite (sprite, flipH, flipV)
Flip a sprite horizontally or vertically.

anchorSprite (sprite, x, y)
Change the pivot point of a sprite.
The anchor sets the origin point of the texture. The default is 0,0 this means the textures origin is the top left.
Setting than anchor to 0.5,0.5 means the textures origin is centered.
Setting the anchor to 1,1 would mean the textures origin points will be the bottom right.

spritePosition (sprite, x, y)
Moves sprite to the x and y coordinates.

spriteVelocity (sprite, x, y)
Adding velocity to a sprite.

displaySprite(sprite, x, y, [width], [height])
Display a sprite.

removeSprite(sprite)
Remove sprite from screen.

spriteCollision(sprite1, sprite2)
Tests if the two sprites are overlapping.

scrollSprite(sprite, x, y, stepX, stepY, width, height)
Scroll a sprite horizontally and / or vertically.

startDrawing(sprite)
Change the current drawing output to the specified output. Graphics will be rendered directly on the Sprite.

stopDrawing()
This function must be called to finish the drawing.

Animation.

addAnimation(sprite, animation, frame, frameWidth, frameHeight, frameRate)
Add an animation.
example: addAnimation(coin, "animcoin", [0,1,2,3,4,5,6,7,8,9], 100, 100, 50);

playAnimation (sprite, animation)
Play animation
Example: playAnimation(player, "walk"

animationActive(sprite, animation)
Tests if the animation is active : true ou false

Text.

displayText (text, x, y, font, size, color)
Display a text.
Example: displayText("Make with S2D.js", 30, 30, "Arial", 18, "Red")

Sound.

loadSound(fileName)
Load a sound.
Example: var sound = loadSound('assets/sound/yeah.mp3');

soundVolume(sound, volume)
Adjusts volume between 0.0 and 1.0.
Example: soundVolume(sound, 0.8);

playSound(sound, loop)
Play sound.
Example: playSound(sound);

pauseSound(sound)
Pause sound.

soundLength(sound)
Size of a sound

soundPosition (sound, position)
Returns the current pattern position of the playing music.

Keyboard.

initKeyboard()
Initializes the keyboard environment.

keyboardPushed()
Checks if the specified key is pressed..

keyboardReleased()
Checks if the specified key has been pushed and released.

×

List of available keys

KEY_BACKSPACE = 8
KEY_TAB = 9
KEY_ENTER = 13
KEY_SHIFT = 16
KEY_CTRL = 17
KEY_ALT = 18
KEY_PAUSE = 19
KEY_CAPSLOCK = 20
KEY_ESCAPE = 27
KEY_PAGEUP = 33
KEY_PAGEDOWN = 34
KEY_END = 35
KEY_HOME = 36
KEY_LEFT = 37
KEY_UP = 38
KEY_RIGHT = 39
KEY_DOWN = 40
KEY_INSERT = 45
KEY_DELETE = 46
KEY_0 = 48
KEY_1 = 49
KEY_2 = 50
KEY_3 = 51
KEY_4 = 52
KEY_5 = 53
KEY_6 = 54
KEY_7 = 55
KEY_8 = 56
KEY_9 = 57

KEY_A = 65
KEY_B = 66
KEY_C = 67
KEY_D = 68
KEY_E = 69
KEY_F = 70
KEY_G = 71
KEY_H = 72
KEY_I = 73
KEY_J = 74
KEY_K = 75
KEY_L = 76
KEY_M = 77
KEY_N = 78
KEY_O = 79
KEY_P = 80
KEY_Q = 81
KEY_R = 82
KEY_S = 83
KEY_T = 84
KEY_U = 85
KEY_V = 86
KEY_W = 87
KEY_X = 88
KEY_Y = 89
KEY_Z = 90
KEY_LEFTWINDOW = 91
KEY_RIGHTWINDOW = 92
KEY_SELECT = 93
KEY_NUMPAD0 = 96
KEY_NUMPAD1 = 97
KEY_NUMPAD2 = 98
KEY_NUMPAD3 = 99
KEY_NUMPAD4 = 100
KEY_NUMPAD5 = 101
KEY_NUMPAD6 = 102
KEY_NUMPAD7 = 103
KEY_NUMPAD8 = 104
KEY_NUMPAD9 = 105
KEY_MULTIPLY = 106
KEY_ADD = 107
KEY_SUBTRACT = 109
KEY_DECIMALPOINT = 110
KEY_DIVIDE = 111
KEY_F1 = 112
KEY_F2 = 113
KEY_F3 = 114
KEY_F4 = 115
KEY_F5 = 116
KEY_F6 = 117
KEY_F7 = 118
KEY_F8 = 119
KEY_F9 = 120
KEY_F10 = 121
KEY_F11 = 122
KEY_F12 = 123

KEY_NUMLOCK = 144

EasySprite.js

Mouse.

initMouse([hide])
Initializes the mouse environment.
If hide is true, the mouse cursor is hidden.
See example : 08 - Hide mouse.html

mouseX()
Returns the actual mouse 'x' position (in pixels) on the current screen

mouseY()
Returns the actual mouse 'y' position (in pixels) on the current screen

mouseButton()
Returns true if a click is detected.

mouseState()
Returns true if a mouse button is pressed.

Debug.

debugScreen([x], [y])
Debug screen.

debugSprite(sprite, [x], [y])
Debug a sprite.