使用电晕SDK的背景无限 [英] Background infinite using corona sdk

查看:105
本文介绍了使用电晕SDK的背景无限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在电晕sdk(无限背景)中滚动背景 我重复使用了两张图片(854x176).

I'm trying to scroll side a background in corona sdk (infinity background) I used two images repeated (854x176).

我尝试了此功能:

 function mov(self, event)
   if self.x < -854 then
     self.x = 854
   else
     self.x = self.x - self.speed
   end
 end

它工作得很好,但问题是重复之间出现小的空白. 有更好的方法吗?

it's working just fine but the problem that a small white space occurred between repetitions. Is there a better way to do this?

推荐答案

一种方法是利用Graphics 2.0 Engine的称为重复填充的功能.

One way of doing this would be to take advantage of Graphics 2.0 Engine's feature called repeating fills.

以下是步骤:

  1. 设置x的默认纹理环绕模式(您也可以对y进行相同操作):

  1. Set the default texture wrapping mode for x (you could do the same for y too):

display.setDefault("textureWrapX", "mirroredRepeat")

包装模式为:

  • " clampToEdge "-(默认)固定填充不会重复
  • "重复"-重复填充,就像并排放置相同的瓷砖一样
  • " mirroredRepeat "-以镜像模式重复填充,每个图块都是其旁边图像的镜像
  • "clampToEdge" - (default) clamped fill won't repeat
  • "repeat" - fill is repeated as if same tiles were placed side by side
  • "mirroredRepeat" - fill is repeated in a mirrored pattern, each tile being a mirror image of the one next to it

创建一个想要背景大小的矩形,例如.全屏

Create a rectangle the size of the background you want to have, eg. full screen

local background = display.newRect(display.contentCenterX, display.contentCenterY, 320, 480)

  • 用背景图片填充显示对象

  • Fill your display object with your background image

    background.fill = {type = "image", filename = "background.jpg"}
    

  • 使用适合您应用的任何方法对其进行动画处理.下面只是一种方法:

  • Animate it using whatever method fits your app. Below's just one way:

    local function animateBackground()
        transition.to(background.fill, {time=5000, x=1, delta=true, onComplete=animateBackground})
    end
    
    animateBackground()
    

    在这里,您只需对background.fill对象的x属性(delta = true)运行过渡,这表明我们宁愿使用x值的更改,而不是最终的最终值

    Here you simply run transition on x property of background.fill object, delta=true indicating that we're rather using changes in x value, not final ending values (see here).

    播放时间x的值,将delta设置为false,使用环绕模式播放,只看它对动画有什么影响.您甚至可能不小心发现了一些很酷的效果,以后可能想用...

    Play with the values for time, x, set delta to false, play with wrapping modes, just to see what effect it has on animation. You might even accidentally discover some cool effect which you might want to use later...

    检查Brent的这本出色的教程索伦蒂诺(Sorrentino),他详细介绍了填充材料.另外,请参阅Graphics-Premium/PatternFill下CoronaSDK中的示例代码.

    Check this excellent tutorial by Brent Sorrentino, who goes through more details on fills. Additionally, see sample code in CoronaSDK under Graphics-Premium/PatternFill.

    完整代码:

    display.setDefault("textureWrapX", "mirroredRepeat")
    
    local background = display.newRect(display.contentCenterX, display.contentCenterY, 320, 480)
    background.fill = {type = "image", filename = "background.jpg" }
    
    local function animateBackground()
        transition.to( background.fill, { time=5000, x=1, delta=true, onComplete=animateBackground } )
    end
    
    animateBackground()
    

  • 这篇关于使用电晕SDK的背景无限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆