You can achieve this sort of thing by creating a custom Component and
implementing the "paint" method in it.  Codename One's EDT maintains a
refresh loop that you can tap into to trigger your paint method.

Your paint() method is passed a Graphics object which includes
functionality to draw graphics primitives, like shapes, text, and images.

This series of blog posts describes this process.  The last one in the list
deals with animation.  The first two, with drawing to Graphics.

http://www.codenameone.com/blog/codename-one-graphics.html
https://www.codenameone.com/blog/codename-one-graphics-part-2-drawing-an-analog-clock.html
https://www.codenameone.com/blog/codename-one-graphics-low-level-animations.html

Best regards

Steve


On Tue, Apr 4, 2017 at 8:05 PM, <[email protected]> wrote:

> Hello! This is a bit of a Java question + a Codename One question. I'm
> migrating a project from another library that uses C to Codename One's API.
> Here is an example of how I do it currently, starting with the function
> prototype:
>
> void Draw(_Texture *tex,    // Source texture
>           _Rect *src,       // Which pixels in the texture will we be
> copying?
>           _Rect *dst        // At what x/y will we be placing these
> pixels on the screen?
>          );
>
> Then, let's say I have an optimized sprite sheet with a _Rect array that
> specifies where every sprite on the sprite sheet is:
>
> _Rect sprite[]={
>     { 0, 0, 46, 49 },    // Stand Right
>     { 46, 0, 15, 15 },   // Walk Right 1
>     { 46, 15, 15, 15 },  // Walk Right 2
>     { 46, 30, 15, 17 },  // Stand Left
>     { 102, 20, 15, 17 }, // Walk Left 1
>     { 117, 20, 15, 17 }  // Walk Left 2
> };
>
> And the player is at a position that is always changing:
>
> _Rect playerRect={Player.x,Player.y};
>
> The final function call would look like:
>
> Draw(Player.tex,&sprite[Player.sprite],&playerRect);
>
> This has proven to be an incredibly fast and portable solution for me,
> which I have used for some Wii homebrew apps for fun. It's sort of a
> write-once, compile anywhere solution. With some #ifdefs, the contents of
> "Draw" change based on the target platform, but the function always takes
> the same arguments and handles them in a multi-platform way. However,
> extending my API (if you can even call it that) to work on Android and
> iOS... no need for that when projects like Codename One exist. :)
>
> Can I please get a simple runnable example that does something like this?
> I have been digging through the documentation for a couple of days now and
> none of the Frankenstein code I'm writing so far works. I'm trying to make
> it so it has this redraw loop going 30 or 60 frames per second where
> objects get evaluated and can move every frame, that way, it can be more
> familiar to the workflow I'm adjusted to than putting animation frames in
> form labels and the like.
>
> I also think an example like this would make Codename One more accessible
> for newcomers who want to use it to make simple 2D games, where manually
> handling on-screen objects in this way is preferable and offers more
> control over the end result. :)
>
> Anyone care to help a CN1 n00b out? :)
>
> --
> You received this message because you are subscribed to the Google Groups
> "CodenameOne Discussions" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> Visit this group at https://groups.google.com/
> group/codenameone-discussions.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/codenameone-discussions/d91cba10-2ff0-4d4d-96bb-
> 1e9dc247d23f%40googlegroups.com
> <https://groups.google.com/d/msgid/codenameone-discussions/d91cba10-2ff0-4d4d-96bb-1e9dc247d23f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Steve Hannah
Software Developer
Codename One
http://www.codenameone.com

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/CAGOYrKXQEqoT-DdSa1DnLoVv03P-%3DdaYBbtG5E012C1L2Wz-ng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to