2d player using editable image

  1. What do you want to achieve? I made a player on a decal (rectangle) and every time you press a key it moves forward a few pixels (creating a new rectangle on another position), and I wanted to make the player’s old position (rectangle) deleted.

  2. What is the issue? There’s no issue, I need any tip to delete the old player position (rectangle).

  3. What solutions have you tried so far? Tried using different functions of editable image, none of them helped

local ImageObject = script.Parent

local EditableImage = Instance.new("EditableImage")
EditableImage.Size = Vector2.one * 1024
EditableImage.Parent = ImageObject

local startPosition : Vector2 = Vector2.new(325, 150)
local updatedPosition : Vector2

EditableImage:DrawRectangle(startPosition, Vector2.new(EditableImage.Size.X/7, EditableImage.Size.Y/7), Color3.new(1, 0, 0.0156863), 0)

local uis = game:GetService("UserInputService")

local function DrawPlayer(y, x)
    updatedPosition = startPosition + Vector2.new(y, x)
    startPosition = updatedPosition
    EditableImage:DrawRectangle(updatedPosition, Vector2.new(EditableImage.Size.X/7, EditableImage.Size.Y/7), Color3.new(1, 0, 0.0156863), 0)
end

uis.InputBegan:Connect(function(input : InputObject)
    if input.KeyCode == Enum.KeyCode.W then
        DrawPlayer(40, 0)
    end
    
    if input.KeyCode == Enum.KeyCode.A then
        DrawPlayer(0, -40)
    end

    if input.KeyCode == Enum.KeyCode.S then
        DrawPlayer(-40, 0)
    end

    if input.KeyCode == Enum.KeyCode.D then
        DrawPlayer(0, 40)
    end
end)
1 Like

You can’t really delete pixels when you use EditableImage. The best way is to completely replace the image with a new rectangle that is the same color of the part.

-- draw rectangle at this line
task.wait()
editableimage:DrawRectangle(Vector2.zero,editableimage.Size,Color3.new(0,0,0),0)
1 Like

Oh, lemme check it out. Thanks for the reply

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.