[solved] Python and ImageManipulator

This forum is currently in read-only mode.
  • How can i use the ImageManipulator Object in a Python script?

    I want to use "ImageManipulator copy image to sprite"

    I have tried: ImageManipulator.CopyToSprite(spritename) but my game crashes at start. how do I have to use this?

  • I'm using .99.84 and it doesn't do anything for me at all so this definitely sounds like a bug.

    When using your syntax (putting the Sprite name in) it doesn't do anything, when putting a 1 or 2 for sprite name it crashes.

    I tried to find the source to the ImageManipulator but it isn't available so I can't do much more to help. I've posted it to the tracker.

  • Yeah, I can't get it to work either.

    I also noticed that there seems to be no method defined for 'Copy from sprite', which makes Python usage of the manipulator even more difficult.

  • It appears that 'CopyToSprite' actually copies from the sprite. What's probably happening is the two functions 'CopyToSprite' and 'CopyFromSprite' both have the name 'CopyToSprite' in python. So the last one defined is the only one accessible. Easily fixable if the source were available.

    Edit:

    Also ImageManipulator.CopyToSprite(spritename) is incorrect.

    With functions (or methods) in construct, only two types work in python: numbers or strings. So the correct way would be: ImageManipulator.CopyToSprite('spritename'). If you use a number instead of a string, the objecttype with an OID (object id) equal to that number would be referenced. If the referenced objecttype has no image data it will cause a crash.

  • This sounds not good to me.

    My problem is that "ImageManipulator copy image to sprite" in construct has only a dropdown list of all my sprites. But I dont want to use the name of a sprite from this list. What I want is to use a variable for the name because i have 100 sprites, and all of them should get the same imagemanipulator actions. If i can not use a variable there, I have to do the same events for every single sprite i want to change.

    I really dont know what to do now.

  • Well, you can use variables instead of string or number literals. The variable just has to contain the name in string form, or the Object ID in number form, as R0J0hound pointed out.

    The bigger issue is the fact that the python methods are messed up, but it should be possible to work around that with the function object. I made a simple example with a couple of different ways to use the function object to do image processing, including from python.

    v.99.84 Cap here: http://dl.dropbox.com/u/5868916/FunctionWorkaround.cap

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you very much. That helped me a lot. But one little Problem is still there. How can i load an Image from an ini file with such a function ?

    INI.ItemString("item1", "image1") does not work in Function.ProcessSprite("Sprite", "Sprite2").

    If i can load the image from an ini string, my problem will be solved.

  • Thank you very much. That helped me a lot. But one little Problem is still there. How can i load an Image from an ini file with such a function ?

    INI.ItemString("item1", "image1") does not work in Function.ProcessSprite("Sprite", "Sprite2").

    If i can load the image from an ini string, my problem will be solved.

    You're welcome. I'm not terribly familiar with the INI object, but I added one and replaced the function call in start of layout with this:

    + System: Start of layout
    -> INI: Set INI file to "MyINI"
    -> INI: Write string "Sprite2" to item "Item1" in group "Group1"
    -> Function: Call function Function.ProcessSprite("Sprite", INI.ItemString("Group1", "Item1")) (and Forget picked objects)
    [/code:2h0ho73a]
    
    ... and it worked the same as before. Assuming that you're storing object names in the INI file.
    
    Also, the same as above can be done from python as:
    
    [code:2h0ho73a]INI.SetFile("MyINI")
    INI.WriteString("Group1","Item1","Sprite2")
    Function.AddParam("Sprite")
    Function.AddParam(INI.ItemString("Group1","Item1"))
    Function.Call("ProcessSprite", 0)[/code:2h0ho73a]
  • This solved my Problem completely. Thank you for your quick help.

  • You can right click just above the drop down list and switch the expression box to "use expression mode" wich allows you to pass things like string from an ini file into it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)