Discord
Login
Community
DARK THEME

DrawImagePart Error

I have one Sprite and two Image in my project

Sprite is 100 high by 100 wide

imageSource = new Image (100, 100)
imageTarget = new Image (100, 100)

Copies the Sprite to imageSource

imageSource.drawSprite (nameSprite, 0, 0, 100, 100)

When I want to copy a Sprite to the screen or to an Image object, it works. screen.drawSpritePart and screen.drawImagePart - work properly. If I copy the next parts of Sprite in the loop, I will finally see the entire Sprite on the screen. If I am looping over the next parts of Image, I will finally see the entire Image on the screen.

ImageTarge.drawSpritePart - Works fine. If I am copying the next parts of Sprite to Image in the loop, when I copy ImageTarget to the screen, I will see the entire Sprite.

ImageTarget.drawImagePart function - not working correctly. When I loop to copy successive parts of another Image, when I copy ImageTarget to the screen, I will see the reduced ImageSource duplicated as many times as I copied it in the loop. If you uncomment line 18, you will see where they should be copied and what size they should be.

Sample code - https://microstudio.dev/i/Loginus/jam3223/

If possible, please fix this error very quickly - because on drawSpritePart I based my idea for a game in 'GAME JAM 3'. Sprites can only be 1024 by 1024, so I put the larger ones into the Assets tab and import them via drawImagePart.

Update

In Firefox 104, I noticed that when copying parts of the Image object (screen.drawImagePart function) and Sprite (screen.drawSpritePart) to the screen, there is a small gap between successive parts. This break is not present when I copy Sprite to Image.

I think I found the error, unfortunately I cannot easily make updates in the coming days, I have a big rework ongoing which needs more testing.

There is a simple workaround: use image.drawSpritePart instead of image.drawImagePart ; they are (supposed to be) the same function and both can accept an Image or Sprite or sprite name as first argument ; only image.drawImagePart is broken as it seems from reading the code.

Thank you for the quick reply !!

My brain exploded when I found out that I can use drawSpritePart on the Image class. The project was in a cul-de-sac. You saved my project. I just loaded a 64x4096 image.

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community