@CodeaBin You’re calling pixelText before it’s created as a function. Either move title = pixelText...
to lower than the pixelText function, or put it in setup.
Ohh, i see now silly me.
Ok, so now its inside setup ( thought it was ), and it says codea got nil on sprite (title)
But i put title= pixelText…
Ok i updated code above.
Little Update.
https://www.dropbox.com/s/t5z3ydpxe46bt65/Video%201-27-2014%2C%205%2001%2056%20PM.mp4
Can someone tell me why its not switching walking images when i hold down the right arrow?
-- shiptest
displayMode(FULLSCREEN)
male=true
walkTimer=0
-- character setup
if male==true then
char = readImage("Documents:male")
end
if female==true then
char = readImage("Documents:female")
end
-- character position
charP = vec2(100,220)
-- controls setup
arrow = readImage("Cargo Bot:Command Right")
arrowP = vec2(100,100)
arrow2 = readImage("Cargo Bot:Command Left")
arrow2P = vec2(50,100)
-- Use this function to perform your initial setup
function setup()
noSmooth()
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
sprite("Documents:space",WIDTH/2,HEIGHT/2,1024,768)
--sprite("Dropbox:Ship",WIDTH/2,HEIGHT/2,2800,526)
sprite("Documents:earth",WIDTH/2,-225,1750,1050)
sprite("Dropbox:Ship",WIDTH/2,HEIGHT/2,2800,415)
-- sprite draw
sprite(char,charP.x,charP.y)
sprite(arrow,arrowP.x,arrowP.y)
sprite(arrow2,arrow2P.x,arrow2P.y)
-- walk left/right setup
if walk==true then
charP.x=charP.x + 1
end
if walk2==true then
charP.x=charP.x - 1
end
-------------------------
if walkAnimation==true then
walkTimer=walkTimer +1
end
if walkTimer > 1 then
char=readImage("Documents:female")
end
if walkTimer > 2 then
char=readImage("Documents:femalewalk")
end
if walkTimer > 2 then
walkTimer=1
end
-- Do your drawing here
end
function touched(touch)
-- Codea does not automatically call this method
if touch.state==BEGAN then
if touch.x>arrowP.x-arrow.width/2 and touch.x<arrowP.x+arrow.width/2 and
touch.y>arrowP.y-arrow.height/2 and touch.y<arrowP.y+arrow.height/2 then
walkAnimation=true
walk=true
end
if touch.x>arrow2P.x-arrow2.width/2 and touch.x<arrow2P.x+arrow2.width/2 and
touch.y>arrow2P.y-arrow2.height/2 and touch.y<arrow2P.y+arrow2.height/2 then
walk2=true
end
end
if touch.state==ENDED then
walk=false
walk2=false
walkAnimation=false
walkTimer=1
end
end
Wanna help?
I know this is completely unrelated, but it reminds me of Planetroids
(Not saying you copied it!)
From taking a brief look at the code, I can’t quite tell. To debug it, try printing all of your variables and see if there is anything out of place. That’s a very good tactic used in very basic debugging.
Thanks!
Edit: Where is the “end” for the “if touch.state == BEGAN”? That could be your problem, but Codea should raise an error…
I have two “ends” on the bottom of touch.state == ENDED?
@Codeabin I don’t have the sprites you have in the code so I had to substitute other sprites which doesn’t give the same effect. But when I press on the right arrow, it alternates the sprites which I assume makes it walk. If I hold down the left arrow, the sprite doesn’t alternate. Did you mean the left arrow doesn’t work.
EDIT: You probably need walkAnimation=true in both of the “if” statements in touched(), not just in the one “if”.
I want it so it keep looping the walking effect over and over again if i hold down the right arrow. It only does the walking effect if i tap it.
@Codeabin This code works for me, in both directions.
function touched(touch)
-- Codea does not automatically call this method
if touch.state==BEGAN then
if touch.x>arrowP.x-arrow.width/2 and touch.x<arrowP.x+arrow.width/2 and
touch.y>arrowP.y-arrow.height/2 and touch.y<arrowP.y+arrow.height/2 then
walkAnimation=true
walk=true
end
if touch.x>arrow2P.x-arrow2.width/2 and touch.x<arrow2P.x+arrow2.width/2 and
touch.y>arrow2P.y-arrow2.height/2 and touch.y<arrow2P.y+arrow2.height/2 then
walkAnimation=true
walk2=true
end
end
if touch.state==ENDED then
walk=false
walk2=false
walkAnimation=false
walkTimer=2
end
end
This doesn’t change images when it moves, i want it so when you hold the right arrow down it loops the walking images so it looks like the person is walking and when they stop holding down the right arrow it changes into the normal sprite and stops moving.
@Dave try it with these images
Walking:
https://www.dropbox.com/s/4n0fl9sko26qde8/Photo%201-27-2014%2C%206%2004%2035%20PM.png
Normal:
https://www.dropbox.com/s/z8knz2oodyjxa5y/Photo%201-26-2014%2C%202%2012%2057%20PM.png