Sprite.Height and Sprite.ImageHeight not working properly?

0 favourites
  • 5 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Problem Description

    After loading an external image into a sprite with the option set to resize the sprite to image size you cant get Sprite.Height and Sprite.ImageHeight.

    When I output the Sprite.Height it always shows the default value of 177, but all loaded images have sizes of 100, 200 or more pixels.

    When I output the Sprite.ImageHeight it always shows 100 even if the loaded image has 200 or more pixels (can't find the reason for this).

    The images have this sizes: 1.jpg 100x100 pixel, 2.jpg 100x100 pixel, 3.jpg 100x200 pixel, 4.jpg was a huge screenshot to see if size changes.

    The animated sprites seem to resize properly, the screenshot was not streched but Sprite.Height returns 177 (the default value of the TempSprite object placed outside of the layout).

    Attach a Capx

    Attached

    Description of Capx

    It loads a banner.txt file containing a list of filenames like 1.jpg|2.jpg|3.jpg... and then creates a loop to create a new sprite for each image.

    To be able to position them depending on their height I used a second sprite object (TempSprite) to load the image first and then use Sprite.Height / Sprite.ImageHeight in the Create Sprite action. All Sprites should move from top to bottom with 10px space between them and wrap around at the end (wrap behavior does not seem to work properly if youc reate sprites outside of the layout so I used my own code with position check)

    I installed XAMPP (local Apache Server) to test it on localhost. Don't know how to change it so you can reproduce it easily.

    relevant code starts in line 19

    Observed Result

    Sprite.Height and Sprite.ImageHeigt of the TempSprite object is always the same value even if the loaded images have different sizes.

    Expected Result

    Since "Resize to Image Size" is set in the Load from URL action it should change the sprite size and the new size should be returned.

    Affected Browsers

    • Chrome: YES
    • FireFox: Don't know
    • Internet Explorer: YES

    Operating System and Service Pack

    Windows 8.1 64 Bit

    Construct 2 Version ID

    r166

  • Closing as not a bug. Your events are wrong, you try to read the size before 'On image URL loaded' triggers.

  • But when I add a "On Image URL loaded" (triggers once after loading an image) event and set a variable containing Sprite.ImageHeight it returns 0. o.O

  • Bl4ckSh33p - please submit a new report with a minimal .capx if you still have a problem (no disabled events, no unrelated objects, only a minimal reproduction of the issue). As it stands your existing report simply uses the wrong events.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi. I tried to reproduce it in a new very simple project but it worked there.

    I tried to add "On Image URL Loaded" to my existing code but it did not work with the For-loop (and you cant put it inside/below the loop) so I created this workaround and just changed the sprite size depending on the first letter in the filename (1 for 100 pixel, 2 for 200 pixel) and it seems to work now.

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