TextSurface实现文字呈现效果

TextSurface实现文字呈现效果

 

介绍:
TextSurface实现文字呈现效果,TextView字体输入的时候展示的动画效果,类似于PPT的呈现效果。
这个demo可以用在处理字幕子类的效果。

效果截图:

 

项目源码:http://www.itlanbao.com/code/20151210/10000/100685.html

代码结构如下:
首先需要TextSurface.reset()先重置一下,
其他的动画实现主要由类CookieThumperSample实现

public static void play(TextSurface textSurface, AssetManager assetManager) {

  final Typeface robotoBlack = Typeface.createFromAsset(assetManager, "fonts/Roboto-Black.ttf");
  Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setTypeface(robotoBlack);

  Text textDaai = TextBuilder
    .create("Daai")
    .setPaint(paint)
    .setSize(64)
    .setAlpha(0)
    .setColor(Color.WHITE)
    .setPosition(Align.SURFACE_CENTER).build();

  Text textBraAnies = TextBuilder
    .create("bra Anies")
    .setPaint(paint)
    .setSize(44)
    .setAlpha(0)
    .setColor(Color.RED)
    .setPosition(Align.BOTTOM_OF, textDaai).build();

  Text textFokkenGamBra = TextBuilder
    .create(" hy's n fokken gam bra.")
    .setPaint(paint)
    .setSize(44)
    .setAlpha(0)
    .setColor(Color.RED)
    .setPosition(Align.RIGHT_OF, textBraAnies).build();

  Text textHaai = TextBuilder
    .create("Haai!!")
    .setPaint(paint)
    .setSize(74)
    .setAlpha(0)
    .setColor(Color.RED)
    .setPosition(Align.BOTTOM_OF, textFokkenGamBra).build();

  Text textDaaiAnies = TextBuilder
    .create("Daai Anies")
    .setPaint(paint)
    .setSize(44)
    .setAlpha(0)
    .setColor(Color.WHITE)
    .setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textHaai).build();

  Text texThyLamInnie = TextBuilder
    .create(" hy lam innie mang ja.")
    .setPaint(paint)
    .setSize(44)
    .setAlpha(0)
    .setColor(Color.WHITE)
    .setPosition(Align.RIGHT_OF, textDaaiAnies).build();

  Text textThrowDamn = TextBuilder
    .create("Throw damn")
    .setPaint(paint)
    .setSize(44)
    .setAlpha(0)
    .setColor(Color.RED)
    .setPosition(Align.BOTTOM_OF | Align.CENTER_OF, texThyLamInnie).build();

  Text textDevilishGang = TextBuilder
    .create("devilish gang")
    .setPaint(paint)
    .setSize(44)
    .setAlpha(0)
    .setColor(Color.RED)
    .setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textThrowDamn).build();

  Text textSignsInTheAir = TextBuilder
    .create("signs in the air.")
    .setPaint(paint)
    .setSize(44)
    .setAlpha(0)
    .setColor(Color.RED)
    .setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textDevilishGang).build();

  textSurface.play(
    new Sequential(
      ShapeReveal.create(textDaai, 750, SideCut.show(Side.LEFT), false),
      new Parallel(ShapeReveal.create(textDaai, 600, SideCut.hide(Side.LEFT), false), new Sequential(Delay.duration(300), ShapeReveal.create(textDaai, 600, SideCut.show(Side.LEFT), false))),
      new Parallel(new TransSurface(500, textBraAnies, Pivot.CENTER), ShapeReveal.create(textBraAnies, 1300, SideCut.show(Side.LEFT), false)),
      Delay.duration(500),
      new Parallel(new TransSurface(750, textFokkenGamBra, Pivot.CENTER), Slide.showFrom(Side.LEFT, textFokkenGamBra, 750), ChangeColor.to(textFokkenGamBra, 750, Color.WHITE)),
      Delay.duration(500),
      new Parallel(TransSurface.toCenter(textHaai, 500), Rotate3D.showFromSide(textHaai, 750, Pivot.TOP)),
      new Parallel(TransSurface.toCenter(textDaaiAnies, 500), Slide.showFrom(Side.TOP, textDaaiAnies, 500)),
      new Parallel(TransSurface.toCenter(texThyLamInnie, 750), Slide.showFrom(Side.LEFT, texThyLamInnie, 500)),
      Delay.duration(500),
      new Parallel(
        new TransSurface(1500, textSignsInTheAir, Pivot.CENTER),
        new Sequential(
          new Sequential(ShapeReveal.create(textThrowDamn, 500, Circle.show(Side.CENTER, Direction.OUT), false)),
          new Sequential(ShapeReveal.create(textDevilishGang, 500, Circle.show(Side.CENTER, Direction.OUT), false)),
          new Sequential(ShapeReveal.create(textSignsInTheAir, 500, Circle.show(Side.CENTER, Direction.OUT), false))
        )
      ),
      Delay.duration(200),
      new Parallel(
        ShapeReveal.create(textThrowDamn, 1500, SideCut.hide(Side.LEFT), true),
        new Sequential(Delay.duration(250), ShapeReveal.create(textDevilishGang, 1500, SideCut.hide(Side.LEFT), true)),
        new Sequential(Delay.duration(500), ShapeReveal.create(textSignsInTheAir, 1500, SideCut.hide(Side.LEFT), true)),
        Alpha.hide(texThyLamInnie, 1500),
        Alpha.hide(textDaaiAnies, 1500)
      )
    )
  );

 }

 

在C语言中实现人机交互界面通常需要使用图形库,比如常用的图形库有: 1. SDL:Simple DirectMedia Layer,跨平台的多媒体库,可用于游戏和其他图形应用程序。 2. GTK:GIMP Toolkit,一个跨平台的GUI工具包,可用于创建桌面应用程序。 3. Qt:一个跨平台的GUI工具包,可用于创建桌面应用程序。 下面以SDL为例,介绍如何使用C语言实现简单的人机交互界面: 1. 安装SDL库:可以在SDL官网(https://www.libsdl.org/)下载相应的安装包,然后按照指引进行安装。 2. 编写代码:下面是一个简单的SDL程序示例,可以创建一个窗口并显示一个文本标签。 ```c #include <SDL2/SDL.h> int main(int argc, char* argv[]) { SDL_Init(SDL_INIT_EVERYTHING); SDL_Window* window = SDL_CreateWindow("Hello World", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN); SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_RenderClear(renderer); SDL_Color textColor = { 0, 0, 0, 255 }; SDL_Surface* textSurface = TTF_RenderText_Solid(font, "Hello, World!", textColor); SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface); SDL_Rect textRect = { 100, 100, textSurface->w, textSurface->h }; SDL_RenderCopy(renderer, textTexture, NULL, &textRect); SDL_RenderPresent(renderer); SDL_Delay(5000); SDL_DestroyTexture(textTexture); SDL_FreeSurface(textSurface); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_Quit(); return 0; } ``` 3. 编译代码:在命令行中使用gcc或者其他编译器编译代码。 4. 运行程序:在命令行中输入编译生成的可执行文件名,即可运行程序并查看效果。 以上是一个简单的SDL程序示例,实际应用中可以根据需求进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值