Jump to content

Set object invisible


Skallagrim

Recommended Posts

At the moment I use the IsoThumpable object for icons that are visible sometimes and sometimes not.

I use this object solely because it is the only object I know, that has a "setSprite()" method.

 

In order to get it invisible I currently do it like this: IsoThumpable.setSprite("")

But I have a bad feeling about doing it like this.

Is there mabe a better way? I am looking for something like "setVisible(false)"

Link to comment
Share on other sites

Pretty sure all IsoObject have setSprite(), as it is  the base class?

Don't quote me on that, though. I don't remember if IsoThumpable is an interface or not.

Thumpable is an interface and most (if not all) of the Objects like barricades, doors and windows implement it IIRC.

At the moment I use the IsoThumpable object for icons that are visible sometimes and sometimes not.

I use this object solely because it is the only object I know, that has a "setSprite()" method.

 

In order to get it invisible I currently do it like this: IsoThumpable.setSprite("")

But I have a bad feeling about doing it like this.

Is there mabe a better way? I am looking for something like "setVisible(false)"

Did you take a look at the sledgehammer code? It destroys objects so it probably does what you want to in the best way possible :)

	self.item:getSquare():RemoveTileObject(self.item);
But reading through your question again, it isn't really what you are looking for :(
Link to comment
Share on other sites

Pretty sure all IsoObject have setSprite(), as it is  the base class?

Don't quote me on that, though. I don't remember if IsoThumpable is an interface or not.

Oh, you are right, but IsoThumpable has two setSprites. I forgot that.

The one from IsoObject takes a IsoSprite as argument, while the second one from IsoThumpable only needs a String.

I was hoping to only offer the string which spares me the creation of an new IsoSprite myself.

Sorry for not beeing more specific.

Did you take a look at the sledgehammer code? It destroys objects so it probably does what you want to in the best way possible :)

	self.item:getSquare():RemoveTileObject(self.item);
But reading through your question again, it isn't really what you are looking for :(

 

Not realy, but thanks for trying.

I hope to not have the IsoSprite removed or replaced constantly. And if not possible, have it done by something that does it savely.

Link to comment
Share on other sites

I found a way to set an IsoObject invisible/visible.

Setting IsoObject invisible:

tile_object:getProperties():Set("invisible", "true")
Setting IsoObject visible again:

tile_object:getProperties():getFlags():set(36, false)
!important, "getProperties():Set()" has to have been used once before, to initialize the necessary objects.

More details:

Every IsoObject/Sprite has a property object one can get by using getProperties().

It contains a properties hashmap and list of flags that can be set true.

ZomboidBitFlag SpriteFlags;THashMap<String, String> Properties;
 

One kind of the flag is

IsoFlagType.invisible(36)
 

But I found no access to the class IsoFlagType, because of that, setting a type of flag in SpriteFlags 'false' can be a little troublesome.

Setting one flag true is no problem, it works like this:

tile_object:getProperties():Set("invisible", "true")
 

This adds an entry in the Hashmap 'Properties' and somehow (could not find out how) this also will set the flag in 'SpriteFlags' true. The value "true" does not matter I think, one could also give "cake" as argument.

Now the object is invisible, without removing the Sprite.

 

Making the object visible again is a little tricky. Nothing I tryed with "Set" or "UnSet" worked.

Instead I managed a workaround:

tile_object:getProperties():getFlags():set(36, false)
36 is the integer value of the flag 'IsoFlagType.invisible', luckily there was a method that accepted integer.

 

PS:

I also use now IsoObject and simply made my own setSprite()

function setSprite(object_IsoObject, name_of_texture)    local sprite = IsoSprite.new()    sprite:LoadFramesNoDirPageSimple(name_of_texture)    object_IsoObject:setSprite(sprite)end
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...