Ayuda,dibujar primitivas pegadas en un mapa,capa.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
oscaradalid
Prole
Posts: 11
Joined: Wed May 09, 2018 11:48 am

Ayuda,dibujar primitivas pegadas en un mapa,capa.

Post by oscaradalid »

Antes de nada disculpad por expresarme en español,pues el ingles no es mi lengua materna y estoy aprendiendo love,aunque hay una serie de conceptos básicos que no logro de comprender,pues he programado en otro lenguaje y difiere su mecánica.
1.¿ Cómo puedo dibujar líneas en un mapa o capa que he creado sin que me borre continuamente la pantalla y de ese modo no me borre lo que he dibujado?¿?
en el manual hay este ejemplo:

Code: Select all

w = love.graphics.getWidth() / 2   -- half the window width
h = love.graphics.getHeight() / 2   -- half the window height
function love.draw()
   local mx, my = love.mouse.getPosition()  -- current position of the mouse
   love.graphics.line(w, h, mx, my)
end

La mecánica la comprendo,pero yo quiero que cada vez que mueva el ratón,una nueva línea más dibuje sin borrar la anterior.
Gracias.



First of all I am sorry for expressing myself in Spanish, because English is not my mother tongue and I am learning love, although there are a number of basic concepts that I can not understand, because I have programmed in another language and its mechanics differ.
1. How can I draw lines on a map or layer that I have created without continuously erasing the screen and thereby not erase what I have drawn?

I understand the mechanics, but I want that every time I move the mouse, a new line draws without deleting the previous one.
thank you.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Ayuda,dibujar primitivas pegadas en un mapa,capa.

Post by raidho36 »

Everything you draw stays there until you clear it (this fills the whole area with solid color). The screen is cleared every frame automatically, but if you draw to a canvas you need to clear it manually.
oscaradalid
Prole
Posts: 11
Joined: Wed May 09, 2018 11:48 am

Re: Ayuda,dibujar primitivas pegadas en un mapa,capa.

Post by oscaradalid »

Thanks, but how do you draw the graphic primitives then without using love.draw ()?
what I want is to draw them on a map, in other programs it would be a type of function called map_put_draw_line (FILE, x0, y0, x1, y0) ... I understand how the system works, each frame erases the screen and paints again what is in love.draw () .. but I want you to copy it in the background or permanent map and can draw more primitives, without being deleted by the passage of the frames.



Gracias, pero ¿cómo se dibujan las primitivas gráficas luego sin usar love.draw ()?
lo que quiero es dibujarlos en un mapa, en otros programas sería un tipo de función llamada map_put_draw_line (FILE, x0, y0, x1, y0) ... Entiendo cómo funciona el sistema, cada frame borra el pantalla y pinta de nuevo lo que está en love.draw () ..pero quiero que lo copie en el fondo o en el mapa permanente y pueda dibujar más primitivas, sin que se borre por el paso de los fotogramas.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Ayuda,dibujar primitivas pegadas en un mapa,capa.

Post by pgimeno »

English version below.

Si quieres dibujar sin borrar, dibuja sobre un canvas, y luego dibuja el canvas. Pero no estoy muy seguro de que eso sea lo que más conviene en la mayoría de casos. De todas formas, he aquí un ejemplo:

Code: Select all

local canvas

function love.load()
  canvas = love.graphics.newCanvas() -- same size as screen by default
  love.graphics.setCanvas(canvas)
  love.graphics.clear(0,0,0,1) -- this is for 11.0 - use 255 instead of 1 for 0.10 and below
  love.graphics.setCanvas()
end

local w = love.graphics.getWidth() / 2   -- half the window width
local h = love.graphics.getHeight() / 2   -- half the window height
function love.draw()
  local mx, my = love.mouse.getPosition()  -- current position of the mouse
  love.graphics.setCanvas(canvas)
  love.graphics.line(w, h, mx, my)
  love.graphics.setCanvas()
  love.graphics.draw(canvas) -- drawn at 0, 0 by default 
end
Ese código hará lo que tú querías: dibujar líneas sin borrar la anterior. Sin embargo, para dibujar mapas, lo típico es usar mapas hechos a base de "tiles" o recuadros, componer la parte visible del mapa en un SpriteBatch y dibujar éste a cada frame. Luego puedes dibujar el resto de objetos encima.

--
English:

If you want to draw without clearing, draw on a canvas, then draw the canvas. However I'm not sure that's the most convenient thing to do in most cases. Anyway here's an example:

[see example above]

That code does what you asked: it draws lines without erasing the previous. However, to draw maps, it's customary to use tile-based maps, then prepare the visible part of the map in a SpriteBatch, which you draw in each frame. Then you can draw the rest of objects on top of it.
oscaradalid
Prole
Posts: 11
Joined: Wed May 09, 2018 11:48 am

Re: Ayuda,dibujar primitivas pegadas en un mapa,capa.

Post by oscaradalid »

Hola, gracias por el ejemplo,
El mirado de intentar que las líneas que se dibujan en el lienzo cuando se interseccionan vaya sumando o incrementando su opacidad hasta tener alfa=1 y de ese modo volverse completamente blanco, opaco, pero no lo consigo. Se agregó dos cuadrados que se interseccionan y se observan como estos funciona lo que pretendo hacer.

¿Qué parámetro debo añadir para que funcione?



Hola, gracias por el ejemplo,
El mirado de intentar que las líneas que se dibujan en el lienzo cuando se interseccionan vaya sumando o incrementando su opacidad hasta tener alfa=1 y de ese modo volverse completamente blanco, opaco, pero no lo consigo. Se agregó dos cuadrados que se interseccionan y se observan como estos funciona lo que pretendo hacer.

¿Qué parámetro debo añadir para que funcione?

Code: Select all

local canvas
--love.graphics.setColor( 1, 1,1,0.5 )
function love.load()
  canvas = love.graphics.newCanvas() -- same size as screen by default
  love.graphics.setCanvas(canvas)
  love.graphics.clear(0,0,0,1) -- this is for 11.0 - use 255 instead of 1 for 0.10 and below
  love.graphics.setCanvas()
end

local w = love.graphics.getWidth() / 2   -- half the window width
local h = love.graphics.getHeight() / 2   -- half the window height
function love.draw()
 
 local mx, my = love.mouse.getPosition()  -- current position of the mouse
  love.graphics.setColor( 1, 1,1,0.2 )--cambia la opacidad de la linea pero no hace la sumas de sus opacidades cuando se intersecciona. :x 
  
  love.graphics.setCanvas(canvas)
  love.graphics.line(w, h, mx, my)
  love.graphics.setCanvas()
  love.graphics.draw(canvas) -- drawn at 0, 0 by default 

  love.graphics.setBlendMode("alpha") --Default blend mode
	love.graphics.setColor(0.6,0,0,0.5)
	love.graphics.rectangle("fill", 50, 50, 100, 100)

  love.graphics.setColor(0.6,0,0,0.5)
	love.graphics.rectangle("fill", 50, 25, 100, 100)

 

end

User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Ayuda,dibujar primitivas pegadas en un mapa,capa.

Post by pgimeno »

You need to draw the canvas with colour 1,1,1,1. Call love.graphics.setColor(1,1,1,1) right before love.graphics.draw(canvas).

Necesitas dibujar el canvas con color 1,1,1,1. Pon love.graphics.setColor(1,1,1,1) justo antes de love.graphics.draw(canvas).
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 57 guests