Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
texture repeat and scroll — Gideros Forum

texture repeat and scroll

I want to make a bitmap scroll indefinitely through the screen. I saw there is a Texture.REPEAT property in the Texture.new method. But I don't know how to use it.
I tried to offset the anchor point of a bitmap, then the anchor position but to no avail.
Also, how do I extend my bitmap if I want to use a smaller texture that should repeat itself?

Comments

  • piepie Member
    edited February 2019
    @meobeou I think that Texture.REPEAT is used to fill a Mesh, Shape or a Pixel object (which you can extend at your pleasure) with a repeated texture.
    To achieve the infinite scrolling I would go for 2 objects one aside of the other that scroll from the beginning to the end of the screen, then switch position
  • Use a texture that's size is a power of 2. Set the repeat option. Map it to a pixel type sprite, size it whatever you want. Change the position of the texture area within the pixel (your instinct may have been to change the pixel position and to have multiple pixels - like @pie - this is a different way of looking at things).
    -- the setup
    x,y=0,0
    scroll=Pixel.new(myTexture,1,1)
    scroll:setDimensions(100,100) -- you could set this at the beginning, this is just to show you that you can change this dynamically
    -- in the frame event
    x+=1  -- this is just an example
    y+=1  -- ditto!
    scroll:setTexturePosition(x%256,-y%256)

    Likes: pie

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+1 / -0 )Share on Facebook
  • I forgot to say, if you want the whole screen to be covered, just setDimension to the visible screen width and height.

    You can then also...
    stage:setClearColorBuffer(false) -- possibly speed up rendering time
    As you will be covering the entire background, so no need to have it cleared on each frame.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • btw, I use this technique on this game:

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • SinisterSoftSinisterSoft Maintainer
    edited February 2019
    Also, if you want to make a game that scrolls infinitely then there are at least two nice ways to do it:

    Use tilemaps and use the scroll commands to feed in one of the edges or again use tilemaps and use the commands to say it basically loops back to the beginning when out of space. You will have to use mod (%) on your x,y positions so they loop too.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • hgy29hgy29 Maintainer

    Use a texture that's size is a power of 2.

    It is no longer strictly necessary in recent Gideros, if your texture isn't power-of-two sized you can ask gideros to leave it as-is by adding extend=false in texture options table.

    +1 -1 (+3 / -0 )Share on Facebook
  • You learn something new every day. :)

    Likes: Apollo14

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+1 / -0 )Share on Facebook
  • @hgy29 thatt's very handy to know, I'll try to remember! Pretty much all asset packs you buy on the internet have parallax scrolling backgrounds that are stupid sizes like 1821and so on :D
Sign In or Register to comment.