Flixel Forums

development => help => Topic started by: flabby_fabby on Thu, Dec 1, 2011

Title: moving a block help
Post by: flabby_fabby on Thu, Dec 1, 2011
When the player pushes the block it doesn't stop moving. How would I add friction?


Code: [Select]
package 
{
import org.flixel.*;

public class block extends FlxSprite
{
[Embed(source = '../assets/block_img.png')] private var blockPNG:Class;

public function block(X:Number,Y:Number)
{
super(X * 8, Y * 8, blockPNG);
acceleration.y = 400;
}

}

}
Title: Re: moving a block help
Post by: flabby_fabby on Thu, Dec 1, 2011
I found that i can use Drag. WOOP WOOP!!  ;)

The only problem I have now is when the player is on the edge of the block and changes direction, the block also moves.

Any ideas???
Title: Re: moving a block help
Post by: test84 on Thu, Dec 1, 2011
I think we need to see more code in order to reply to that one.
Title: Re: moving a block help
Post by: flabby_fabby on Thu, Dec 1, 2011
block.as

Code: [Select]
package   
{
   import org.flixel.*;
   import org.flixel.plugin.photonstorm.*;
   
   public class block extends FlxSprite
   {
      [Embed(source = '../assets/block_img.png')] private var blockPNG:Class;
     
      public function block(X:Number,Y:Number)
      {
         super(X * 8, Y * 8, blockPNG);
         immovable = false;
         moves = true;
         acceleration.y = 400;
         drag = new FlxPoint(100, 0);
      }
   }

}

PlayStase.as update();

Code: [Select]
override public function update():void
      {
         super.update();
         
         FlxG.collide(player, level);
         FlxG.collide(level, level);
      }

http://www.swfcabin.com/swf-files/1322757822.swf


(press up to jump)
Title: Re: moving a block help
Post by: test84 on Thu, Dec 1, 2011
I can't see the actual swf in action, due to my Internet problem but I can safely assume that 1) your problem is not in those codes that you just posted and probably is somewhere at your player's update and 2) Why you collide(level, level) ?
Title: Re: moving a block help
Post by: camasthecat on Thu, Dec 1, 2011
I think it has something to do with flixel's code that pushes an object out to collide...
Title: Re: moving a block help
Post by: Alextfish on Fri, Dec 2, 2011
I had a little play with the SWF and can't see the problem.

Could you describe precisely what's the behaviour you're seeing that's undesirable?

I.e. 1) What are the circumstances when it happens? Where is the player, where is the block, where is the platform? 2) What precisely happens? 3) What precisely would you want to happen instead?
Title: Re: moving a block help
Post by: flabby_fabby on Fri, Dec 2, 2011
When the hero is over hanging over the block and you walk into the block, the block moves.

I want the hero to walk over it without it affecting the block.

So I only want the block to move if ( hero._y + hero._height > block._y )

(https://lh5.googleusercontent.com/-pTzMMQFW1Jrx848b4koY92giGsBdJ1SGi-xtjtxbCnnWL0EyAsnEIU4PcRCeFSOQ7kpWPrARcrBC1WlDrB2mufKYpR5y6OsVHU=w1024)

Hopefully this picture explains it more. The red outline is the offset of the image for collision.



Also, I did a collide test with level to level because the blocks fall through the platform if I don't.

Is there a better way to do this?
Title: Re: moving a block help
Post by: wg/funstorm on Sun, Dec 4, 2011
Can't see the picture "Your client does not have permission to get URL /-pTzMMQFW1Jrx848b4koY92giGsBdJ1SGi-xtjtxbCnnWL0EyAsnEIU4PcRCeFSOQ7kpWPrARcrBC1WlDrB2mufKYpR5y6OsVHU=w1024 from this server."
Title: Re: moving a block help
Post by: flabby_fabby on Sun, Dec 4, 2011
sorry about that. here's the image...

(http://s7.postimage.org/74biomsvf/Untitled.jpg)
Title: Re: moving a block help
Post by: OldmanBiles on Mon, Dec 5, 2011
I can't see the swf above. So you're saying that you don't want the block to move when the player walks over it, but you do want it to move if he walks into it?

If so, can't you just set the immovable tag inside your flxsprite when the player is colliding with the top of the box?
Title: Re: moving a block help
Post by: Kytin on Mon, Dec 5, 2011
So I only want the block to move if ( hero._y + hero._height > block._y )

Shouldn't that be if ( hero._y + hero._height < block._y )?
The way you have it, the block only moves when the player is above it.

Also, I did a collide test with level to level because the blocks fall through the platform if I don't.

Is there a better way to do this?

Create a separate group for the blocks and collide that group against the level. This also has the advanage that you can collide them with the player separately, using a different function if you choose.
Title: Re: moving a block help
Post by: noFunk on Tue, Dec 6, 2011
I had a similar problem, take a look at this post it really helped me out
http://forums.flixel.org/index.php/topic,4479.msg27640.html#msg27640