How to make sprite object dynamic?

Hello,

I wonder if there is a way to change sprite position to make it really dynamic? I mean all examples coming with SDK are ‘static’ sprites. Horse, cat and green dude are moving on the spot, but the background is moving. Is it possible to make it vice versa - static background, but ‘dynamic’ sprite?

let’s say I want to make a cat from jungle scene to move from one side of the scren to another one and stop:

startX = 100
endX = 300
local sheet1 = sprite.newSpriteSheet( “runningcat.png”, 512, 256 )
local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 8)
sprite.add( spriteSet1, “cat”, 1, 8, 1000, 1 ) – play only once
local instance1 = sprite.newSprite( spriteSet1 )
instance1.x = startX
instance1:prepare(“cat”)
instance1:play()

I guess instance1.x should change during the frame playing but I can’t figure out how to make it it incremental during the play.
I tried playing with enterFrame and pushing some increment expressions to instance1:play() but it didn’t work.

is there a way to do it? [import]uid: 109065 topic_id: 18998 reply_id: 318998[/import]

Play the sprite while using transition.to() - that will get the desired effect I believe you’re describing.

Peach :slight_smile: [import]uid: 52491 topic_id: 18998 reply_id: 73177[/import]

Hello Peach,

this was obvious and I tried it before making other tricks, but it didn’t work out as expected.

play and transition seems do not work in parallel. only in series.
play usually kicks in only after transition finishes it’s action.

[import]uid: 109065 topic_id: 18998 reply_id: 73231[/import]

How were you coding that?

instance:play()
transition.to()

That should work OK - or it did last I tested it. Do you have any kind of sample you could share?

Peach :slight_smile: [import]uid: 52491 topic_id: 18998 reply_id: 73413[/import]

Hello Peach,

here is a sample:
require “sprite”
startX = 100
startY = 100
endX = 300
local sheet1 = sprite.newSpriteSheet( “runningcat.png”, 512, 256 )
local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 8)
sprite.add( spriteSet1, “cat”, 1, 8, 5000, 1 ) – play only once
local instance1 = sprite.newSprite( spriteSet1 )
instance1.x = startX
instance1.y = startY
instance1.xScale = .5
instance1.yScale = .5
instance1:prepare(“cat”)
instance1:play()
transition.to(transition.to(instance1, {alpha=1, x=endX, y=startY } ))

I’ve set sprite play time to 5000msec, so it can be clearly seen
that transition is engaged with a first sprite only. [import]uid: 109065 topic_id: 18998 reply_id: 73555[/import]

Try running this;

[lua]display.setStatusBar( display.HiddenStatusBar )

require “sprite”
startX = 100
startY = 100
endX = 300
local sheet1 = sprite.newSpriteSheet( “runningcat.png”, 512, 256 )
local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 8)
sprite.add( spriteSet1, “cat”, 1, 8, 300, 0 ) – play only once
local instance1 = sprite.newSprite( spriteSet1 )
instance1.x = startX
instance1.y = startY
instance1.xScale = .5
instance1.yScale = .5
instance1:prepare(“cat”)
instance1:play()
transition.to(instance1, {time = 2000, alpha=1, x=endX, y=startY } )[/lua]

Works fine here - latest stable build. (704).

Peach :slight_smile: [import]uid: 52491 topic_id: 18998 reply_id: 73663[/import]

hmm… I guess this is a bug.

with:

sprite.add( spriteSet1, “cat”, 1, 8, 300, 0 )

both play() and transition.to() are working in parallel

but as soon as I set it to:

sprite.add( spriteSet1, “cat”, 1, 8, 300, 1 )

it makes play() ans transition.to() in sequence.

checked on 2011.591 and 2011.704 builds
[import]uid: 109065 topic_id: 18998 reply_id: 73786[/import]

I actually just ran this and it worked fine on 704 on my Mac.

If you file a bug for it can you be extra sure to include as many details as possible? (Because I can’t reproduce it I’m guessing others may have a hard time too.)

Peach :slight_smile: [import]uid: 52491 topic_id: 18998 reply_id: 73861[/import]

heh, I am making all development and testing on windows. just checked with another windows pc. it shows the same results. I am using win7 enterprise for both of my pc’s. [import]uid: 109065 topic_id: 18998 reply_id: 73880[/import]

since this thread is transforming to a ‘I found a bug’ thread I would like to report one more bug with
timer.performWithDelay :slight_smile:

this code works fine:

timer.performWithDelay(delay, function)

but as soon as I make it

timer.performWithDelay(delay, function())
or
timer.performWithDelay(delay, function(a,b))

the delay is never done, function is called immediately.
[import]uid: 109065 topic_id: 18998 reply_id: 73883[/import]

File the bug here with details; http://developer.anscamobile.com/content/bug-submission

For the timer you should use;

[lua]timer.performWithDelay(delay, function)[/lua]

and not;

[lua]timer.performWithDelay(delay, function())[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 18998 reply_id: 73916[/import]