Platformer with Level Editor
import QtQuick 2.0
import Felgo 3.0
Canvas {
id: grid
property real gridSize: editorOverlay.scene.gridSize * container.scale
property string gridColor: "white"
property var container
x: {
if(container) {
return (container.x % gridSize)
}
else {
return 0
}
}
y: {
if(container) {
return (container.y % gridSize) - gridSize
}
else {
return 0
}
}
width: editorOverlay.width + gridSize
height: editorOverlay.height + gridSize
onPaint: drawGrid()
function drawGrid()
{
var context = getContext("2d");
context.clearRect(0, 0, grid.width, grid.height)
context.beginPath()
context.lineWidth = 0.4 * container.scale;
context.strokeStyle = gridColor
var xSize = grid.width
var ySize = grid.height
for(var x = 0; x*gridSize < xSize; x++)
{
context.moveTo(x*gridSize, 0)
context.lineTo(x*gridSize, ySize)
}
for(var y = 0; y*gridSize < ySize; y++)
{
context.moveTo(0, y*gridSize)
context.lineTo(xSize, y*gridSize)
}
context.stroke()