Low-res Sprites when drawn inside of another function

I’m not sure if this has been posted or if it’s my code, but for some reason when I draw the Planet Cute: Character Boy sprite inside of the touched(touch) function, it draws him like it’s on a GBA. Here’s my code:

-- Planet Cute: Worlds DEMO

-- Use this function to perform your initial setup
function setup()
    print("Demo of Planet Cute: Worlds, an RPG I will be making for iOS. it will take a while.")
    displayMode(FULLSCREEN_NO_BUTTONS)
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(0, 255,0,255)

    -- This sets the line thickness
    strokeWidth(5)

    -- Do your drawing here
    startButtons:draw()
    text("PLANET CUTE : WORLDS", 524, 700)
    font("Verdana")
end
function touched(touch)
    startButtons:touched(touch)
    if start == true then
        function draw()
            person:draw()
            end
    end
    end

And yes this is an extremely early version of Planet Cute Worlds. I haven’t even configured the dpad yet.
And another thing- When I use a cursor, when it draws the player the game will not read touches

Welcome to Codeslinger’s random rant corner.

What the fuck is this mess supposed to do?

Sorry to offend beginners (and be glad to receive Codeslinger’s “Sorry”, it could be far worse), but that’s the only way to get you on a path of enlightenment.

I’m sure you omitted a bunch of code, but even the paltry rest raises confusion in abundance. I cannot read through it, I can hardly image what it’s doing except for painting a green background.

Before doing any more harm to innocent commands, explain. And don’t be shy to answer “dumb” questions.

What happens here?


(1) print(...)
(2) displayMode(FULLSCREEN_NO_BUTTONS)

And here?


(3) text(...)
(4) font(...)

Bonus question: Why is text eventually rendered with the given font?

Now this, especially at (6):


(5) if start == true then
(6)     function draw()
(7)         ...
(8)     end
(9) end

Remember, I know what these lines do (at least in this isolation), I want to know what your thoughts were when presenting us the whole abomination.

  1. puts words in the output box.
  2. Fullscreen, without the back/record/pic buttons
  3. Writes word at given x,y.
    4)Sets font type.
    5)Fonttype.
    6)A boolean value.
    This ‘mess’ is an extremely early version of Planet Cute Worlds.

@Codeslinger thanks for taking the time to respond. Next time don’t be so offensive in delivering your response.

@Punker2000 is learning, and is only 11 years old.

@Punker2000 in this code is the same problem happens in yours? :

-- Planet Cute: Worlds DEMO

-- Use this function to perform your initial setup
function setup()
    --print("Demo of Planet Cute: Worlds, an RPG I will be making for iOS. it will take a while.")
    displayMode(FULLSCREEN_NO_BUTTONS)
    start = true
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(0, 255,0,255)

    -- This sets the line thickness
    strokeWidth(5)

    -- Do your drawing here
    --startButtons:draw()
    text("PLANET CUTE : WORLDS", 524, 700)
    font("Verdana")
end
function touched(touch)
    --startButtons:touched(touch)
    if start == true then
        function draw()
            person:draw()
        end
    end
end

person = class()
function person:draw()
    -- Codea does not automatically call this method
    sprite("Planet Cute:Character Boy",CurrentTouch.x,CurrentTouch.y)
end

I fixed it, but I still don’t know how it happened. I made it where the guy is only drawn if the ‘started game’ value is true. I also added the dPad, but it’s kinda jittery.

I think the problem is to put

function draw()

end

In the touched function

All your problems are because you are trying to draw from the touched function. (There are a few articles on he wiki explaining why not to, here is a link). Try to use a variable to say when to draw the person, and set that variable in touch.

oh, and @Juanjo56, your code is doing that, because whenever your code calls the touched function, it overwrites the draw function. Try putting in a background(0,255,0) at the beginning of your new draw function.

Here is a modified version of @Juanjo56 code.

-- Planet Cute: Worlds DEMO

-- Use this function to perform your initial setup
function setup()
    --print("Demo of Planet Cute: Worlds, an RPG I will be making for iOS. it will take a while.")
    displayMode(FULLSCREEN_NO_BUTTONS)
    --start = true
    inTouch = false
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(0, 255,0,255)

    -- This sets the line thickness
    strokeWidth(5)

    -- Do your drawing here
    --startButtons:draw()
    text("PLANET CUTE : WORLDS", 524, 700)
    font("Verdana")
    if inTouch == true then
        person:draw()
    end
end
function touched(touch)
    --startButtons:touched(touch)
    -- commented all of this out, as it is doing the incorrect thing, and
    -- the start variable isn't needed
    --if start == true then
        --function draw()
            --person:draw()
        --end
    --end
    -- Toggles inTouch
    if touch.state == BEGAN then
        inTouch = true
    elseif touch.state == ENDED then
        inTouch = false
    end
end

person = class()
function person:draw()
    -- Codea does not automatically call this method
    sprite("Planet Cute:Character Boy",CurrentTouch.x,CurrentTouch.y)
end

How ever, this does not work with multi-touch. Here is code which does =

-- Planet Cute: Worlds DEMO

-- Use this function to perform your initial setup
function setup()
    --print("Demo of Planet Cute: Worlds, an RPG I will be making for iOS. it will take a while.")
    displayMode(FULLSCREEN) -- I HATE the no buttons mode.
    people = {}
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(0, 255,0,255)

    -- This sets the line thickness
    strokeWidth(5)

    -- Do your drawing here
    text("PLANET CUTE : WORLDS", 524, 700)
    font("Verdana")
    for _, v in pairs(people) do
        person:draw(v.x, v.y)
    end
end
function touched(touch)
    -- This adds, updates and removes the positions of the touches
    if touch.state == BEGAN then
        people[touch.id] = vec2(touch.x, touch.y)
    elseif touch.state == MOVING then
        people[touch.id] = vec2(touch.x, touch.y)
    elseif touch.state == ENDED then
        people[touch.id] = nil
    end
end

person = class()
function person:draw(x, y)
    -- Codea does not automatically call this method
    sprite("Planet Cute:Character Boy",x, y)
end

Punker, I thought of answers like:

(1) Prints something to the output window.

(2) Makes the output window go away (and also the buttons, so anybody who runs into it has to discover the 3-finger-triple to escape) so (1) will have no visible effect. I keep (1) just in case I don’t like (2) any more.

Maybe you want to restate what (3) and (4) do? And remember the bonus question.

I want you to understand the implications of what you have written and if others can understand it, too.

Like in those Shaolin movies, you first have to carry tubs of water around like a donkey before anyone shows you how to hit a tree without hurting yourself.

If you really want your sprite on the screen, we’ll get you there.

I fixed it! Geez…