Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by IMBilleh

Hey everyone,

Right now, I'm working on a puzzle game similar to Tetris Attack. However, I'm a bit stuck. I'm making all the Block entities increment up over time by using the vel.y.

Once the blocks have moved up a certain amount, new blocks should be created underneath. I am having difficulty with this part...

At first, I decided that every update, I would increment an index and once it reaches the limit, it would create the new line of blocks and would be put back down to zero. This failed to work because of the way Impact does updates. The number of updates called is very dependent on the device it is run on.

Then, I decided that once the blocks moved a certain number of pixels (based off the velocity), then I could check that way. However, the y-positions of the entities get off after several updates. So even though after three seconds with velocity of 30, the entity should move exactly 90 pixels, it will actually move 89.99850 or 90.99850.

So my question is, how do I handle this problem? How do I ensure that my entities move exactly how I want them to?

P.S.
Just as an added extra because someone might mention it, I also thought of completely removing the automatic update and just update my own positions with the pixel positions I desire, but I run into problems with lagging and not smooth transitions. Impact does very well at keeping the actions smooth, but if you have a better method, by all means, enlighten me =)

1 decade ago by paulh

you could try one of these, although not sure that will solve your actual problem :-)


ig.System.DRAW.AUTHENTIC
ig.System.DRAW.SMOOTH
ig.System.DRAW.SUBPIXEL
The default is SMOOTH.

1 decade ago by jswart

Quote from IMBilleh

At first, I decided that every update, I would increment an index and once it reaches the limit, it would create the new line of blocks and would be put back down to zero. This failed to work because of the way Impact does updates. The number of updates called is very dependent on the device it is run on.


So if I understand you, this is what you were doing:

// ...

	update: function(x, y, settings) {

		if ( counter > num_to_add_new_blocks ) {
			createNewBlocks();
		}

		counter++;
	},

// ...


Instead try using timers to get consistenty.

	newBlockTimer = ig.Timer(),

	init: funciton(x, y, settings) {
		this.newBlockTimer.set(15); // make new blocks in 15 seconds
	},

	update: function(x, y, settings) {

		// if the timer == 0, ie: 15 seconds have passed then add new blocks
		if ( this.newBlockTimer.delta() ) {
			createNewBlocks();
                        this.newBlockTimer.reset() // set timer back to 15
		}
	},


Let me know if that worked, obviously it is also pseudo-code so you will have to build it out.

1 decade ago by IMBilleh

That seemed to work. There is still a slight issue in that when new blocks are created at the bottom, they either overlap just slightly or have a space just slightly. The space is negligible, and appears to be less than a pixel or two.

This is most certainly due to the small error found in the vel.y update calls.

1 decade ago by jswart

Maybe for the velocity issue you can round?

vel = Math.floor(vel); // round down, Math.ceil(vel) - round up
if ( vel === 0 ) {
    vel = 1; // keep velocity from being rounded to 0 over and over and not moving / slowing down
}

On second thought, I'm not sure what the velocity issue is about. Why are you using it if? If you are using the timers then you are creating the blocks after a given period. So you should no longer need to do anything with the velocity.

I wouldn't use velocity either in place of the timer, because as you noticed it increases over time based on acceleration until it reaches maxVelocity.

You should check the position after the given amount of time.


    initPos = this.pos.y;
    // 3 seconds pass
    currPos = this.pos.y;
    if ( currPos - initPos > 90 ) {
        // do stuff
    }


Obviously I don't know everything about your situation. What is the vel.y value used for?

1 decade ago by IMBilleh

I'm speaking of the velocity of the blocks. The blocks are constantly raising every frame.
Page 1 of 1
« first « previous next › last »