Using sprite maps with CAAT: getRef, spriteIndex and WebGL

39 views
Skip to first unread message

Arne Brutschy

unread,
Jul 12, 2013, 4:39:58 AM7/12/13
to caa...@googlegroups.com
Hello,

we're using sprite maps with CAAT: on startup, we load a 2048x2048px map
with the preloader and initialize it using the initializeFromMap
function. Works like a charm.

In order to use the sprites of the map, we would need to do something
along these lines:

var sprite = spriteMap.getRef().setSpriteIndex('name');
var actor = new CAAT.Actor();
actor.setBackgroundImage(sprite, false);
actor.setSize(sprite.getWidth(), sprite.getHeight());

This is obviously quite uncomfortable. Preferably, one would use
something like this:

var actor = new CAAT.Actor();
actor.setBackgroundImage(spriteMap.setSpriteIndex('name'), true);

Unfortunately, this does not work because setBackgroundImage calls
getRef(), which does not copy the spriteIndex of the image.

We fixed this by copying the spriteIndex in getRef() as well. We can now
use the spritemap as describe above, which is really efficient.

Unfortunately, we just realized that this breaks WebGL - bad. When using
WebGL, the canvas remains black and we get the following output on the
console:

> WebGL: INVALID_VALUE: vertexAttribPointer: bad size, stride or offset index.html:1
> WebGL: INVALID_OPERATION: uniformMatrix4fv: location is not from current program

and a whole lot of console messages as follows:

> ["Imagen ", "file:///[somesprite].png", " de tamano ", [width], [height], " no cabe."] Constants.js

What is going wrong here? Why does copying spriteIndex in getRef() work
fine in canvas, but breaks WebGL? And, if copying spriteIndex is not
possible: how can we change CAAT that using spritemaps becomes feasible?
In the current form it's just very inefficient to use.

Regards,
Arne

hyperandroid

unread,
Jul 14, 2013, 4:18:01 AM7/14/13
to caa...@googlegroups.com
Into this already.
Thanks.
--
You received this message because you are subscribed to the Google Groups "CAAT javascript framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caatjs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Arne Brutschy

unread,
Jul 15, 2013, 1:35:14 AM7/15/13
to caa...@googlegroups.com

Awesome, thanks! I feared that I didn't get my point across. If I can
help with anything (testcase or similar), let me know.

Arne

On Sun, 14 Jul 2013 01:18:01 -0700 hyperandroid
<hypera...@gmail.com> wrote:
> Into this already.
> Thanks.
>
> On Friday, July 12, 2013, Arne Brutschy wrote:
>
> > Hello,
> >
> > we're using sprite maps with CAAT: on startup, we load a
> > 2048x2048px map with the preloader and initialize it using the
> > initializeFromMap function. Works like a charm.
> >
> > In order to use the sprites of the map, we would need to do
> > something along these lines:
> >
> > var sprite = spriteMap.getRef().**setSpriteIndex('name');
> > var actor = new CAAT.Actor();
> > actor.setBackgroundImage(**sprite, false);
> > actor.setSize(sprite.getWidth(**), sprite.getHeight());
> >
> > This is obviously quite uncomfortable. Preferably, one would use
> > something like this:
> >
> > var actor = new CAAT.Actor();
> > actor.setBackgroundImage(**spriteMap.setSpriteIndex('**name'),
> > https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> .
> >
> >
> >
>


Reply all
Reply to author
Forward
0 new messages