Create Dynamic sprites with custom size and collision object (SOLVED)

Hi, I like to create rectangular sprites with dynamic width and add an image on to it.
also, this sprite need to have a collision object and it needs to fit with the sprite’s width and height

my game similar to https://britzl.github.io/Towerz/ and boxes width should be dynamic.

when create an instance using “factory.create(component, p,null, { maxPosition = maxxxPostion,blockSize=52 },vmath.vector3(0.4, 0.4, 1))” function, it should be create new instance according to the blockSize parameter

How I do this? is there any example I can refer.

The problematic part will probably be setting the size of the collision object. You can scale the game object but that will not affect the collision object.

Maybe it can be solved without the built in physics? Or maybe my Chipmunk2d physics extension could be used?

I believe the scaling is respected when used at spawn time?

Yes that’s true! So delete and recreate would work. Good point @Mathias_Westerdahl!

It still only accepts uniform scale though, right? So having dynamic width is not possible.

1 Like

Doesn’t work with 3D physics.

I had an hour and half on flight today and decided to create something very similar to what you asked for. It’s done without any physics or anything and it should be quite easy to adapt.

CODE: https://github.com/britzl/stackem
DEMO: https://britzl.github.io/stackem/

12 Likes

Thank you very much