mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 15:12:18 +00:00
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
|
|
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
|
|
|
|
function preload() {
|
|
|
|
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
|
|
|
}
|
|
|
|
var mushroom;
|
|
var texture;
|
|
|
|
function create() {
|
|
|
|
// Here we'll create a renderTexture the same size as our game
|
|
texture = game.add.renderTexture('mousetrail', 800, 600);
|
|
|
|
// This is the sprite that will be drawn to the texture, we set it to visible false as we only need its texture data
|
|
mushroom = game.add.sprite(0, 0, 'mushroom');
|
|
mushroom.visible = false;
|
|
mushroom.anchor.setTo(0.5, 0.5);
|
|
|
|
// This is the sprite that is drawn to the display. We've given it the renderTexture as its texture.
|
|
game.add.sprite(0, 0, texture);
|
|
|
|
}
|
|
|
|
function update() {
|
|
|
|
if (!game.input.activePointer.position.isZero())
|
|
{
|
|
// Here we draw the mushroom sprite to the renderTexture at the pointer coordinates.
|
|
// The 'false' parameter 2nd from the end tells it not to clear itself, causing the trail effect you see.
|
|
// The final 'true' parameter tells it to render sprites even with visible false set.
|
|
texture.render(mushroom, game.input.activePointer.position, false, true);
|
|
}
|
|
|
|
}
|