Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - MattB

Pages: [1] 2
help / Re: Performance in huge tiled maps
« on: Wed, May 16, 2012 »
Yeah. The tilemap only draws a selection of tiles that are actually on screen. Take a look at the drawTilemap method in FlxTilemap to see how.

help / Re: Seperation Code Explained
« on: Thu, May 10, 2012 »
I see. If it had moved left we don't want to move the object's x even further left or back to the right, just change its width hence the 0.

I was so close to understanding it, but drawing it out really helped.

Thank you.

help / Re: Seperation Code Explained
« on: Sat, May 5, 2012 »
Anybody? Pretty please?

help / Re: Seperation Code Explained
« on: Tue, May 1, 2012 »
I'm still scratching my head on this one. It has to do with Sweep Testing, right?

help / Seperation Code Explained
« on: Mon, Apr 30, 2012 »
I'm trying to implement the code flixel uses to seperate Rectangles in another project and I was wondering if anyone could explain these lines of code in the SeparateX function (it also appears in the SeparateY):

Code: [Select]
var obj1rect:FlxRect = new FlxRect(Object1.x-((obj1delta > 0)?obj1delta:0),Object1.last.y,Object1.width+((obj1delta > 0)?obj1delta:-obj1delta),Object1.height);

var obj2rect:FlxRect = new FlxRect(Object2.x-((obj2delta > 0)?obj2delta:0),Object2.last.y,Object2.width+((obj2delta > 0)?obj2delta:-obj2delta),Object2.height);

It uses these rectangles to determine if it should check for overlap, and I'm not sure why the X is defineds as:
Object1.x-((obj1delta > 0)?obj1delta:0

Why do I only was to add the change in X to the check rectangle if the object was moving right? I'm also a little hazy as to why we add absolute value of the X delta to the width, though it makes since if the implication is it's checking overlap for the objects soon-to-be position.

It would be super helpful if some one could explain these rectangles to me.

help / Re: [SOLVED] collision headache
« on: Thu, Mar 15, 2012 »
I'm having this exact same issue. I'm doing my own port to XNA and when my sprite moves from right to left with gravity applied it gets stuck on every tile.  Increase the selection of tiles being checked doesn't help, and if I simply make to FlxObject blocks next to each other the same thing happens.

help / Mouse Movement
« on: Fri, Dec 16, 2011 »
Has anyone on here made a game with flixel that features move-to-mouse-click style game play like Diablo or newer Kings Quest games. I'm trying to make a quick adventure game for my dads birthday and need help getting started quickly without testing a bunch of different methods to find what works best.

I don't use Flixel 2.5 (yet, that might change soon), but I added this function to FlxObject to check if objects are touching.

Code: [Select]
virtual public function touches(Core:FlxObject, Bias:Number = 1):Boolean
var bias:Number = Bias;
if (bias < 0)
bias = 0;

var tx:Number = x;
var ty:Number = y;
if((scrollFactor.x != 1) || (scrollFactor.y != 1))
tx -= floor(FlxG.scroll.x*scrollFactor.x);
ty -= floor(FlxG.scroll.y*scrollFactor.y);
var cx:Number = Core.x;
var cy:Number = Core.y;
if((Core.scrollFactor.x != 1) || (Core.scrollFactor.y != 1))
cx -= floor(FlxG.scroll.x*Core.scrollFactor.x);
cy -= floor(FlxG.scroll.y*Core.scrollFactor.y);
if(((cx+Core.width+bias) <= tx) || (cx-bias >= (tx+width)) || ((cy+Core.height+bias) <= ty) || (cy-bias >= (ty+height)))
return false;
return true;

I don't know if you can plug that right in to 2.5, but the important lines are:

Code: [Select]

if(((cx+Core.width+bias) <= tx) || (cx-bias >= (tx+width)) || ((cy+Core.height+bias) <= ty) || (cy-bias >= (ty+height)))
return false;
return true;

That's just a check to see if the objects respective edges are within 1 pixel of each other. I doesn't alway work prefectly with tilemaps due to some weird rounding stuff, but it more often than not gets the job done. You can change the "Bias" to make it return true if an objects edges are 2 pixels away or 3 or 50 or whatever.

Something like:
if((abs(thing1.midX - thing2.midX) <= (thing2.width/2) + (thing1.width/2) + checkDistance) && (abs(thing1.midY - thing2.midY) <= (thing2.height/2) + (thing1.height/2) + checkDistance))

could potentially test overlaps and touching too. Shrug.

help / Re: Getting BitmapData for a TileType? (2.5)
« on: Sun, Nov 6, 2011 »
Okay. I'm using a really date version of flixel I've been updating myself, but the idea should be the same.

First you'll need these new variables.

Code: [Select]
protected var _flashRect:Rectangle; // for rendering colorTransform
protected var _flashPixels:BitmapData; // for rendering colorTransform
protected var _flashPointZero:Point; // for rendering colorTransform

protected var _alpha:Number;

I think the current flixel Tilemap already has a _flashRect, so just calling it _flashRect2 should work, if using if the way I've detailed below breaks anything in 2.5.

Then make sure you new them in the constructor and set the complex ones to null in destroy()

Code: [Select]
public function FlxTilemap()
widthInTiles = 0;
        heightInTiles = 0;
_data = new Array();
_rects = new Array();
_point = new Point();
_flashRect = new Rectangle();
_flashPointZero = new Point();

override public function destroy():void
_pixels = null;
_data = null;
_rects = null;
_point = null;
_flashRect = null;
_flashPixels = null;

My FrankenFlixel doesn't have a debug mode so you'll see a lot less vars there.

Here's the actual set and get functions for alpha

Code: [Select]
public function get alpha():Number
return _alpha;

public function set alpha(Alpha:Number):void
if(Alpha > 1)
Alpha = 1;
if(Alpha < 0)
Alpha = 0;
if(Alpha == _alpha)
_alpha = Alpha;
if ((_alpha != 1))
_colorTransform = new ColorTransform(1, 1, 1, _alpha);
_flashRect.x = _flashRect.y = 0;
_flashRect.width = _pixels.width;
_flashRect.height = _pixels.height;
_flashPixels.copyPixels(_pixels, _flashRect, _flashPointZero);
_flashPixels.colorTransform(_flashRect, _colorTransform);
_colorTransform = null;


Then you need to change the code that renders each tile from...
Code: [Select]
if (_rects[columnIndex] != null)
FlxG.buffer.copyPixels(_pixels, _rects[columnIndex], _point, null, null, true);

Code: [Select]
if (_rects[columnIndex] != null)
if (_colorTransform != null)
FlxG.buffer.copyPixels(_flashPixels, _rects[columnIndex], _point, null, null, true);
FlxG.buffer.copyPixels(_pixels, _rects[columnIndex], _point, null, null, true);

I think in 2.5 the line is: Buffer.pixels.copyPixels(_tiles,_flashRect,_flashPoint,null,null,true);
I think you can just use the same if statement and change _tiles ot _flashPixels for the _colorTransform check.

Sorry that's kind of all over the place and dirty, but it should get you going. Look at the color function from FlxSprite and you should be able to replicate their behavior pretty simply.

help / Re: Getting BitmapData for a TileType? (2.5)
« on: Sun, Nov 6, 2011 »
I got tilemaps with a variable alpha channel to work with virtually no hit to FPS. It'd be pretty easy to add a color-shift / blend modes too. If anyone in this thread wants the code, lemme know.

help / Re: Tracing TileMaps
« on: Sun, Nov 6, 2011 »
Yeah, that makes sense! Thanks. I wasn't sure how to go about setting up the event listeners.

I'll test it out when I get back home.

help / Re: efficient tilemaps
« on: Sun, Nov 6, 2011 »
it's not to hard to import bitmaps with more than one color. Try some code like this where bgSrc is bitmapData and Level2BG is an embedded image.

Code: [Select]
bgSrc = (new Level2BG).bitmapData;

var tileString:String ="";
var bType:uint;
var h:int;
var w:int;
var bW:int;
var bH:int;

if (bgSrc != null)
bW = bgSrc.width;;
bH = bgSrc.height;
//get bgtiles
for (h = 0; h < bH; h++)
for (w = 0; w < bW; w++)
bType = bgSrc.getPixel(w, h);

if (bType == 0x4a0046)
//Purple Industry
tileString += "0,"
else if (bType == 0x9c78fc)
tileString += "1,"
else if (bType == 0x580c00)
tileString += "2,"
}//end w loop
tileString += "\n";
}//end h loop
bgTiles.loadMap(tileString, ImgBgTiles, 20, 20, 3, 0);

All it's doing is looping through an image and writing the data string for the tile map according to color values like 0x4a0046. If you like you can place objects like enemies and such in the same loop by assigning a color value to the x,y you want them at drawing that on your map as well.

Code: [Select]
else if (bType == 0xff00c0)
addAlien(w, h);


public function addAlien(bX:Number, bY:Number):void
var alien:Alien = new Alien();

help / Re: Tracing TileMaps
« on: Sun, Nov 6, 2011 »
Chelnok. How could one load an external file into a variable to use with the tileMap?

help / Re: Getting BitmapData for a TileType? (2.5)
« on: Sat, Nov 5, 2011 »
I'm trying to do the same thing in a game I'm working on. My approach is to make a second tilemap for the hidden areas, using the same embedded tile image but with a higher collision index. This has the nice benefit of letting me auto-tile my hidden areas. As a bonus, I expanded the auto-tile to accept a range of tiles as just-cause for edge detection.

Code: [Select]
* An internal function used by the binary auto-tilers.
* @param Index The index of the tile you want to analyze.
protected function autoTile(Index:uint, minBounds:int = -1, maxBounds:int = -1):void
if(_data[Index] == 0)

var startIndex:uint;
startIndex = _data[Index];
if (minBounds == -1)
minBounds = startIndex;
if (maxBounds == -1)
maxBounds = startIndex + 16;

_data[Index] = 0 ;
if((Index-widthInTiles < 0) || (_data[Index-widthInTiles] >= minBounds && _data[Index-widthInTiles] <= maxBounds)) //UP
_data[Index] += 1;
if((Index%widthInTiles >= widthInTiles-1) || (_data[Index+1] >= minBounds && _data[Index+1] <= maxBounds)) //RIGHT
_data[Index] += 2;
if((Index+widthInTiles >= totalTiles) || (_data[Index+widthInTiles] >=minBounds && _data[Index+widthInTiles] <= maxBounds)) //DOWN
_data[Index] += 4;
if((Index%widthInTiles <= 0) || (_data[Index-1] >= minBounds && _data[Index-1] <= maxBounds)) //LEFT
_data[Index] += 8;
_data[Index] += startIndex;

You might also note it lets me auto-tile multiple rows of tiles from the same sheet.

Anyways, I'm going to add an alpha channel to the tile map so they become transparent when you overlap them by adding a colortransform to the rendered pixels.

help / Re: Ledge Grabbing?
« on: Thu, Oct 27, 2011 »
Thanks guys. I've rewritten my dated Flixel 1.whatever Tile-map code to closer resemble 2.5's and think I'll be able to use the auto-tile math to check for tiles above and below potential edges. That pastebin code looks promising too.

help / Ledge Grabbing?
« on: Tue, Oct 25, 2011 »
I only found one other thread on this with no real answers.

I'm working on a side-scroller and I want to do this:  (Yeah, I'll probably message the guy who made this and ask too)

I'm using an old version of Flixel that still includes the hitWall function, and my initial idea is to override that, setting a flag like canGrab, when the player is above the ledge, and then when the player collides with his top below the edge, put him in a grab state if the canGrab flag is true. But I imagine the player would then be able to grab every flxBlock, even blocks with blocks on top of them that weren't really blocks. Then there's the matter of the "pulling up".

Has anyone done this?

games / Re: My Robot is Fight
« on: Mon, May 9, 2011 »

Here's the newest update. It has configurable keys and I fixed the bug causing the difficult wall-jumping / double-jumping. I plan on adding some default key settings as well, so you can simply push a button and have W,A,S,D controls.

I'll look into that rocket launcher bug and add a suicide command in the menu for the mean time. Good point about the music as well.

I plan on adding multiplayer to this eventually, so the skill menu probably won't ever pause the action. However, I may add some rooms with no enemies as safe rooms. In the meantime, the inventory is always a safe place to make your robot more fight.

games / Re: Dark Star (working name)
« on: Sun, Apr 17, 2011 »
This is awesome. I keep blowing myself up with the pulse rifle though... :)

games / Re: My Robot is Fight
« on: Sun, Apr 17, 2011 »
I plan on making the keys assignable eventually. But yeah, in the meantime, A and D make sense (S is already used for the skill menu).

games / My Robot is Fight
« on: Fri, Apr 15, 2011 »
Hey all. Just wanted to post a link to the alpha test of a game I've been developing using Flixel [modified from version 1.4]. It's called My Robot is Fight and it's a Side-Scroller Rogue-like where you take the role of a determined robot trying to save its home planet from horrible flesh-beast.

Tell me what you think and let me know if you find any bugs.

(A few of the graphics and sounds are still placeholders.)

[I did all of the music, art and sound.]

Pages: [1] 2