@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.
@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.
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.
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
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
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?
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
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
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.
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.
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.
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.
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
@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
@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.
@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.
@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.
@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.
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.
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.
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.
@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.
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.
@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.
Comments
@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.
Sorry about the new discussion thing I will do that from now one.
Thanks for the touch info so I don’t keep looking for something that’s not there.
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
@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.
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.
So if you could post how the touch should be done
Thank you again pac
This will add 1 to the number as fast as you can touch the screen.
This will add 1 to the number as fast as you can move your finger across the screen.
Okay thanks again I was not doing it the right way at all
So thanks again.
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
@pac Try using a mesh. Look it up in the reference and we’ll go from there.
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
I okay I will check that out thanks
Can you put more than one sprite into a mesh?
Just a quick question I need to ask before I go to far
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
Here’s a lot of sprites and it still runs at full speed.
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
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?
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.
Look at the translate command under Graphics.
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
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.
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.
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
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.
@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:
Anyone else want to tidy/add anything?
@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.
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.
@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.
@pac I stripped out all of the code except for the code moving the camera and ship. See if that helps any.
@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.
Okay thanks that really helped
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
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
@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.
Thanks
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
It’s okay I ficked it all I did was put it back where it was then it went away.
How do you clear a sprite off the screen. And have a scene start drawing?
Thanks pac
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.
~~~
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.
I know that is how it suppose to work but when I stop drawing the sprite it stays one the screen and blinks
On sorry bad iPad spellcheck
@pac - show us a little of your code then we understand what you are trying to do.
Sounds like you are alternating a conditions.
function MainMenuDraw()
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.
@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.
@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.