Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
RenderTarget on positioned sprite — Gideros Forum

RenderTarget on positioned sprite

totebototebo Member
edited May 2016 in Bugs and issues
This has been bugging me for a while, but not enough to write a post about it. Until now!

What's the correct way of drawing a moved sprite to a RenderTarget?

This, predictably, causes clipping:
local source = Bitmap.new(Texture.new("calm.png"))
source:setPosition(100,100)
 
local rt = RenderTarget.new(source:getWidth(), source:getHeight())
local bmp = Bitmap.new(rt)
rt:draw(source)
stage:addChild(bmp)
This works, but feels cumbersome:
local source = Bitmap.new(Texture.new("calm.png"))
source:setPosition(100,100)
 
local rt = RenderTarget.new(source:getWidth(), source:getHeight())
local bmp = Bitmap.new(rt)
 
local previous_x, previous_y = source:getPosition()
source:setPosition(0,0)
rt:draw(source)
source:setPosition(previous_x,previous_x)
stage:addChild(bmp)
My Gideros games: www.totebo.com

Comments

  • keszeghkeszegh Member
    another cumbersome solution:
    you could have an additional dummy sprite which contains your sprite, and only you move this dummy sprite. then when rendering the sprite itself it won't be moved.

    Likes: totebo

    +1 -1 (+1 / -0 )Share on Facebook
  • antixantix Member
    edited May 2016
    Of course the first example causes clipping because you are trying to draw the graphic outside the RenderTarget.

    The 2nd example whilst working is not very optimal. A better way would be..
    local source = Bitmap.new(Texture.new("ball.png"))
    local rt = RenderTarget.new(source:getWidth(), source:getHeight())
    rt:draw(source)
    local bmp = Bitmap.new(rt)
    bmp:setPosition(100,100)
    stage:addChild(bmp)
    It would be interesting to know how you are actually intending to use the RenderTarget :)
  • totebototebo Member
    Well, I have a game world into which I'm importing a bunch of terrain from Tiled. To save CPU I'm creating one big bitmap of the static terrain (stuff that won't be interacting with anything). I use RenderTarget to do this. Now, while it works, it is still somewhat slow when the level is too large. So I thought I might subdivide the background into segments, which I can show and hide depending on if they're within the visible screen area. It would have been nifty to be able to specify a x and y in the RenderTarget, so I don't have to move the game world around, which prompted my question.

    In this case it would be ok, because the moving around would happen before the game starts. But if I were to do the same with game objects within the game world it might cause issues because I've overridden their setPosition() function.

    You asked. :)

    This is my dream:
    RenderTarget.new(x, y, width, height, filtering)
    My Gideros games: www.totebo.com
  • SinisterSoftSinisterSoft Maintainer
    Can you not have the large render target - but make a new texture region (pointing to the rendertarget) that is drawn to the screen instead. You then just need to change the x,y start positions of the new region as the screen scrolls.
    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
  • totebototebo Member
    edited May 2016
    What an interesting idea. I suppose there wouldn't be a CPU hit because it's only the visible, smaller area, that would use CPU, not the RenderTarget itself? Nice one Sinister, might just do the trick.
    My Gideros games: www.totebo.com
  • SinisterSoftSinisterSoft Maintainer
    You mean the GPU? It should be less than before and better than rendering multiple smaller rendertargets...
    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
  • antixantix Member
    edited May 2016
    The idea from @SinisterSoft would work in theory. However in my experience RenderTarget suffers from the same issue as a normal texture.. Maximum Texture Size. This will cause things to not work with older devices.

    So why not just use the provided TileMap renderer? It seems to me to be terribly fast. Am I missing something? When you say "it's slow" do you mean with your current RenderTarget system, or the provided TileMap renderer?
Sign In or Register to comment.