How to move ImageSprite

20 views
Skip to first unread message

Steve Marcus

unread,
Aug 25, 2013, 3:08:41 PM8/25/13
to alternate-java-bridg...@googlegroups.com
What am I missing?



Canvas canvas1;

ImageSprite movingSprite;



canvas1 = new Canvas(this,R.id.canvas1);

movingSprite = new ImageSprite (canvas1,R.id.aBImageSprite1);
                movingSprite.Rotates(true);
movingSprite.X(50);
movingSprite.Y(50);
movingSprite.Heading(0);
  movingSprite.Interval(45);
  movingSprite.Speed(2);
                movingSprite.Enabled(true);



Shouldn't this move the Image Sprite? It appears on the canvas fine, but it just sits in the same place and doesn't move. 

Also it seems to ignore the X and Y coordinates - it's stuck at (0,0) in the top left of the canvas.

Am I missing something (probably)?

Thanks,


S

Imp Inc

unread,
Aug 25, 2013, 7:35:56 PM8/25/13
to alternate-java-bridg...@googlegroups.com
Hmm. Not sure about the X, Y thing, but if you want to use the internal timer in the sprite, you have to initialize it. Just run movingSprite.Initialize().

I'll have to take a look at the X, Y thing next weekend.

Ryan

Imp Inc

unread,
Aug 25, 2013, 7:36:36 PM8/25/13
to alternate-java-bridg...@googlegroups.com
Oh, you should wait until at least screen initialization to try moving the sprite. If you're doing it in define(), that may be why.

Steve Marcus

unread,
Aug 26, 2013, 9:29:58 AM8/26/13
to alternate-java-bridg...@googlegroups.com
Great yep that worked. Thanks.

Steve Marcus

unread,
Aug 26, 2013, 10:44:56 AM8/26/13
to alternate-java-bridg...@googlegroups.com
Regarding the XY thing, this seems to work:

movingSprite.X(movingSprite.X()+50);
movingSprite.Y(movingSprite.Y()+50);

but just specifying the number (50) does not seem to.

Imp Inc

unread,
Aug 26, 2013, 11:00:59 AM8/26/13
to alternate-java-bridg...@googlegroups.com
Hmm.. It should just work, but perhaps it's being picky because it wants a double. Add a "d" at the end of the number to enforce it as a double like so:

movingSprite.X(50d);

or, add a decimal point:

movingSprite.X(50.0);

- Ryan
Reply all
Reply to author
Forward
0 new messages