0 Favourites

How do I swap 9-patch image with a different one?

  • 9-patch only has one frame, unlike sprites which allow multiple frames..

    How would I change the image of a 9-patch so that I can switch between them at runtime?

    if it can't be done with built-in methods, are there any plugins that solve this?

  • There is always the option of using several 9-patch objects with different images and regrouping them in a family for events purpose.

  • I have the 9-patch in a container.. so there will be multiple instances of it. I don't think putting them in a family will solve the issue.

  • It would have, if not for the "being in a container" part. I don't see how you'll be able to do what you want without Ashley adding some sort built-in way of having multiple frames for a 9-patch or a "Load image from url" thing.

  • hm.. yea.. I think loading from url wouldn't work either because it would probably end up changing all the instances as well if they all share the same image. There'd have to be some built in support for multiple frames I guess.

    I'll have to experiment and see if I can work with using multiple separate 9-patches somehow. Will require more tedious management unfortunately. :\

  • unfortunately, I still need this.

    2 years later no solutions.

  • Stack two 9patches on top of each other in a container. Toggle visibility.

  • I have a 9patch that is part of a container with another 9patch and a spritefont.

    I have 25 layers, and a container on each one.

    In the events I pick the 9patch by checking if it is on a layer.

    When one is picked, the other objects in the container are also picked.

    now..

    I want to be able to have 25 different looking 9patches.

    It would be simple if I could just store these in different animations/frames. I would simply set the animation/frame in the editor.

    Unfortunately I can't do this.

    So, the only way is to create 25 9patches.. but they need to be in a container too! So each of those have to have another 25 other 9patches and 25 other spritefonts!

    Not to mention that I need 25 times the number of events! because I can't put them in a family. If I did, I would need to put the spritefont and other 9patches in other families too, and then pick each one based on the other that is picked.. so it creates a mess of events!!

    This is all because I can't have 9patches with animations/frames..

    The same can be said of tiledbackgrounds.

    @Ashley

  • In that case, where you have a more involved feature, it would probably be worth building your own 9-patch like container out of sprites. It shouldn't be too difficult (one set of events to pin to imagepoints basically).

    The functionality can be recreated with events, just like most behaviors and features in Construct. Particles is another object that comes to mind where I regularly just use sprites and events.

    EDIT: Note that I'm all for updating the 9-patch object. Rotations please! =)

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • oosyrag , unfortunately sprites don't tile/repeat. I could use a tilebackground, but those don't have animations/frames, so that would be 4*4*25 tiledbackground objects(for each side of the 9patch area)!! So using sprites/tiledbackgrounds is out of the question.

  • You're right! Now I'm curious to see what I can pull off with sprites only. Do your 9-patches dynamically resize much during runtime? Or just need a function to place them and allow them to change animation frames?

  • Some get dynamically resized during runtime, yes. And the objects in the container sometime get repositioned also.

    I've been wondering perhaps a behavior could be created that is similar to the Pin behavior but just copies all the properties/position/size, etc. So a more advanced pin behavior. Then perhaps I could create the other 9patches and then create and pin them to the current 9patches at the start based on what layer it is on. Then I could control the original 9patches and the pinned ones would auto-copy that..

    This seems like it might be the most sane way of handling it without all the headaches of eventsheet complexity that makes further development more difficult.

    but not sure if a behavior can accomplish that yet- would need to look into how the pin behavior works and if it can be expanded.

  • So I spent some time and cloned the Pin behavior and added the option to scale the object to the pinned object's scale.

    I wish I didn't have to resort to this behavior and the extra objects, but I feel like my feature requests aren't being heard so I have to make due with what I have. This is the best option I can come up with on my own.

    So I might spend some more time adding more features to the behavior and then sharing it in the plugin section of the forum. I feel like it will be very useful for others.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
99 10,127
karshinkoff's avatar
karshinkoff
Unread hot topic
132 10,993
Burvey's avatar
Burvey
Unread hot topic
0 Favourites
XBOX ONE UWP performance?
88 9,674
q3olegka's avatar
q3olegka