Project Issues

Instead of being a hindrance to the community and constantly asking questions, upon suggestion this thread is now a place where I’ll post my issues, compact in one little thread. If any other new people, such as myself, happen to stumble upon this thread maybe they can also learn.

Current problem: Not so much of a problem but a misunderstanding. I cannot figure out physics. I’ve studied the reference and physics lab tests but I can’t wrap my head around it. I want to know how to use your own images and apply physics to them. Help, please?

@Treshur - I suggest you use a single thread for all your problems on the same project, to avoid cluttering the forum. You can edit the subject if you want (just edit the original post).

Codea provides its own time calculation with DeltaTime (fraction of a second since the last draw), so I wouldn’t add 0.1, but DeltaTime instead.

Where you say “elseif timer > 5 and animrun == true then” you then go on to set timer=12 and run it down to zero. The problem is that the next time Codea draws, timer will still be > 5 and animrun is still true, so it will set timer=12 again…and again…and again. You need to change animrun (or maybe another indicator variable) so this code only runs once.

@Treshur here is a simple example with tween.

function setup()
    print("Hello World")
    imgs = {readImage("Planet Cute:Character Boy"),
    readImage("Planet Cute:Character Cat Girl"),
    readImage("Planet Cute:Character Horn Girl"),
    readImage("Planet Cute:Character Pink Girl"),
    readImage("Planet Cute:Character Princess Girl")
    imgcount = {count = 1}
 tween(1,imgcount,{count = 5},{easing = tween.easing.linear,loop = tween.loop.forever})

function draw()
    background(0, 0, 0, 255)


Thanks for the feedback. I’ve added the while statement to that in particular and that specific problem is good to go. Now I have one pain left… the switches are extremely fast. I was thinking of putting the values of timer as high as 50-500 and let it count all the way there, extending the duration of the sprite switches.

What do you think?


Holy goodness on my mother’s coffee jar. I did NOT know you could index multiple images with tween. I… love you. You both are awesome helpers. Codea really does have an awesome community.

EDIT: EDIT: It looks like the last sprite is not loaded. I put in two and only 1 played, so nothing happened. I put in three and only the two animated.

@Treshure - a tween just interpolates (or counts) one or more numbers. In this case, it is just changing count. The tween function doesn’t know you are using it to change images. So you can use tweens for lots of things.

wrt timer length, just play with it, and see what works best. If it’s 500, that’s fine. But probably there is something wrong that you need to fix.

I notice in your original code, that timer counts up to 5 initially, and then does Walking or whatever. When it counts down from 12, as soon as it gets below 5, it gets increased back to 5, so Normal doesn’t get much of a chance to run. I would look carefully at how your counter is actually running in practice. For example, if you put a print(timer) command at the end of draw (temporarily for testing), you will see what your timer is actually doing.

Thanks for the documentation and suggestions. I decided to scrap my original code because it was extremely messy and the concept only worked with few animations. Things would get very tiresome and tricky if there were more animations.

I’ve updated the main post with my latest issue. I’m trying to use Briarfox’s method of using sprites in hashes… but the problem comes in when the tweens conflict in the touch statement. Could use some advice there. Thanks again.

@Treshure - no advice without code!

:stuck_out_tongue: Was taking a few extra minutes for the email to get to me and I could write the explanation. It’s all there now.

@Treshure - I just tidied your code. It reads more easily, and you will make fewer mistakes if you keep everything lined up, and indent carefully, as i have done.

@Treshure - shouldn’t it be

sprite(walkright[imgcount.count], pos.x, pos.y)

however, I notice the sprite that increments imgcount.count goes up to 3, and you only have two images…

“It looks like the last sprite is not loaded. I put in two and only 1 played, so nothing happened. I put in three and only the two animated.” It was the issue I encountered before, so I added 1 and the two sprites played. If I had two, only 1 played.

Anywho, all is well and compiled but I realized the same guy should have his same actions, I’m having two people on the screen. I added another identical tween(), but with imgcount1 and count1. I’ve put the values from walkright into imgs. The only problem is that I don’t want all the animations to play.

Anything I can do to do something like

tween(1,imgcount,{count = 3 - 5},{easing = tween.easing.linear,loop = tween.loop.forever})

To select which ones? I’ll add what I did to the file now.

@Treshure - if you only want animations 3,4,5 to play, set imgcount.count=3 and tween it to 5, then it will loop between 3 and 5

@Treshure - I can see why your last animation never played, too. If you want to use tweens to cycle between two animations, and you start at 1 and tween to 2, and take the floor of the result, that result will always be 1! (think about it)

So you need to start at 1 and tween up to 2.9999 (say), then the 2nd animation will also get a turn.

Awesome! Everything works now. Thanks again. I’ll just have to figure out how to manipulate t.x and t.y positions with sprites to do turns.

I updated the thread with my latest issue. This is starting to get very complicated…

@Treshure - The reason you get an error is that “touch” does not exist.

  1. in the touched function, the parameter t holds all the touch info, and it only exists while that function runs. By the time draw runs, t doesn’t exist any more.

  2. you have never defined the variable touch anywhere, so it is nil.

If you want “touch” to hold all the current touch info, then put this line into the touched function

x = t.x  --put it after this existing line of code
touch = t --now touch exists, and the info stored in t will be retained

All works well, I tweaked a few things and it’s perfect.

Newest problem updated.

@Treshure - you are missing } on the end of the line in the second case. You can avoid this kind of problem if you lay your code out more neatly, eg

imgs = {
    readImage("Documents:Normal", pos.x, pos.y),      
    readImage("Documents:Breathing", pos.x, pos.y),
    readImage("Documents:WalkLeft", pos.x, pos.y), 
    readImage("Documents:WalkRight", pos.x, pos.y)

because it makes it easier to see what is happening, and to add new items.

I forgot to add the } in the example.
I tried your example and it doesn’t work, same error.

imgs = {
       readImage("Documents:Normal", pos.x, pos.y),
       readImage("Documents:Breathing", pos.x, pos.y),
       readImage("Documents:WalkLeft", pos.x, pos.y), 
       readImage("Documents:WalkRight", pos.x, pos.y),
       readImage("Documents:WalkLeft(L)", pos.x, pos.y), 
       readImage("Documents:WalkRight(L)", pos.x, pos.y)