Strange behavior when creating instances

Discussion and feedback on Construct 2

Post » Wed Oct 22, 2014 9:35 am

I intend to create 32 (numberBlocks) instances of a sprite with random frames, but sometimes are created 29, 30, 31instances. The rest of the script is okay.

I have attached a print below. What could be wrong? Thanks.

Image
imgur
Last edited by RBuster on Wed Oct 22, 2014 11:22 pm, edited 3 times in total.
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Post » Wed Oct 22, 2014 5:44 pm

Nothing's wrong from the look of it. Is numbers.Count not equal to 32 after the loop?
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Wed Oct 22, 2014 9:10 pm

Hi @R0J0hound

Sometimes only. Most often 30 or 31. I tried to put the value directly instead of variable and the same thing happens.
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Post » Wed Oct 22, 2014 9:11 pm

Post a minimal example.
ImageImageImage
B
71
S
22
G
249
Posts: 3,762
Reputation: 138,575

Post » Wed Oct 22, 2014 11:25 pm

@blackhornet / @R0J0hound
You do not have the required permissions to view the files attached to this post.
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Post » Thu Oct 23, 2014 2:06 am

I'd say there are two things going wrong here.
1) it's a bit unreasonable to generate 32 physics objects on top of the same location and not expect some problems
2) Box2D web seems to definitely have trouble with this, locking the objects at odd locations.

If you switch to Box2D asm.js, as the engine, it actually works better.

(Also you need to get rid of the one object that is already in the layout, to control generating specific numbers.)
You do not have the required permissions to view the files attached to this post.
ImageImageImage
B
71
S
22
G
249
Posts: 3,762
Reputation: 138,575

Post » Thu Oct 23, 2014 10:56 am

Hi @blackhornet

blackhornet wrote:I'd say there are two things going wrong here.
1) it's a bit unreasonable to generate 32 physics objects on top of the same location and not expect some problems


I change it only in the example. In the real project I generate the squares in randomly Y positions

blackhornet wrote:2) Box2D web seems to definitely have trouble with this, locking the objects at odd locations.

If you switch to Box2D asm.js, as the engine, it actually works better.

(Also you need to get rid of the one object that is already in the layout, to control generating specific numbers.)


I changed the physics engine to Box2D asm.js and I think the problem is gone, but I tested your capx too and least squares is being generated (21 on average instead of 32). Why?

A last doubt: I tested the game on mobile and I saw that the movements of the squares is slow. It is because of physics behavior, right? Is there any way to optimize this? Thanks in advance.
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Post » Thu Oct 23, 2014 6:05 pm

It does create 32 objects in the loop, every time. The ones you don't see on screen are off screen, they were pushed there by the physics collision resolution. Notice how the sprites stack vertically before spreading horizontally. The two best things you can do is not create the objects on top of each other and make the walls thicker so it's harder for the objects to be pushed through the walls. Also enabling "bullet" in the physics properties may help. It could also be that some of the blocks are falling out over the side walls since there is no top wall.

Edit:
If you're on not getting 60 fps on mobile then physics will go slower. You can change the "stepping mode" to "framerate independent" to fix that. By default "fixed" is used because it makes physics simulations more stable. That just means that instead of dt being used, 1/60 is.
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Thu Oct 23, 2014 7:43 pm

Hi @R0J0hound

Top wall is a good solution to prevent the blocks falling out. In this way and changing the the physics engine to Box2D asm.js, now I have 32 squares on the screen.

I enabled the bullet option in the physics properties and the movement is smoother. I like it, but instead of 32 now always appears 28 (remembering that I decreased the thickness of the walls and added one on top).

Edit: Bullet option enabled is better for mobile?
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 11 guests