Last active
December 13, 2021 00:56
-
-
Save kidGodzilla/e417cba4d60ae21fc193f6ec27889948 to your computer and use it in GitHub Desktop.
Demonstrates how to load an external sprite into the game client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Register an external sprite, CORS headers required for images | |
game.loadSprite('skeletonplayer', { | |
"id": "skeletonplayer", | |
"width": 48, | |
"height": 48, | |
"filepath_1": "http://filestore.b-cdn.net/skeleton_1.png", | |
"filepath_2": "http://filestore.b-cdn.net/skeleton_2.png", | |
"filepath_3": "http://filestore.b-cdn.net/skeleton_3.png", | |
"animations": { | |
"atk_right": { | |
"length": 3, | |
"row": 0 | |
}, | |
"walk_right": { | |
"length": 4, | |
"row": 1 | |
}, | |
"idle_right": { | |
"length": 2, | |
"row": 2 | |
}, | |
"atk_up": { | |
"length": 3, | |
"row": 3 | |
}, | |
"walk_up": { | |
"length": 4, | |
"row": 4 | |
}, | |
"idle_up": { | |
"length": 3, | |
"row": 5 | |
}, | |
"atk_down": { | |
"length": 3, | |
"row": 6 | |
}, | |
"walk_down": { | |
"length": 4, | |
"row": 7 | |
}, | |
"idle_down": { | |
"length": 3, | |
"row": 8 | |
} | |
}, | |
"offset_x": -16, | |
"offset_y": -20 | |
}); | |
// Todo: We need to send a message to all connected players and all future connected players to load the sprite. | |
// Switch the player's game character to the new sprite | |
game.player.setSprite(game.sprites.skeletonplayer); | |
// Same thing, local image via fqdn | |
game.loadSprite('skeletonplayer2', { | |
"id": "skeletonplayer2", | |
"width": 48, | |
"height": 48, | |
"filepath_1": "http://browserquest.appdeck.co/img/1/skeleton2.png", | |
"filepath_2": "http://browserquest.appdeck.co/img/2/skeleton2.png", | |
"filepath_3": "http://browserquest.appdeck.co/img/3/skeleton2.png", | |
"animations": { | |
"atk_right": { | |
"length": 3, | |
"row": 0 | |
}, | |
"walk_right": { | |
"length": 4, | |
"row": 1 | |
}, | |
"idle_right": { | |
"length": 2, | |
"row": 2 | |
}, | |
"atk_up": { | |
"length": 3, | |
"row": 3 | |
}, | |
"walk_up": { | |
"length": 4, | |
"row": 4 | |
}, | |
"idle_up": { | |
"length": 3, | |
"row": 5 | |
}, | |
"atk_down": { | |
"length": 3, | |
"row": 6 | |
}, | |
"walk_down": { | |
"length": 4, | |
"row": 7 | |
}, | |
"idle_down": { | |
"length": 3, | |
"row": 8 | |
} | |
}, | |
"offset_x": -16, | |
"offset_y": -20 | |
}); | |
// Switch player to skeletonplayer2 | |
game.player.setSprite(game.sprites.skeletonplayer2); | |
// Saitama (But he's too big) | |
game.loadSprite('saitama', { | |
"id": "saitama", | |
"width": 48, | |
"height": 48, | |
"filepath_1": "http://filestore.b-cdn.net/saitama_x.png", | |
"filepath_2": "http://filestore.b-cdn.net/[email protected]", | |
"filepath_3": "http://filestore.b-cdn.net/[email protected]", | |
"animations": { | |
"atk_right": { | |
"length": 11, | |
"row": 1 | |
}, | |
"walk_right": { | |
"length": 11, | |
"row": 1 | |
}, | |
"idle_right": { | |
"length": 11, | |
"row": 1 | |
}, | |
"atk_up": { | |
"length": 11, | |
"row": 2 | |
}, | |
"walk_up": { | |
"length": 11, | |
"row": 2 | |
}, | |
"idle_up": { | |
"length": 11, | |
"row": 2 | |
}, | |
"atk_down": { | |
"length": 11, | |
"row": 0 | |
}, | |
"walk_down": { | |
"length": 11, | |
"row": 0 | |
}, | |
"idle_down": { | |
"length": 11, | |
"row": 0 | |
} | |
}, | |
"offset_x": -16, | |
"offset_y": -20 | |
}); | |
game.player.setSprite(game.sprites.saitama); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just paste one of these in the console