image.setTranslation - BUG

I noticed that the setTranslation method from the Image class is not working properly.

Here is a code example.

init = function()
  image = new Image( 400, 200 )
  // image.setColor( "#FFFFFF")
  // image.drawRect( 0, 0, 399, 199)
  // image.setDrawAnchor( 0, 0 ) 

  image.setTranslation( 200, 100 )
  angle = 0
 // image.setDrawRotation( angle )
 // image.setTranslation( 200, 100 )

update = function()
  angle += 1
  print( angle) 
  if angle > 360 then angle = 0 end

draw = function()

  image.setTranslation( 200, 100 )
  image.setDrawRotation( angle )
 // image.setDrawAnchor( 0, 0 )
  image.drawSpritePart('icon', 0, 0, 200, 100, 0, 0, 200, 100 )

  image.drawLine( 0, 0, 200, 100 )  
 // image.setDrawAnchor( 0, 0 )
  screen.drawImage( image, 0, 0, 400, 200 )

The sprite should form a circle in the center of the screen. However, it is drawn in the upper left corner. Now when you start editing the code - suddenly it starts drawing correctly. Try removing the comment characters.

There is another setTranslation and setDrawRotation bug. In my project, the Sprite was not drawing in the right place. (I copied Sprite to Image using drawSpritePart) But only the first time in the loop. Each subsequent painting was as I wanted. I found that using setDrawAnchor (0,0) fixes this bug.

Firefox 104 browser, 64 bit.

The default coordinates system for drawing into an Image differs from the default screen coordinates system. It is not well documented yet, but it is at least explained in the API cheatsheet here: https://github.com/pmgl/microstudio/wiki/en-API-cheatsheet#draw-on-image

I know the image has a different point (0, 0) position than screen. In this example, setTranslation does not work. Only when I start editing the code - add a letter or delete the sign - do I get the correct coordinate shift.

Run this code


The code editor on the left - the program works on the right.

Now enter the Editor and uncomment, for example, 2 lines.

This line does not change anything into programmers. It's in the Init section and will not be executed. Changing the code in the editor causes the program that runs on the right to behave differently.

I know why Microstudio behaves this way when starting the program and editing the code.

I made a mistake .

I had a copy of the program listing made in the second file (init, update, draw). When I deleted this file (or commented it entirely) the program worked as expected.

But the error with the graphics is - I prepared the second code.


In this code, the first frame of the animation is always shifted. I do not know why . The animation is jerky in the first frame.

As I uncomment line 51 in lib / Sprite360 everything works fine.

Post a reply



Validate your e-mail address to participate in the community