代号One - ReplaceAndWait()不起作用?

时间:2017-12-02 01:49:29

标签: android ios codenameone

此问题与我之前的问题" Codename One - Transition from FormA to FormB to FormC"有关。

我花了很多时间尝试在Form之间进行转换,但在真实设备上没有成功(在模拟器上没有问题)。最后,我选择更改逻辑,将三个Form之间的转换替换为替换同一Form中的三个Container。想法是ReplaceAndWait()方法确保它等待替换的结束。但是......在这种情况下,代码在Codename One模拟器(使用Android和iOS皮肤)中运行良好,并且不适用于真实设备。更清楚的是:没有"淡化效果"在真实设备上(在Android 4.x和5.x上测试)。以下代码有什么问题?

from random import randrange

import pygame as pg


class Platform(pg.sprite.Sprite):

    def __init__(self, x, y, width, height):
        super().__init__()
        self.image = pg.Surface((width, height))
        self.image.fill(pg.Color('dodgerblue1'))
        self.rect = self.image.get_rect(topleft=(x, y))


def main():
    screen = pg.display.set_mode((640, 480))
    clock = pg.time.Clock()
    all_sprites = pg.sprite.Group()  # This group that will contain all sprites.
    # You probably want to add the platforms to a separate
    # group as well, so that you can use it for collision detection.
    platforms = pg.sprite.Group()

    for _ in range(6):  # Create six platforms at random coords.
        platform = Platform(randrange(600), randrange(440), 170, 20)
        platforms.add(platform)
        all_sprites.add(platform)

    done = False

    while not done:
        for event in pg.event.get():
            if event.type == pg.QUIT:
                done = True

        all_sprites.update()

        screen.fill((30, 30, 30))
        all_sprites.draw(screen)

        pg.display.flip()
        clock.tick(30)


if __name__ == '__main__':
    pg.init()
    main()
    pg.quit()

1 个答案:

答案 0 :(得分:1)

这在设备上对我有用:

    Form f = new Form("Fade", new BorderLayout());

    Container container1 = BorderLayout.center(FlowLayout.encloseCenterMiddle(new Label(duke)));

    Container container2 = BorderLayout.center(FlowLayout.encloseCenterMiddle(new Label(" ")));

    Label redDuke = new Label(duke);
    redDuke.getUnselectedStyle().setBgColor(0xff0000);
    redDuke.getUnselectedStyle().setBgTransparency(255);

    Container container3 = BorderLayout.center(FlowLayout.encloseCenterMiddle(redDuke));

    f.add(CENTER, container1);
    f.show();

    callSerially(() -> {
        container1.getParent().replaceAndWait(container1, container2, CommonTransitions.createFade(2000));
        container2.getParent().replaceAndWait(container2, container3, CommonTransitions.createFade(1000));
    });

但由于在设备上使用不同的淡入淡出方式,因此它在模拟器上的工作方式并不完全正确。为了提高效率,在设备和模拟器上实现淡入淡出的方式略有不同,并且某些行为可能会有所不同,特别是对于半透明/透明组件。