rhysm_08 Posted December 2, 2010 Report Share Posted December 2, 2010 (edited) Trying to get the sandbox menu for my mod, and after finding the source files and spending a long time getting the fonts working, i now have a working flash menu for my mod. But, that's not enough . I've been working together to try implement a feature that should be do-able. A Randomised background, that changes each time the mod is loaded. With plenty of background images, it should add a nice variety within the mod. The problem, however, is the code. h = ["Strokes_small.png", "Dirty2_small.png", "Bokeh4_small.png"]; i = 3 //Catches the number of values inside the "h" array j = Math.floor(Math.random()*i); //A random value, with a ceiling equal to the length of the "h" array k = h[j] //Defines the path for the background to be used. this.background_img.loadImg(k) Now, if i change "this.background_img.loadImg(k)" to the image filename, which is located at the root of the mainmenu, to simplify things, it does actually work, but it only loads 1 image, which defeats the purpose of this code. Edited December 2, 2010 by rhysm_08 Quote Link to comment Share on other sites More sharing options...
AncientMan Posted December 2, 2010 Report Share Posted December 2, 2010 (edited) Math.Random() doesn't work in BF2 Flash (well it does, but it's not seeded by anything, so it's just the same number pattern over and over, which is probably since it can't get the time). To work around this, I built my own off the "getTimer()" function, which is a timer showing how long flash has been running, which should be different each time it's called, so it should give off a somewhat random number. Something like the following should do the trick (which gets the first decimal point number): function getRandomIntInRange(bottom:Number, top:Number) { var dif:Number = top-bottom+1; var random1:Array = new String(((getTimer()-1000)/1000).toString()).split("."); var random2:String = new String(random1[1]).charAt(1); return Math.floor(bottom+(dif*(random2/10))); } Then you would just call it like: var images:Array = ["Strokes_small.png", "Dirty2_small.png", "Bokeh4_small.png"]; this.background_img.loadImg(images[getRandomIntInRange(0, 2)]); Should work, was a while since I coded it for the random login images in Project Reality, can't remember if that's all I did or if I did something else to make it work... Edited December 2, 2010 by AncientMan Quote Link to comment Share on other sites More sharing options...
rhysm_08 Posted December 2, 2010 Author Report Share Posted December 2, 2010 (edited) Wow, cheers!<br><br>It loads "Strokes_small.png" for the menu, after login it would occasionally change between "Bokeh4_small.png" and "Dirty2_small.png". I guess your code works, but how would i change this if I had 7 images? How would that affect the code?<div><br></div><div>EDIT: Unrelated problem, but still annoying lol. Everytime I login, even with internet disconnected, it loads a newsticker that says "go to sandbox to download latest version and avoid being disappointed" Now i'm finding it hard to find the line of code that even raises that in flash, but it must be somewhere. If I run the SWF directly it says<br><br>where the ticker is "http://sandboxmod.com/ingame/newsticker .1.0.0.png". Now I find this strange, as the newsticker image is not even in the flash images folder, and if it is loading from online, i wonder how it does that even when i switch off the internet </div> Edited December 2, 2010 by rhysm_08 Quote Link to comment Share on other sites More sharing options...
AncientMan Posted December 2, 2010 Report Share Posted December 2, 2010 If you want, you can add in 20 or so frames right at the beginning of the timeline with a black sprite over the top. This will slightly increase the time taken to get to the login menu, but it will allow you to have a more random number, since the time will be increased, giving a more likely chance of a slight variation in milliseconds. As for adding in more images, just add the names into the array and fix up the range so it's from 0 to 6 or however many images you have... You could also do something like: this.background_img.loadImg(images[getRandomIntInRange(0, images.length - 1)]); Then you only need to add in new images into the array, and don't have to worry about changing the range. Quote Link to comment Share on other sites More sharing options...
rhysm_08 Posted December 2, 2010 Author Report Share Posted December 2, 2010 (edited) Cool, it works with many pictures. As a feature, it changes the background when logging in as well . Though, having 1 last issue with the news ticker. Here's an example... As you can see here, there is an unwanted newsticker. Getting very frustrating as I can't find the code in flash, just a sprite that is a grey colour. Also, as stated before, I am using the sandbox menu here: http://sandboxmod.com/forums/viewtopic.php?id=510 Edited December 2, 2010 by rhysm_08 Quote Link to comment Share on other sites More sharing options...
AncientMan Posted December 2, 2010 Report Share Posted December 2, 2010 (edited) BF2 flash can't have external dynamic text (well not natively anyway). It will be an image container with the text being an image. Also, if you haven't realised already, everything is grey boxes . The boxes are used for basic positioning, then actionscript takes over and draws it through code. Just delete the image container and you'll be sorted . Or do a search for the actionscript name of the image container, and it'll show up in the code, since it has to be referenced for it to load the image. Edited December 2, 2010 by AncientMan Quote Link to comment Share on other sites More sharing options...
Freeze Posted December 2, 2010 Report Share Posted December 2, 2010 http://sandboxmod.com/ingame/newsticker.1.0.1.png http://sandboxmod.com/ingame/05b9.png http://sandboxmod.com/ingame/news_content_l.png http://sandboxmod.com/ingame/news_content_r.jpg Probably the leftovers you are looking for. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.