ID:156977
 
I have a 10x10 map and I'm using a 320x320px .png as the "background" for the map. I want to swap out the background image with another one at runtime. How would I do that?

ts
If your map format is TOPDOWN, you simply change icon of object which is located at (1,1), if TILED then it gets split into tiles, and you'll have to use loop and set different icon for each tile
IIRC, the map gets split up into different turfs when run, so you cannot simply change the turf.icon and expect them all to change, you could try block() and go through and change each one like that.
In response to Leur
Only '1' turf is returned for the "block" of 10x10 so this is not possible.
In response to Ripiz
Your just saying it can't be done and that I have to break the image into individual turfs, right?
In response to Tsfreaks
proc/ChangeBackground()
if(world.map_format==TOPDOWN_MAP)
var/obj/background/B = locate(/obj/background) in world
if(B)
B.icon='new_icon.png'
else if(world.map_format==TILED_ICON_MAP)
for(var/obj/background/B in world)
B.icon='new_icon.png'
In response to Tsfreaks
You try this?
for(var/turf/T in block(locate(1,1,1), locate(10,10,1)))
In response to Leur
Yeah. It returns one turf.

ts
In response to Ripiz
OK... I didn't know about "map_format" I'm playing around with it and can now see the different behaviors between each type.

Thanks,
ts
In response to Tsfreaks
I just tested it, and the results were like what you said, there was 1 icon, with a bunch of blank returns afterwards.

-Retested, I tried using for(var/turf/T in locate(1,1,1)) but that didn't work, this however did work.

turf
background
icon='test.png'
mob
verb
getTurfs()
for(var/turf/T in block(locate(1,1,1),locate(1,1,1)))
T.icon='test2.png'
In response to Leur
Leur wrote:
I tried using for(var/turf/T in locate(1,1,1)) but that didn't work

For the sake of explanation:
locate(1,1,1) returns a turf, so the line would read like, for any turf in this turf. As a turf can never contain another turf, the for statement logically finds no object object fulfilling your requirements and returns.
In response to Leur
ok... interesting. Thanks for following up. I may make use of it after all.

ts

In response to Schnitzelnagler
*facepalms* Thanks Schnitzelnagler, I always repeat this error for some reason.

TsFreaks:
var/turf/T = locate(1,1,1)
T.icon='test2.png'
In response to Leur
Leur wrote:
TsFreaks:
var/turf/T = locate(1,1,1)
T.icon='test2.png'


Actually, assuming your previous snippet with the strange occupational therapy for your poor CPU, you might as well try locate(/turf/background), or even locate(my_typepath), which would yield a more modular version, allowing you to package a neat little flexible procedure that takes a type path and either an icon file, or an icon state as argument. Locate the turf with the type path, if finding such a turf, and an icon file was passed, change the icon variable, else, if an icon_state (text) was passed, check the turfs icon for that icon_state and set it accordingly if possible. Return true or false, according to success or failure.