Skip to content

Tween instances interfering with each other #2

@bc-bytes

Description

@bc-bytes

I'm having an issue with this library. When I create multiple instances of a tween, they seem to be interfering with each other. Lets say I have a tween for the player in the player class:

pl={
 x=0,
 y=0,
 sprite=0
}
pl.tween=tween_machine:add_tween({
 func=inback,
 duration=0.45
})
pl.tween:register_step_callback(pl_update_y)
pl.tween:register_finished_callback(pl_tween_end)

That works as expected. However, when I try to update tweens created for enemy objects, the enemy movement (processed by the enemy tween) is causing the player to move erratically. When I remove the enemy tween the player tween works fine again. Here's how I create enemy objects:

enemy_group1={}
for i=1,max_group_enemies do
  enemy={
   etype=1,
   width=0,
   height=0,
   edir=⬅️,
   tween=tween_machine:add_tween({})
  }
add(enemy_group1,enemy)

Basically, each enemy has its own tween, and is updated each frame like this:

if e.state==1 then
  e.tween.v_start=135
  e.tween.v_end=-15
  e.tween.duration=4.27
  e.tween.func=linear
  e.state=2
 else
  e.x=e.tween.value
  if e.x<-8 then
   e.alive=false
   enemies_alive-=1
  end
end

The only difference between the two (player/enemy) tweens is that I use a callback for the player tween to update player position, but access the tween's value directly to update enemy positions.

I'm new to pico-8 development, so it's quite possible I'm misunderstanding something on the Lua side of things. Any help much appreciated, and thanks for the library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions