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

#1

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.

0 Likes

#2

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?

0 Likes

#3

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

0 Likes

#4

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

0 Likes

#5

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

1 Like

#6

Doesn’t work with 3D physics.

0 Likes

#7

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/

11 Likes

#8

Thank you very much

0 Likes