subImage vs setOrigin

24 views
Skip to first unread message

dangelo...@gmail.com

unread,
May 20, 2013, 12:28:09 PM5/20/13
to pl...@googlegroups.com
Sorry people i have a map of 3000*3000 (for example) and a screen of 1200*800 and i need the move of this map.
I tryed to use subImage and setOrigin for take the part of the map that i need to show on the screen(each update). Both work obviously...
Now my question is faster make a subimage of 1200,800 (of the 3000*3000 image) and set it to 0,0 of the screen or just setOrigin of my image 3000*3000 for move it.
Thanks

Michael Bayne

unread,
May 20, 2013, 12:46:09 PM5/20/13
to pl...@googlegroups.com
On Mon, May 20, 2013 at 9:28 AM, <dangelo...@gmail.com> wrote:
Sorry people i have a map of 3000*3000 (for example) and a screen of 1200*800 and i need the move of this map.
I tryed to use subImage and setOrigin for take the part of the map that i need to show on the screen(each update). Both work obviously...

Having a texture that's 3000x3000 isn't going to work on mobile devices, so you should be aware that your game will only work on HTML5 desktop browsers (and the Java backend of course).

Now my question is faster make a subimage of 1200,800 (of the 3000*3000 image) and set it to 0,0 of the screen or just setOrigin of my image 3000*3000 for move it.

Basically, they're going to be exactly the same. OpenGL doesn't draw pixels outside the viewport, so the parts of the 3000x3000 quad that are outside the viewport will not be rendered.

However, if you take a naive approach to creating a subimage (i.e. call Image.subImage on every frame), then you'll be generating garbage, which will make that approach slower.

Using the setOrigin approach is probably best, because if you do discover that you want to support mobile devices and split your background image up into tiles, you can just stick those tiles into a GroupLayer and continue to use setOrigin on the group layer to position the background and everything will work exactly the same.

-- m...@samskivert.com

dangelo...@gmail.com

unread,
May 20, 2013, 1:40:47 PM5/20/13
to pl...@googlegroups.com
Perfect thanks for the help, I understand I have to continue to use the setOrigin, it's true?
But the 3000*3000 it was only an example. Because my Render do all.
For example i have an ImmediateLayer called gameLayer that do all.
In this Immediate (in the render) i do this in this order:
    - move the map with setOrigin (the main character stay in the center, only the map move).
    - draw the actual character sprite 
    - add bullet on the map (my character shots sometimes)
My update calculate only the actual sprite of the character and updare the bullet x,y.
For now I don't have groupLayer. 

Michael Bayne

unread,
May 20, 2013, 1:44:30 PM5/20/13
to pl...@googlegroups.com

On Mon, May 20, 2013 at 10:40 AM, <dangelo...@gmail.com> wrote:
In this Immediate (in the render) i do this in this order:
    - move the map with setOrigin (the main character stay in the center, only the map move).
    - draw the actual character sprite 
    - add bullet on the map (my character shots sometimes)

If you're drawing your background image into a Surface (via ImmediateLayer), I don't see what you're calling setOrigin on. The ImmediateLayer? Either way, if things look right, then you're fine.

-- m...@samskivert.com

dangelo...@gmail.com

unread,
May 20, 2013, 1:58:02 PM5/20/13
to pl...@googlegroups.com
You're right, I explained badly, the map is actually a imageLayer NOT drawn on the surface of the render, but under it and is moved each time with the setOrigin inside the render (this part of the code should I put it in the update , making imageLayer global).
Happen to know something about a video or sound in playn?
thanks again ;)
Reply all
Reply to author
Forward
0 new messages