Im Trying to find out why don't the polygons move when I change their variables

,

I'm just trying to make polygons alongside a character like their hitbox but I don't know to make that a part of their Sprite so I'm doing it this way I tried first using a rect since I knew they were simpler But it doesn't seem to work Can you guys see any problems with my code

main.lua

import "ANIMATEDIMAGE"

import "LDtk"

import "CoreLibs/timer"

import "CoreLibs/object"

import "CoreLibs/sprites"

import "CoreLibs/graphics"

import "enity"

import "level/level”

local gfx = playdate.graphics

local anim = AnimatedImage

local timer = pd.timer

function playdate.update()

playdate.graphics.clear()

chunk1()

end

level.lua

import "CoreLibs/sprites"

import "CoreLibs/graphics"

pd = playdate

gfx = pd.graphics

pgp =pd.geometry.polygon

rect =pd.geometry.rect

arc =pd.geometry.arc

l = 0

r = 20

d = 400

a = 50

r1 = rect.new(l,r,d,a)

function chunk1()

gfx.drawRect(r1)

print(l , r)

if playdate.buttonIsPressed("a") then

    l = l + 100

    r = r + 100

end

end

It's because when you call rect.new it copies those values, so when you update the originals it doesn't update the copied version

2 Likes

Then is there any way to change the variables or such no way to change the position of a rect or Polygon Once it has already been placed

Not sure about polygon, but you can move a rect by simply setting the x or y property.

E.g. r.x = 10

You can move polygons like so:

local transform = pd.geometry.affineTransform.new()
transform:translate(x, y)
gfx.drawPolygon(transform:transformedPolygon(pgp))
1 Like