Discord
Login
Community
DARK THEME

setDrawAnchor isnt work ?

init = function()
  //screen.setDrawAnchor(0,0)
  screen.setDrawAnchor(1,-1)
  starsCount = 900
  for i=0 to starsCount
    stars[i].x = random.nextInt(screen.width)
    stars[i].y = random.nextInt(screen.height)
  end
end

update = function()
end

draw = function()
  for i=0 to starsCount
    screen.drawRound(stars[i].x,stars[i].y,2,2,"red")
  end
end

try to change:

  screen.setDrawAnchor(1,-1)
  screen.setDrawAnchor(1,1)
  screen.setDrawAnchor(0,0)

nothing happen

The reason it doesn't show anything is:

  1. Because the circle you are drawing is small, meaning that it doesn't make much of a difference where the anchor is drawn, as the effect it will have will be minor.
  2. Because you are generating random stars each time in the init function, you won't see the effect of the anchor change as it affects the central point of the objects - which are changing each time you change the draw anchor and restart the project.

If you try the code below and change the draw anchor in the draw function while the project is running, you will see that the draw anchor does have an effect:

init = function()
  starsCount = 900
  for i=0 to starsCount
    stars[i].x = random.nextInt(screen.width*2)-screen.width
    stars[i].y = random.nextInt(screen.height*2)-screen.height
  end
end

update = function()
end

draw = function()
  screen.setDrawAnchor(0,1) // change this while the program is running
  for i=0 to starsCount
    screen.drawRound(stars[i].x,stars[i].y,20,20,"red")
  end
end

Hopefully this helps :)

All of the above :)

If you would like to see it 'interactive', here a variation that is driven by the cursor keys.
I guess the question is, what was the intent :)

init = function()
  starsCount = 900
  for i=0 to starsCount
    stars[i].x = random.nextInt(screen.width*2)-screen.width
    stars[i].y = random.nextInt(screen.height*2)-screen.height
  end
end

update = function()
    tx  = keyboard.RIGHT-keyboard.LEFT
    ty  = keyboard.UP   -keyboard.DOWN  
end
   
draw = function()
  screen.clear()
  screen.setDrawAnchor(tx,ty) // use cursor keys
  for i=0 to starsCount
    screen.drawRound(stars[i].x,stars[i].y,20,20,"red")
  end
end

Live Long and Tinker

Post a reply

Progress

Status

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