HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.97k stars 433 forks source link

Expanding FlxRandom #1094

Closed steverichey closed 6 years ago

steverichey commented 10 years ago

I've had a few ideas for more FlxRandom functions, particularly ones that I've wanted to have a few times already. I'd like to add:

If these are beyond the scope, or you have any other ideas, let me know. Thanks!

sruloart commented 10 years ago
SeiferTim commented 10 years ago

I'm pretty sure that there is already perlin noise for flash targets, but it would be great to make sure it works on all targets.

gamedevsam commented 10 years ago

+1 for perlin noise generation.

sruloart commented 10 years ago

http://api.haxeflixel.com/types/flixel/tile/GraphicAutoAlt.html#method_detail perlinNoise(baseX : Float, baseY : Float, numOctaves : UInt, randomSeed : Int, stitch : Bool, fractalNoise : Bool, ?channelOptions : UInt, ?grayScale : Bool, ?offsets : Array) : Void inherited from flash.display.BitmapData

"randomSeed The random seed number to use. If you keep all other parameters the same, you can generate different pseudo-random results by varying the random seed value. The Perlin noise function is a mapping function, not a true random-number generation function, so it creates the same results each time from the same random seed."

steverichey commented 10 years ago

@sruloart I'm not sure it would be possible to do a meaningful general-purpose random item generator, but I know I could certainly use a random FlxSprite generator. A random FlxPath generator sounds handy too!

Also, the problem with the pre-existing perlin method is that it's only for BitmapData, which is presumably slower than, say, a two-dimensional array. In some cases, you might only want a one-dimensional array, and in others, you might need three dimensions. I think you could do some kind of Array<T> return to return an arbitrary number of array dimensions, correct? So your parameters could be minValue, maxValue, dimensions, numOctaves, smoothingFunction (which could be a FlxEase function), and size.

Gama11 commented 10 years ago

Randmonly generated sprites or paths might be handy in an addon, but I don't think that the core FlxRandom is the right place for that.

I like the other suggestions though.

Eiyeron commented 10 years ago

For the perlin, one can search ideas from libnoise. I saw there nice ideas to implement, as the module system or the different noises given by the library.

steverichey commented 10 years ago

Thanks for all the feedback, I've got some research to do! I want to find the "best" solution for HaxeFlixel, and I'll submit a pull request as soon as I have a good implementation.

MSGhero commented 8 years ago

I have perlin/simplex noise written already, although the parameters are slightly different than BitmapData's. FlxRandom or addons?

nightblade9 commented 6 years ago

Was this ever resolved? #1146 and #1148 don't seem to introduce any new methods related to generating perlin noise. Or, if a new method is not needed, how can I generate perlin noise?

01010111 commented 6 years ago

@nightblade9 You could always try this library https://github.com/whuop/hxNoise

I've used noisehx in the past as well with a haxeflixel project

MSGhero commented 6 years ago

I have a simplex noise PR in addons, but I’m not sure I want to merge it. It seems way too specific

nightblade9 commented 6 years ago

@01010111 thanks, that looks promising. I'll check it out. It looks a bit abandoned though (I opened a PR for a README change and it's still not merged after a couple of days).

@MSGhero perlin/simplex noise is used quite a lot in procedural generation. If you can merge it (even if it becomes a flixel addon), I think that would be really useful to a lot of people (like myself).

Gama11 commented 6 years ago

FlxSimplex has been merged into flixel-addons (https://github.com/HaxeFlixel/flixel-addons/pull/280) and is part of the 2.7.0 release.