Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to speed up the touch’s ticked up

pacpac
in Questions Posts: 79

Please if anyone knows how to get the touches to trigger fast please post how you did it.

Tagged:
«1

Comments

  • dave1707dave1707 Mod
    Posts: 7,155

    @pac Please stop creating a new discussion for every question you ask. Pick one of your existing discussions or this one, and ask all your questions there.

    As for your question, you can’t increase the speed of the touch or draw routine. They run at 60 times per second except I think on the newer iPads where they might run at 120 times per second. Even though you can’t increase the speed, the speed can be reduced as your programs get more complex. For complex programs where the speed is reduced on one type of iPad, they might run at normal speed (60) on devices with faster processors.

  • pacpac
    Posts: 79

    Sorry about the new discussion thing I will do that from now one.

  • pacpac
    Posts: 79

    Thanks for the touch info so I don’t keep looking for something that’s not there.

  • pacpac
    Posts: 79

    So do you know if when you publish it does the touch respond faster?

    Because if not I will need to redo me code.
    Please respond

    And thank you again and again Dave.

    Pac

  • dave1707dave1707 Mod
    edited November 18 Posts: 7,155

    @pac I’ve never published anything so I can’t say from experience. As I said above, the draw and touch routines run at 60 times per second so they probably do the same for published code. You’ll have to wait for someone who published code to give an exact answer.

    PS. What are you trying to do that you need faster touch. No one can touch the screen faster than 60 times per second.

  • pacpac
    Posts: 79

    My code just does not (never has) responded very fast even if it is in a program all on it’s on I won’t respond faster than about 1 touch per second. And I have an iPad Pro.

  • pacpac
    Posts: 79

    So if you could post how the touch should be done

    Thank you again pac

  • dave1707dave1707 Mod
    Posts: 7,155

    This will add 1 to the number as fast as you can touch the screen.

    function setup()
        fill(255)
        a=0
    end
    
    function draw()
        background(40, 40, 50)    
        text(a,WIDTH/2,HEIGHT/2)
    end
    
    function touched(t)
        if t.state==BEGAN then
            a=a+1
        end
    end
    
  • dave1707dave1707 Mod
    Posts: 7,155

    This will add 1 to the number as fast as you can move your finger across the screen.

    function setup()
        fill(255)
        a=0
    end
    
    function draw()
        background(40, 40, 50)    
        text(a,WIDTH/2,HEIGHT/2)
    end
    
    function touched(t)
        if t.state==MOVING then
            a=a+1
        end
    end
    
  • pacpac
    Posts: 79

    Okay thanks again I was not doing it the right way at all

    So thanks again.

  • pacpac
    Posts: 79

    Okay so I have run into a problem we’re I am trying to put down terrain but the problem is that I was using sprites but the problem is that it slows the program down to much to keep redrawing the sprites so does anyone know how to put something on the screen that won’t disappear?

    Please write if you do Pac

  • dave1707dave1707 Mod
    Posts: 7,155

    @pac Try using a mesh. Look it up in the reference and we’ll go from there.

  • pacpac
    Posts: 79

    I think I found how do to it with an image making it so that it only has to draw one sprite but could some one please post some code on how to do images

  • pacpac
    Posts: 79

    I okay I will check that out thanks

  • pacpac
    Posts: 79

    Can you put more than one sprite into a mesh?

  • pacpac
    Posts: 79

    Just a quick question I need to ask before I go to far

  • pacpac
    Posts: 79

    So I think I know the answer of the can they hold more than one sprite which is yes.

    But I don’t know who to work with pictures please post code

    Thanks pac

  • dave1707dave1707 Mod
    Posts: 7,155

    Here’s a lot of sprites and it still runs at full speed.

    displayMode(FULLSCREEN)
    
    function setup()
        tot,cnt=0,0
        rectMode(CENTER)
        size=20
        m=mesh()
        for x=1,WIDTH/size do
            for y=1,HEIGHT/size do
                m:addRect(x*size,y*size,size,size*2)
            end
        end
        m.texture="Planet Cute:Character Cat Girl"
    end
    
    function draw()
        background(40, 40, 50)
        m:draw()
        fill(255)
        rect(WIDTH/2,HEIGHT-50,70,30)
        fill(0)
        cnt=cnt+1
        tot=tot+DeltaTime
        text("fps "..cnt//tot,WIDTH/2,HEIGHT-50)
    end
    
  • pacpac
    Posts: 79

    Okay I see your use of mesh I think this will work.

    But with me track recorded I will be back on in about a minute

    Thanks

  • pacpac
    Posts: 79

    Hey It worked so thank you but before I put all my code on this how do you move the mesh around like if you needed to move it 100 down?

  • pacpac
    Posts: 79

    Okay I found a way that will work by doing that addRect again and changing the size. If this is the wrong way to do it please tell me but for know I will use this.

    Thanks again for answering all the questions I have had so far.

  • dave1707dave1707 Mod
    Posts: 7,155

    Look at the translate command under Graphics.

  • pacpac
    Posts: 79

    Okay will do but thank youuuuuuuu soooooooo much when I ran my code In with the FPS in there I was trying to draw so many sprites I had I down to 3FPS now it runs at 59FPS thank you so much.

    Pac

  • pacpac
    Posts: 79

    Hey Dave I am having a problem. I need to get a camera in craft to follow an entity but my problem is that I don’t know how and that the reference doesn’t make any sense some please help me.

  • dave1707dave1707 Mod
    Posts: 7,155

    Instead of moving the camera and the entity, move everything else so it looks like the camera and entity are moving. I don’t know what you’re doing, so I can’t give you too much help.

  • pacpac
    Posts: 79

    I am trying to make a space video game but the problem is that when you move the ship the ship flys off the screen

  • dave1707dave1707 Mod
    Posts: 7,155

    Here’s something I wrote a while ago. Run in landscape position. This might be like what you’re after. Slide your finger up or down the screen to increase or decrease your speed. Tilt the iPad left or right to turn. Fly thru the green balls but avoid the red balls.

    displayMode(FULLSCREEN)
    
    function setup() 
        assert(craft, "Please include Craft as a dependency")
        parameter.number("maxSpeed",.1,1.2,.5)
        parameter.watch("Gravity.x")
        parameter.watch("fps")
        setup1()
    end
    
    function setup1()
        mx,mz=0,0
        gameOver=false
        hgx=Gravity.x
        st=os.time()
        speed,ey,ang=0,45,0
        cameraX,cameraZ=-205,-205
        count=200
        yellow=0
        scene = craft.scene()
        scene.camera.position = vec3(cameraX,0,cameraZ)
        scene.camera.eulerAngles=vec3(ex,ey,ez)
        scene.sun.rotation = quat.eulerAngles(45,0,45)
        scene.ambientColor = color(90,90,90)
        skyMaterial = scene.sky.material
        skyMaterial.sky = color(252, 255, 0, 255)
        skyMaterial.horizon = color(0, 203, 255, 255)    
        tab={}
        for z=1,count do    -- 1=red
            createSphere(math.random(-200,200),math.random(-200,200),2,1,255,0,0,0,0)
        end
        for z=1,count do    -- 2=green
            createSphere(math.random(-200,200),math.random(-200,200),.25,2,0,255,0,0,0)
        end
        createFloor()
    end
    
    function update(dt)
        scene:update(dt)
        scene.camera.position = vec3(cameraX,1,cameraZ)
        scene.camera.eulerAngles=vec3(0,ey,0)
    end
    
    function draw()
        fps=1/DeltaTime//1
        background(0)
        if gameOver then
            sprite("Tyrian Remastered:Explosion Huge",WIDTH/2,HEIGHT/2,500,500)
            fill(255,0,0)
            text("Hold the ipad level then",WIDTH/2,HEIGHT/2+50)
            text("Double tap the screen to restart",WIDTH/2,HEIGHT/2)
            text(200-count.." hits in "..en-st.." seconds",WIDTH/2,HEIGHT/2-50)
            val=string.format("%5.2f",(200-count)/(en-st))
            text(val.." hits per second",WIDTH/2,HEIGHT/2-100)
            return
        end
        en=os.time()
        update(DeltaTime)
        scene:draw()
        if speed>maxSpeed then
            speed=maxSpeed
        elseif speed<=0 then
            speed=0
        end
        ey=ey-ang
        x=speed*math.sin(math.rad(ey))
        z=speed*math.cos(math.rad(ey)) 
        cameraX=cameraX+x
        cameraZ=cameraZ+z
        for a,b in pairs(tab) do
            if b.type==1 then
                if cameraX>=b.ent.position.x-b.size and cameraX<=b.ent.position.x+b.size and 
                        cameraZ>=b.ent.position.z-b.size and cameraZ<=b.ent.position.z+b.size then
                    gameOver=true
                    sound(SOUND_EXPLODE, 27037)
                end
            end
            if b.type==2 then
                if cameraX>b.ent.position.x-b.size and cameraX<b.ent.position.x+b.size and 
                        cameraZ>b.ent.position.z-b.size and cameraZ<b.ent.position.z+b.size then
                    b.ent:destroy()
                    table.remove(tab,a)
                    count=count-1
                    sound(SOUND_HIT, 19423)
                    createSphere(math.random(-200,200),math.random(-200,200),.5,3,255,255,0,.2,.2)
                    yellow=yellow+1
                end
            end
            if b.type==3 then
                if cameraX>=b.ent.position.x-b.size and cameraX<=b.ent.position.x+b.size and 
                        cameraZ>=b.ent.position.z-b.size and cameraZ<=b.ent.position.z+b.size then
                    b.ent:destroy()
                    table.remove(tab,a)
                    yellow=yellow-1
                    sound(SOUND_POWERUP, 19422)
                else
                    xx=b.ent.position.x
                    zz=b.ent.position.z
                    xx=xx+b.xv
                    zz=zz+b.zv
                    if xx<-200 or xx>200 then
                        b.xv=-b.xv
                    end
                    if zz<-200 or zz>200 then
                        b.zv=-b.zv
                    end
                    b.ent.position=vec3(xx,1,zz)
                end
            end
        end
        gx=Gravity.x
        ang=ang+(gx-hgx)*4
        hgx=gx
        pushMatrix()
        translate(WIDTH/2,HEIGHT/2-100)
        rotate(ang*-30)
        sprite("Tyrian Remastered:Boss A",0,0,300)
        fill(255)
        text(count.."  ".."  "..yellow.."  "..string.format("%2.1f",speed),0,0)
        translate()
        popMatrix()
        if speed==0 then
            text("Slide your finger up/down to + or - the speed",WIDTH/2,HEIGHT-50)
        end
    end
    
    function touched(t)
        if t.state==BEGAN then
            if t.tapCount==2 and gameOver then
                setup1()
                return
            else
                ang=0
            end
        elseif t.state==MOVING then
            speed=speed+t.deltaY/80
        end
    end
    
    function createFloor(x,z)
        c1=scene:entity()
        w=c1:add(craft.rigidbody,STATIC)
        c1.model = craft.model.cube(vec3(400,1,400))
        c1.position=vec3(x,-.5,z)
        c1.material = craft.material("Materials:Standard")
        c1.material.map = readImage("Blocks:Cactus Top")
        c1.material.offsetRepeat=vec4(0,0,50,50)
    end
    
    function createSphere(x,z,size,type,r,g,b,xv,zv)
        sphere1=scene:entity()
        s1=sphere1:add(craft.rigidbody,KINEMATIC)
        sphere1.position=vec3(x,1,z)
        sphere1:add(craft.shape.sphere,size)
        sphere1.model = craft.model.icosphere(size,1)
        sphere1.material = craft.material("Materials:Specular")
        sphere1.material.diffuse=color(r,g,b)
        table.insert(tab,{ent=sphere1,xv=xv,zv=zv,size=size,type=type})
    end
    
  • Posts: 1,014

    @dave1707 - yeah, great demo you posted before. Just made a few changes - not polished and needs a few obvious mods but changed the createSphere() mod to add a little variety:


    function createSphere(x,z,size,type,r,g,b,xv,zv) sphere1=scene:entity() s1=sphere1:add(craft.rigidbody,KINEMATIC) sphere1.position=vec3(x,0,z) mat = tostring(math.floor(math.random(20)+40)) sphere1.model = craft.model("Nature:naturePack_0"..mat) table.insert(tab,{ent=sphere1,xv=xv,zv=zv,size=size,type=type}) end

    Anyone else want to tidy/add anything?

  • dave1707dave1707 Mod
    edited November 24 Posts: 7,155

    @Bri_G That makes it different and hard to know what to hit or avoid. It takes a really long time to load on my iPad Air. When I first posted this it was a starter game for anyone to add whatever they wanted to it. I still play with it every now and then. I got the green balls down in the teens, but the yellow balls are hard to get. I was thinking of adding more tries so the game didn’t end after one bad collision but then I like just flying around hitting the green balls and chasing the yellow balls. Here’s the original link from about a year ago.

    https://codea.io/talk/discussion/8932/starter-game-22#latest
    
  • pacpac
    Posts: 79

    Yes that is something like what I need but I am can’t see where you move the camera / object around. Please point it out.

  • dave1707dave1707 Mod
    Posts: 7,155

    @pac Look thru the code for all occurances where I use camera. The camera gets moved in the draw function just before the large for loop where I modify cameraX and cameraZ. In the setup function I define the camera using the variables cameraX and cameraZ.

  • edited November 24 Posts: 1,014
    @dave1707 - yes, does take a long time to initialise. I just like flying around objects trying to avoid all of them. Will play around with it, but later. See if I can improve the startup and avoid having to restart. Could make a few games out of this. Thanks for reposting it.
  • dave1707dave1707 Mod
    Posts: 7,155

    @pac I stripped out all of the code except for the code moving the camera and ship. See if that helps any.

    displayMode(FULLSCREEN)
    
    function setup() 
        assert(craft, "Please include Craft as a dependency")
        hgx=Gravity.x
        speed,ey,ang=.1,45,0
        cameraX,cameraZ=-205,-205
    
        scene = craft.scene()
    
        scene.camera.position = vec3(cameraX,0,cameraZ)
    
        skyMaterial = scene.sky.material
        skyMaterial.sky = color(252, 255, 0, 255)
        skyMaterial.horizon = color(0, 203, 255, 255)    
    
        createFloor()
    end
    
    function update(dt)
        scene:update(dt)
        scene.camera.position = vec3(cameraX,1,cameraZ)
        scene.camera.eulerAngles=vec3(0,ey,0)
    end
    
    function draw()
        background(0)
        update(DeltaTime)
        scene:draw()
    
        ey=ey-ang
        x=speed*math.sin(math.rad(ey))
        z=speed*math.cos(math.rad(ey)) 
        cameraX=cameraX+x
        cameraZ=cameraZ+z    
        gx=Gravity.x
        ang=ang+(gx-hgx)*4
        hgx=gx
    
        pushMatrix()
        translate(WIDTH/2,HEIGHT/2-100)
        rotate(ang*-30)
        sprite("Tyrian Remastered:Boss A",0,0,300)
        translate()
        popMatrix()
    end
    
    function createFloor(x,z)
        c1=scene:entity()
        w=c1:add(craft.rigidbody,STATIC)
        c1.model = craft.model.cube(vec3(400,1,400))
        c1.position=vec3(x,-.5,z)
        c1.material = craft.material("Materials:Standard")
        c1.material.map = readImage("Blocks:Cactus Top")
        c1.material.offsetRepeat=vec4(0,0,50,50)
    end
    
  • dave1707dave1707 Mod
    Posts: 7,155

    @Bri_G It is kind of fun just flying around. The part I like best is chasing the yellow balls. Maybe I’ll remove the red balls so I don’t have to run into them.

  • pacpac
    Posts: 79

    Okay thanks that really helped

  • pacpac
    Posts: 79

    Is there an app that lets me make 3D models on my iPad?

    If you don’t know by the morning/don’t respond I am going to make new discussion tomorrow.

    Thanks pac

  • pacpac
    Posts: 79

    So I am trying to make a game that uses the water craft stuff the problem is that I can find an water so could you please tell me how I could change a plane to have a blue color or tell me who to put a sprite on a plane both are good but the second on is better.

    Thanks Pac

  • dave1707dave1707 Mod
    edited November 29 Posts: 7,155

    @pac Here’s another version where I had more time to play around with it. It takes about 5 seconds to load because of the models.

    displayMode(FULLSCREEN)
    
    function setup() 
        assert(craft, "Please include Craft as a dependency")
        hgx=Gravity.x
        speed,ey,ang=.1,45,0
        cameraX,cameraZ=-200,-200
        scene = craft.scene()
        scene.camera.position = vec3(cameraX,0,cameraZ)
        skyMaterial = scene.sky.material
        skyMaterial.sky = color(252, 255, 0, 255)
        skyMaterial.horizon = color(0, 156, 255, 255)        
        createShip(50)
        createSea()
    end
    
    function update(dt)
        scene:update(dt)
        scene.camera.position = vec3(cameraX,1,cameraZ)
        scene.camera.eulerAngles=vec3(0,ey,0)
    end
    
    function draw()
        background(0)
        update(DeltaTime)
        scene:draw()
        ey=ey-ang
        x=speed*math.sin(math.rad(ey))
        z=speed*math.cos(math.rad(ey)) 
        cameraX=cameraX+x
        cameraZ=cameraZ+z    
        gx=Gravity.x
        ang=ang+(gx-hgx)*4
        hgx=gx
    end
    
    function createShip(nbr)
        for z=1,nbr do
            sh=scene:entity()  
            sh.position=vec3(math.random(-200,200),0,math.random(-200,200))
            mr=sh:add(craft.renderer) 
            mr.model=craft.model("Watercraft:watercraftPack_"..string.format("%03d",math.random(29)))
        end
    end
    
    function createSea(nbr)
        c1=scene:entity()
        c1.model = craft.model.cube(vec3(400,1,400))
        c1.position=vec3(0,-.15,0)
        c1.material = craft.material("Materials:Standard")
        c1.material.map = readImage("Surfaces:Desert Cliff Normal")
        c1.material.offsetRepeat=vec4(0,0,20,20)
        c1.material.diffuse=color(0, 183, 255, 255)
    end
    
  • pacpac
    Posts: 79

    Thanks

  • pacpac
    Posts: 79

    Okay I have a problem that is driving me mad. So in my game in had the set up and all then I choose that it needed to have a menu it started on so I moved the setup and draw to a new file and renamed the setup (and made a new one) but now it keeps saying error the line that the setup was on before can you please tell me who to remove this error.

    Thanks pac

  • pacpac
    Posts: 79

    It’s okay I ficked it all I did was put it back where it was then it went away.

  • pacpac
    Posts: 79

    How do you clear a sprite off the screen. And have a scene start drawing?

    Thanks pac

  • dave1707dave1707 Mod
    Posts: 7,155

    To clear a sprite off the screen, you stop drawing it. To have a scene start drawing, you start drawing it. Your question isn’t very clear as to what you’re trying to do.

  • edited November 30 Posts: 1,014
    @pac - to switch sprites on and off you need a conditional check ...

    ~~~
    If condition == true then
    show sprite
    else
    Dont show sprite
    end
    ~~~

    You obviously need to add your own code, you may want to move the sprite, change it move to another page if your sprite is a button. All in draw() function or a sub function called within the draw function.

    Hope that helps.
  • pacpac
    Posts: 79

    I know that is how it suppose to work but when I stop drawing the sprite it stays one the screen and blinks

  • pacpac
    Posts: 79

    On sorry bad iPad spellcheck

  • edited November 30 Posts: 1,014

    @pac - show us a little of your code then we understand what you are trying to do.

    Sounds like you are alternating a conditions.

  • pacpac
    Posts: 79

    function MainMenuDraw()

    if GameMode == 1 then
        --draw the sprite for the start button
    
    
    
        if i < 120 then
            sprite("Project:entry001", 500, 500, 200, 200)
    
        end
    
        i = i + 1
    
    end
    print(i)
    

    end

    This function gets called by the draw function but the sprite does not go away after i go over 120 so please help me know ho to get the sprite to go away.

  • Posts: 1,014

    @pac - check to see if you modify i in your other code, it looks like a global. If it resets to 0 or 1 then you will never stop it displaying hence the flash when
    I == 121.

    Also, it looks like you may be waiting for a start button to be tapped. You should set that code up in the touched(t) function. Without seeing most of your code we can’t see where the error is.

  • dave1707dave1707 Mod
    Posts: 7,155

    @pac Do you have the background() command at the start of your draw() function. Sounds like you’re not clearing the screen each draw cycle.

Sign In or Register to comment.