Project issues

@bhob12 - this is where you should read the built in docs. Look in the Animation section, for tween.sequence.

@bhob12 If you want to animate something look at the built in docs and the animation example as @Ignatz suggests.

If you need to call a function after x amount of time you can use tween.delay(). You will need to trigger it as it runs one time. If you want to call a function every x seconds you can do this:

function setup()
    delay(3)
end
    
function delay(d)
tween.delay(d,function() print("Hello World") delay(d) end)

end

I suspect that you are wanting to use this for animations, in that case @Ignatz is correct with tween.sequence()

I’m still finding the whole tween.delay troubling… how do you use it. The built in codea description isint helping…

How do I draw a triangle and fill it in?

How do I draw a triangle and fill it
So:

Fill(12,12,35)

Then what?

@bhob12 You can draw a triangle with “line”, but there isn’t an easy way to fill it in. To do that, you need to use a mesh. Here is a simple example that draws a triangle and fills it with the color red.


function setup()
    myMesh = mesh()  -- define mesh
    myMesh.vertices = {vec2(100,100),vec2(200,200),vec2(200,100)} -- coordinates
    myMesh:setColors(255,0,0)  -- set the color red
end

function draw()
    background(40, 40, 50)
    myMesh:draw()  -- draw the triangular mesh
end

Thanks a lot

How do I (use) a sprite.

@bhob12 Move you finger around the screen.


function setup()
    dx=WIDTH/2
    dy=HEIGHT/2
end

function draw()
    background(40,40,50)
    fill(255)
    text("move your finger around the screen",WIDTH/2,HEIGHT-100)
    sprite("Planet Cute:Character Cat Girl",dx,dy)
    text(dx,WIDTH/2,HEIGHT-200)
    text(dy,WIDTH/2,HEIGHT-250)
end

function touched(t)
    if t.state==MOVING then
        dx=dx+t.deltaX
        dy=dy+t.deltaY
    end
end

How do I text a variable so that it appears on the screen but the value can change therefore the # on the screen can change with it (because they’re the same)

@bhob12 See the above code. I added 2 text statement in the draw() function to display the x and y location of the sprite as you move it around.

How do I add iAd … Also how would I use the keyboard on the ipad/iPhone and type with it on the computer? Thx

iAds involve an exported Codea project in Xcode and some knowledge of Obj-C.

On Macs, you can use your hardware keyboard when the virtual keyboard appears.

–I know my code isn’t very pretty and I know that it is hanging by a thread :expressionless: but help is still very much appreciated. –

–My current problem is as follows: I have created a variable called “score”. A value of 1 is added to it every time a sprite called “img” passes off the screen inbetween two lines. If the “img” were to touch one of the two lines on either side of the screen the game would end and what im trying to make happen is for the score to actually say the correct # instead of 0. It says 0 because every time the sprite goes of the screen it is redrawn at the top of the screen. –

–if blueY <= 5 then
blueY = HEIGHT
blueX = math.random(0,WIDTH)
sprite(img,blueX,blueY)
score = score + 1
end–

–The “score” variable is 1 for a short moment but then when the “img” is redrawn at the top of the screen the score is back to 0 because blueY no longer is <= 5.–
–As always I’m very thankful to those who respond and try to help.–


function setup()
        supportedOrientations(PORTRAIT)
        menu = true
        play = false
        options = false
        more = false
        lose = false
        musictap = false
        nomusictap = false
        score = 0
        local x = 300
        local y = 1000
--blueX changes where the "img" is located every time it appears at the top of the screen--
        blueX = WIDTH/2
        blueY = HEIGHT
        music("Game Music One:Toy Land")
end


 
function draw()
    
    if menu then
        
        background(29, 41, 51, 255)
        fill(6, 126, 233, 255)
        font("Baskerville-SemiBold")
        fontSize(100)
        text("Blueberry",WIDTH/2,(HEIGHT/10) *8)
        text("Crumble",WIDTH/2,(HEIGHT/10) * 7)
        fill(92, 71, 109, 255)
        ellipse((WIDTH/10) * 2,(HEIGHT/10) * 4,(WIDTH/40) * 7,(WIDTH/40) * 7)
        ellipse((WIDTH/10) * 2,(HEIGHT/10) * 2,(WIDTH/40) * 7,(WIDTH/40) * 7)
        fontSize(35)
        fill(255, 255, 255, 255)
        text("Play",(WIDTH/10) * 2,(HEIGHT/10) * 4)
        text("How",(WIDTH/10) * 2,(HEIGHT/10) * 2)
        fill(92, 71, 109, 255)
        ellipse((WIDTH/10) * 8,(HEIGHT/10) * 4,(WIDTH/40) * 7,(WIDTH/40) * 7)
        ellipse((WIDTH/10) * 8,(HEIGHT/10) * 2,(WIDTH/40) * 7,(WIDTH/40) * 7)
        fill(255, 255, 255, 255)
        text("Options",(WIDTH/10) * 8,(HEIGHT/10) * 4)
        text("More",(WIDTH/10) * 8,(HEIGHT/10) * 2)
        
    elseif play then
       
        score = 0
        local gapWidth = 30
        local blueSpeed = 5
        blueY = blueY - blueSpeed
        
        background(12, 144, 239, 255)
        stroke(127, 127, 127, 255)
        strokeWidth(5)
        line(0,10,WIDTH/2-gapWidth,10)
        line(WIDTH/2+gapWidth,10,WIDTH,10)      
        sprite(img,blueX,blueY)
        
        if play and blueX-16 > WIDTH/2-30 and blueX+16 < WIDTH/2+30 and blueY < 10 then 
            background(48, 109, 55, 255)
            end
        
        if play and blueX-16 < WIDTH/2-30 and blueY-16 <=10 or blueX+16 > WIDTH/2+30 and blueY-16 <=10 then 
            lose = true
            play = false
            music.stop()
            sound(SOUND_EXPLODE)
            end
        
        if play and blueY+16 <= 5 then
            blueY = HEIGHT
            blueX = math.random(0,WIDTH)
            sprite(img,blueX,blueY)
            score = score + 1     
            end
        
    elseif lose then
            local gapWidth = 30
            background(12, 144, 239, 255)
            line(0,10,WIDTH/2-gapWidth,10)
            line(WIDTH/2+gapWidth,10,WIDTH,10)   
            fill(127, 127, 127, 255)
            ellipse(WIDTH/2,HEIGHT/2,WIDTH,WIDTH)
            fill(255, 255, 255, 255)
            font("Baskerville-Bold")
            text("Your score was: "..score,WIDTH/2,(HEIGHT/8)*3)
        
    elseif how then 
            background(29, 41, 51, 255)
            text("Tilt the blueberries into the gap", WIDTH/2, (HEIGHT/4) * 3)
            text("Don't let them hit the line or it's game over",WIDTH/2,(HEIGHT/8)*5)
            fill(92, 71, 109, 255)
            ellipse((WIDTH/10) * 2,(HEIGHT/10) * 4,(WIDTH/40) * 7,(WIDTH/40) * 7)
            ellipse((WIDTH/2),(HEIGHT/10) * 4,(WIDTH/40) * 7,(WIDTH/40) * 7)
            fontSize(35)
            fill(255, 255, 255, 255)
            text("Play",(WIDTH/10) * 2,(HEIGHT/10) * 4)
            text("Back",(WIDTH/2),(HEIGHT/10) * 4)
        
    elseif options then
            background(29, 41, 51, 255)
            fill(92, 71, 109, 255)
            ellipse((WIDTH/2),(HEIGHT/10) * 4,(WIDTH/40) * 7,(WIDTH/40) * 7)
            fill(255, 255, 255, 255)
            text("Back",(WIDTH/2),(HEIGHT/10) * 4)
            text("Music:",(WIDTH/10)*4,HEIGHT/2)
            text("On",420,510)
            text("Off",505,510)
           
    elseif more then
            background(29, 41, 51, 255)

    end

end



function touched(touch)
    local a = touch.x
    local b = touch.y

    if menu and a>100 and a<200 and b>340 and b<485 or how and a>100 and a<200 and b>340 and b<485 then
        play = true
        menu = false
    elseif menu and a>100 and a<200 and b>120 and b<285 then
        menu = false
        how = true
    elseif menu and a>600 and a<700 and b>340 and b<485 then
        options = true
        menu = false
    elseif menu and a>600 and a<700 and b>120 and b<285 then
        menu = false
        more = true
    elseif how and a>WIDTH/2-50 and a<WIDTH/2+50 and b>340 and b<485 then
        menu = true
        how = false
    elseif options and a>WIDTH/2-50 and a<WIDTH/2+50 and b>340 and b<485 then
        menu = true
        options = false
    elseif options and a>395 and a<460 and b>495 and b<520 then
        music("Game Music One:Toy Land",loop)
        nomusictap = false
        musictap = true
    elseif options and a>480 and a<540 and b<520 and b>495 then
        music.stop()
        nomusictap = true
        musictap = false
    end
end

–The image is a spritely I made so I put it in a new class and called the image “img”.–

–The code for that is below–

@bhop12 You’re always setting score=0 in your “if play” section in draw(). You should probable set score=0 in setup and menu.

@bhop12 Here’s your code. I commented out the score=0 in draw. I added blueX=blueX+Gravity.x*5 at the end of draw to move the sprite when the iPad is tilted. I also changed “img” to a sprite I have because I don’t know where img was coming from.


displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT)
    
function setup()
    menu = true
    play = false
    options = false
    more = false
    lose = false
    musictap = false
    nomusictap = false
    score = 0
    local x = 300
    local y = 1000
    -- blueX changes where the "img" is located every time 
    -- it appears at the top of the screen
    blueX = WIDTH/2
    blueY = HEIGHT
    music("Game Music One:Toy Land")
end

function draw()
    if menu then
        background(29, 41, 51, 255)
        fill(6, 126, 233, 255)
        font("Baskerville-SemiBold")
        fontSize(100)
        text("Blueberry",WIDTH/2,(HEIGHT/10) *8)
        text("Crumble",WIDTH/2,(HEIGHT/10) * 7)
        fill(92, 71, 109, 255)
        ellipse((WIDTH/10) * 2,(HEIGHT/10) * 4,(WIDTH/40) * 7,(WIDTH/40) * 7)
        ellipse((WIDTH/10) * 2,(HEIGHT/10) * 2,(WIDTH/40) * 7,(WIDTH/40) * 7)
        fontSize(35)
        fill(255, 255, 255, 255)
        text("Play",(WIDTH/10) * 2,(HEIGHT/10) * 4)
        text("How",(WIDTH/10) * 2,(HEIGHT/10) * 2)
        fill(92, 71, 109, 255)
        ellipse((WIDTH/10) * 8,(HEIGHT/10) * 4,(WIDTH/40) * 7,(WIDTH/40) * 7)
        ellipse((WIDTH/10) * 8,(HEIGHT/10) * 2,(WIDTH/40) * 7,(WIDTH/40) * 7)
        fill(255, 255, 255, 255)
        text("Options",(WIDTH/10) * 8,(HEIGHT/10) * 4)
        text("More",(WIDTH/10) * 8,(HEIGHT/10) * 2)
    elseif play then

        --score = 0     commented this line

        local gapWidth = 30
        local blueSpeed = 5
        blueY = blueY - blueSpeed
        background(12, 144, 239, 255)
        stroke(127, 127, 127, 255)
        strokeWidth(5)
        line(0,10,WIDTH/2-gapWidth,10)
        line(WIDTH/2+gapWidth,10,WIDTH,10)    
  
        sprite("Planet Cute:Gem Orange",blueX,blueY,50)  -- changed sprite

        if play and blueX-16 > WIDTH/2-30 and blueX+16 < WIDTH/2+30 and 
                blueY < 10 then 
            background(48, 109, 55, 255)
        end
        if play and blueX-16 < WIDTH/2-30 and blueY-16 <=10 or 
                blueX+16 > WIDTH/2+30 and blueY-16 <=10 then 
            lose = true
            play = false
            music.stop()
            sound(SOUND_EXPLODE)
        end
        if play and blueY+16 <= 5 then
            blueY = HEIGHT
            blueX = math.random(0,WIDTH)

            sprite("Planet Cute:Gem Orange",blueX,blueY,50)  -- changed sprite

            score = score + 1     
        end
    elseif lose then
        local gapWidth = 30
        background(12, 144, 239, 255)
        line(0,10,WIDTH/2-gapWidth,10)
        line(WIDTH/2+gapWidth,10,WIDTH,10)   
        fill(127, 127, 127, 255)
        ellipse(WIDTH/2,HEIGHT/2,WIDTH,WIDTH)
        fill(255, 255, 255, 255)
        font("Baskerville-Bold")
        text("Your score was: "..score,WIDTH/2,(HEIGHT/8)*3)
    elseif how then 
        background(29, 41, 51, 255)
        text("Tilt the blueberries into the gap", WIDTH/2, (HEIGHT/4) * 3)
        text("Don't let them hit the line or it's game over",WIDTH/2,(HEIGHT/8)*5)
        fill(92, 71, 109, 255)
        ellipse((WIDTH/10) * 2,(HEIGHT/10) * 4,(WIDTH/40) * 7,(WIDTH/40) * 7)
        ellipse((WIDTH/2),(HEIGHT/10) * 4,(WIDTH/40) * 7,(WIDTH/40) * 7)
        fontSize(35)
        fill(255, 255, 255, 255)
        text("Play",(WIDTH/10) * 2,(HEIGHT/10) * 4)
        text("Back",(WIDTH/2),(HEIGHT/10) * 4)
    elseif options then
        background(29, 41, 51, 255)
        fill(92, 71, 109, 255)
        ellipse((WIDTH/2),(HEIGHT/10) * 4,(WIDTH/40) * 7,(WIDTH/40) * 7)
        fill(255, 255, 255, 255)
        text("Back",(WIDTH/2),(HEIGHT/10) * 4)
        text("Music:",(WIDTH/10)*4,HEIGHT/2)
        text("On",420,510)
        text("Off",505,510)
    elseif more then
        background(29, 41, 51, 255)
    end    

    blueX=blueX+Gravity.x*5 -- added this line of code

end

function touched(touch)
    local a = touch.x
    local b = touch.y
    if menu and a>100 and a<200 and b>340 and b<485 or 
            how and a>100 and a<200 and b>340 and b<485 then
        play = true
        menu = false
    elseif menu and a>100 and a<200 and b>120 and b<285 then
        menu = false
        how = true
    elseif menu and a>600 and a<700 and b>340 and b<485 then
        options = true
        menu = false
    elseif menu and a>600 and a<700 and b>120 and b<285 then
        menu = false
        more = true
    elseif how and a>WIDTH/2-50 and a<WIDTH/2+50 and b>340 and b<485 then
        menu = true
        how = false
    elseif options and a>WIDTH/2-50 and a<WIDTH/2+50 and b>340 and b<485 then
        menu = true
        options = false
    elseif options and a>395 and a<460 and b>495 and b<520 then
        music("Game Music One:Toy Land",loop)
        nomusictap = false
        musictap = true
    elseif options and a>480 and a<540 and b<520 and b>495 then
        music.stop()
        nomusictap = true
        musictap = false
    end
end

Wow thanks a lot this is really helpful and I’m thankful.

When I run my codea project in xcode, (in the ios simulator) it still has the parameter bank in the left of the screen and the four icons in the bottom of the left hand corner are still there… I’m not sure why they’re there. Can someone help

@bhob12 displayMode(FULLSCREEN_NO_BUTTONS)

Are you using

displayMode(FULLSCREEN_NO_BUTTONS)