Image flip script
Janne

Hi,
does anyone have simple script for memory game card flip?

All 3 Comments
Gio

Hi

If I understand what you mean, I believe you can almost fake a 3d rotation (the card flipping) by animating its width: it shrinks, you switch images, then it expands again.

Something along the lines of this:

// in the onAddToScene function:
    this.originalSize = this.getSprite().getSize();
    this.flipState = 0;



// add a flip function to your card object and paste this
    var self = this;
    this.listenFor('onUpdate');
    this.onUpdate = function()
    {
        var size = self.getSprite().getSize();
        switch (self.flipState)
        {
            case 0:
                self.getSprite().setSize(size.x * 0.9, size.y);
                if (size.x < 2)
                {
                    self.flipState = 1;
                    self.getSprite().setImageFile('card_front.png');
                }
                break;
            case 1:
                var newWidth = size.x * 1.1;
                if (newWidth >= self.originalSize.x)
                {
                    newWidth = self.originalSize.x;
                    self.flipState = 2;
                 }
                self.getSprite().setSize(newWidth, size.y);
                break;
        }
    };

 

Shri

Gio,

Why not use the resizeOverTime() with a callback.

Do you not recommend using the wade draw functions anymore ? I have noticed some calls give warnings/errors with the new webgl stuff

cheers,

Shri

Gio

Yes resizeOverTime() is OK, you could do that as well. The effect would be a bit different because that is linear, this one isn't. But it would probably be OK anyway.

Some special draw functions won't work in webgl mode (gradients and vector stuff) because they are canvas-based, but that doesn't mean you cannot use the ones that do work. Or use all of them on a canvas layer :) This particular one (resizeOverTime) will work in both webgl and canvas mode.

We are working on an entirely different (and much easier) way of doing these things now anyway, hopefully I'll be able to reveal more details soon.

Post a reply
Add Attachment
Submit Reply
Login to Reply