mirror of
https://github.com/photonstorm/phaser
synced 2024-12-04 02:20:23 +00:00
d583b364bd
Game.add.bitmapData now has the addToCache parameter. If set the texture will be stored in Game.Cache and can be retrieved with Cache.getBitmapData(key).
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
|
|
var game = new Phaser.Game(800, 600, Phaser.WEBGL, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
|
|
|
function preload() {
|
|
|
|
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
|
|
|
}
|
|
|
|
var mushroom;
|
|
var texture;
|
|
var image;
|
|
|
|
function create() {
|
|
|
|
texture = game.add.renderTexture('mousetrail', 800, 600);
|
|
|
|
// We create a sprite (rather than using the factory) so it doesn't get added to the display, as we only need its texture data.
|
|
mushroom = new Phaser.Sprite(game, 0, 0, 'mushroom');
|
|
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.
|
|
image = game.add.image(0, 0, texture);
|
|
|
|
game.input.onDown.add(tint, this);
|
|
|
|
}
|
|
|
|
function tint() {
|
|
|
|
image.tint = Math.random() * 0xFFFFFF;
|
|
|
|
}
|
|
|
|
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.
|
|
texture.render(mushroom, game.input.activePointer.position, false);
|
|
}
|
|
|
|
}
|
|
|
|
function render() {
|
|
|
|
}
|