Strange behavior when creating instances

0 favourites
  • 9 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • 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.

    imgur

  • Nothing's wrong from the look of it. Is numbers.Count not equal to 32 after the loop?

  • Hi R0J0hound

    Sometimes only. Most often 30 or 31. I tried to put the value directly instead of variable and the same thing happens.

  • Post a minimal example.

  • 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.)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi blackhornet

    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

    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.

  • 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.

  • 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?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)