Professional Web Applications Themes

Displaying part of an image - Macromedia Flex General Discussion

I'm making a board game in Flex. Both to save bandwidth and for convenience in the code, I want to store the bitmaps for all the tiles in a single GIF, then just display the appropriate part of that GIF in each tile's Image object. Here's a simplified example of what I'm trying to do. Let's say each tile has 2 boolean properties, giving 4 possible tiles, each of which has its own 32x32 bitmap. So, my tiles.gif is going to be 64x64, but each tile Image object is 32x32 and I'm displaying of the four quadrants of the GIF, ...

  1. #1

    Default Displaying part of an image

    I'm making a board game in Flex. Both to save bandwidth and for convenience in
    the code, I want to store the bitmaps for all the tiles in a single GIF, then
    just display the appropriate part of that GIF in each tile's Image object.

    Here's a simplified example of what I'm trying to do. Let's say each tile has
    2 boolean properties, giving 4 possible tiles, each of which has its own 32x32
    bitmap. So, my tiles.gif is going to be 64x64, but each tile Image object is
    32x32 and I'm displaying of the four quadrants of the GIF, depending on whether
    that tiles is (true, false), (true, true), or whatever.

    This is pretty easy to do in Java and I assumed it would be obvious in Flex,
    but I can't find the appropriate properties in the Image class. First of all,
    when I set the width and height to 32, it resizes the Image. So first of all, I
    need to know how to stop the image from resizing, and second of all, I need to
    know how to change which section of the image is displayed.

    Am I overlooking something obvious, or am I going to have to do something
    using the Bitmap class and bind that to the Image objects, or what?

    Xopods Guest

  2. #2

    Default Re: Displaying part of an image

    If I'm understanding correctly what you're trying to do, I'd say you need to
    use mask(s) to accomplish the task. See if the following link helps you:

    [url]http://www.insideria.com/2008/01/flex-graphics-tricks-part-1-ma.html[/url]

    TS

    VarioPegged Guest

  3. #3

    Default Re: Displaying part of an image

    No, I doubt it's that complicated. Worst case scenario, some of the examples
    I've been looking at seem to suggest you can do it using Bitmap objects and the
    scroll() function, but I was hoping there was an even easier way. It's such a
    basic thing in game programming (animated sprites all work that way... the
    image is like an animation strip), but I guess Flex isn't really designed for
    game programming.

    Xopods Guest

  4. #4

    Default Re: Displaying part of an image

    Seems pretty simple:

    <mx:Canvas clipContent="true" height="32" width="32">
    <mx:Image scaleContent="false" x="-32" y="-32"
    </mx:Canvas>

    To show the 1,1 tile (assuming 0,0 is your start). Just progrtamtically
    change your x/y as needed, and the canvas will clip the image to 32x32.

    Otherwise, you will need to do something like what I did here:
    [url]http://www.pinktogether.com[/url]
    which is use bitmap compositing and manipulation.


    slaingod Guest

  5. #5

    Default Re: Displaying part of an image

    Thanks, that's exactly what I needed to know. Somehow in poring over the properties list of the Image component, I failed to find the scaleContent attribute.
    Xopods Guest

Similar Threads

  1. How to load image in vb part of WebApplication
    By m.mahmoudieh in forum ASP.NET General
    Replies: 0
    Last Post: January 20th, 01:54 PM
  2. Displaying only a part of a record field
    By neilorourker in forum Coldfusion - Advanced Techniques
    Replies: 6
    Last Post: April 4th, 08:24 PM
  3. Displaying part of HTML before and after system() command
    By Aaron Whiffin in forum PHP Development
    Replies: 4
    Last Post: October 6th, 02:21 PM
  4. ??? on how to link to a specific part of an image
    By Anthony MMTS in forum Macromedia Fireworks
    Replies: 4
    Last Post: July 23rd, 02:25 PM
  5. how to pixelate part of an image
    By Phil in forum Macromedia Fireworks
    Replies: 9
    Last Post: July 15th, 05:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139