Discord
Login
Community
DARK THEME

Map & sprite scaling

I create a map which is 24 (16x16) cells wide by 16 deep and display it using:

screen.drawMap("mymap",0,0,screen.width,screen.height)

Using a 16:9 (1920x1080) monitor, the scaling factor 'sf' is therefore 356/(24*16) = 356/384.

If I want to display a 16x16 sprite at the same size I'm using:

screen.drawSprite("sprite",x,y,16*sf,16*sf)

I find I need to subtract 0.5 from the sprite's x co-ordinate to keep sprite and map aligned (which makes sense for an even width sprite I suppose!).

Is this the usual method used in microStudio to keep map cell and sprite sizes and positions in sync?

Draw a 'TileMap' on an object of type 'Image' at large size (actual screen size).

You will avoid the need to convert coordinates.

image = new Image( 1920, 1080 )
image.drawMap( "mymap", 0, 0, 1920, 1080)
image.drawSprite( "sprite",x , y, 16, 16 )
screen.drawImage( image, 0, 0, screen.width, screen.height )

Ah, I haven't explored the image type yet, I didn't know that was possible - thanks!

Hmmm... doesn't seem to work for me. As a test, I created a map of 40 wide x 30 high cells of 16x16 = 640x480 and a sprite of 32x32.

init = function()
  buff=new Image(640,480)
end

update = function()
end

draw = function()
  buff.drawMap("mymap1",0,0,640,480)
  buff.drawSprite("mysprite1",0,0,32,32)    
  screen.drawImage(buff,0,0,screen.width,screen.height)
end

The sprite is displayed at top left as expected but the map (which is filled with two different 16x16 sprites) doesn't show at all ie it isn't being drawn to the off-screen image.

As a further test I added:

buff.drawText("Hello", 100,100,"#FF0)

and that doesn't work either.

I'm using the offline version of microStudio on Linux with 'microScript 2.0' and 'basic graphics API' in settings.

Congratulations, you found a mistake !!

This code works !!! Although I don't know why !!! My guess is when you execute the command

  screen.drawMap("mymap1",0,0,screen.width*sca, screen.height*sca)

then some variable values are initialized and that helps.

init = function()
  sca = 2    
  buff = new Image( screen.width*sca, screen.height*sca )
  buff.setAlpha(1)
  buff.setColor("#FFF")
  //buff.setDrawAnchor( -1,1 )  
  //buff.setTranslation( 200, 100 )
  screen.setTranslation( -screen.width/2, screen.height/2 )
  screen.setScale( 1/ sca, 1/sca )
  screen.setDrawAnchor( -1,1 )
  screen.setAlpha(1)
////
////Without this line of code it doesn't work !!
////
  screen.drawMap("mymap1",0,0,screen.width*sca, screen.height*sca)
////^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
////
end

update = function()
end

draw = function()
  buff.clear()
  buff.drawRect( 0,0,screen.width*sca,screen.height*sca)
  buff.drawLine( 0,0,screen.width*sca,screen.height*sca)

  buff.drawSprite("mysprite1",0,0,32,32)    
  buff.drawMap("mymap1",0,0,screen.width*sca, screen.height*sca)
  screen.clear()
  screen.drawImage(buff,0,0,screen.width*sca,screen.height*sca)
end

That's odd and doesn't seem to make any sense - I wonder if anyone else can explain why? (@Gilles)

Post a reply

Progress

Status

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