如何在 Flex 4.5 应用程序中使用 MovieClips 补间?

发布于 2024-11-30 22:16:28 字数 1300 浏览 1 评论 0原文

我是 Flex 新手,正在尝试将纯 Flash/AS3 纸牌游戏 移植到弹性 4.5。

它大部分工作得很好,但我在那里遗漏了一些谜题部分:

我创建了一个基于 UIComponent 的自定义组件,表示一副纸牌(它们是 Sprites 或 MovieClip 的数组):

在此处输入图像描述

在最初的纯 Flash/AS3 游戏中,我对桌上的 3 张牌使用了 Tween - 向游戏用户显示谁放了哪张牌(通过将它们滑向打表中间):

import fl.transitions.*;
import fl.transitions.easing.*;

public class Deck extends UIComponent {
    private var _card:Array = new Array(3);
    private var _tween:Array = new Array(3);
            ....

    override protected function createChildren():void {
        _tween[YOU] = new Tween(_card[0], 'y', Regular.easeOut, _card[0].y + 40, _card[0].y, .5, true);
        _tween[LEFT] = new Tween(_card[1], 'x', Regular.easeOut, _card[1].x - 40, _card[1].x, .5, true);
        _tween[RIGHT] = new Tween(_card[2], 'x', Regular.easeOut, _card[2].x + 40, _card[2].x, .5, true);
             ....

但是Flash Builder 4.5似乎根本不知道fl.transitions.*包?

有人对如何使用 有建议吗补间在这里?

就像我写的其余部分(我的自定义 Flex 组件、移动卡片精灵等)效果很好。只有 Tween 行需要注释。

谢谢你! 亚历克斯

I'm new to Flex and am trying to port a pure Flash/AS3 card game to Flex 4.5.

It works mostly well, but I'm missing few puzzle parts there:

I've created a custom component based on UIComponent representing a deck of cards (which are an array of Sprites or MovieClips):

enter image description here

In the original pure Flash/AS3 game I was using Tween for the 3 cards at the table - to show the game user, who has put which card (by sliding them towards playing table middle):

import fl.transitions.*;
import fl.transitions.easing.*;

public class Deck extends UIComponent {
    private var _card:Array = new Array(3);
    private var _tween:Array = new Array(3);
            ....

    override protected function createChildren():void {
        _tween[YOU] = new Tween(_card[0], 'y', Regular.easeOut, _card[0].y + 40, _card[0].y, .5, true);
        _tween[LEFT] = new Tween(_card[1], 'x', Regular.easeOut, _card[1].x - 40, _card[1].x, .5, true);
        _tween[RIGHT] = new Tween(_card[2], 'x', Regular.easeOut, _card[2].x + 40, _card[2].x, .5, true);
             ....

However Flash Builder 4.5 doesn't seem to know fl.transitions.* packages at all?

Does anybody please have an advice on how to use Tween here?

Like I've written the rest (my custom Flex component, moving card-Sprites around, etc.) works well. Only the Tween lines had to be commented.

Thank you!
Alex

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半窗疏影 2024-12-07 22:16:28

查看 Google 代码上的 Tweener 类。使用它,您可以指定对象、其属性及其所需值的映射以及时间,并且它将这些属性从当前值“补间”到所需值。

Tweener.addTween(yourCard, {y:50, time:1});//for a 1 second tween 

Take a look at the Tweener class on Google Code. With it you can specify and object, and a map of its properties and their desired values, along with time, and it will 'tween' those properties from their current to their desired values.

Tweener.addTween(yourCard, {y:50, time:1});//for a 1 second tween 
神回复 2024-12-07 22:16:28

我的第一个下意识反应是将 flash.swc(由 Flash CS Pro 提供)添加到 Flex 构建路径中,然后:

import fl.transitions.*;
import fl.transitions.easing.*;

可以再次使用。

在此处输入图像描述

但从长远来看,我可能会编写自己的函数来移动扑克牌并运行它事件。ENTER_FRAME。因为我不想仅仅为了卡片滑动而包含 Tweener 或 Tweenlite 库。

        _tween[0] = _card[0].y;
        _tween[1] = _card[1].x;
        _tween[2] = _card[2].x;
                ....
        _card[0].y = _tween[0] + 20;
        addEventListener(Event.ENTER_FRAME, slideCardYou);

        _card[1].x = _tween[1] - 20;
        addEventListener(Event.ENTER_FRAME, slideCardLeft);

        _card[2].x = _tween[2] + 20;
        addEventListener(Event.ENTER_FRAME, slideCardRight);
                ....

    private function slideCardYou(event:Event):void {
        if (_card[0].y-- < _tween[0]) 
            removeEventListener(Event.ENTER_FRAME, slideCardYou);
    }

    private function slideCardLeft(event:Event):void {
        if (_card[1].x++ > _tween[1]) 
            removeEventListener(Event.ENTER_FRAME, slideCardLeft);
    }

    private function slideCardRight(event:Event):void {
        if (_card[2].x-- < _tween[2]) 
            removeEventListener(Event.ENTER_FRAME, slideCardRight);
    }

我还查看了 mx.effects.Tween 和 Spark.effects.Animate,但它们似乎更适合 UIComponent,而不是像我这样的 Sprites。

My first knee-jerk reaction has been to add flash.swc (delivered by Flash CS Pro) to the Flex build path and then:

import fl.transitions.*;
import fl.transitions.easing.*;

can be used again.

enter image description here

But in the long-term I will probably write my own function to move the playing cards and run it on Event.ENTER_FRAME. Because I don't want to include Tweener or Tweenlite libraries for mere card sliding.

        _tween[0] = _card[0].y;
        _tween[1] = _card[1].x;
        _tween[2] = _card[2].x;
                ....
        _card[0].y = _tween[0] + 20;
        addEventListener(Event.ENTER_FRAME, slideCardYou);

        _card[1].x = _tween[1] - 20;
        addEventListener(Event.ENTER_FRAME, slideCardLeft);

        _card[2].x = _tween[2] + 20;
        addEventListener(Event.ENTER_FRAME, slideCardRight);
                ....

    private function slideCardYou(event:Event):void {
        if (_card[0].y-- < _tween[0]) 
            removeEventListener(Event.ENTER_FRAME, slideCardYou);
    }

    private function slideCardLeft(event:Event):void {
        if (_card[1].x++ > _tween[1]) 
            removeEventListener(Event.ENTER_FRAME, slideCardLeft);
    }

    private function slideCardRight(event:Event):void {
        if (_card[2].x-- < _tween[2]) 
            removeEventListener(Event.ENTER_FRAME, slideCardRight);
    }

Also I've looked at mx.effects.Tween and spark.effects.Animate but they seem to be more appropriate for UIComponents and not Sprites as in my case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文