+ Reply to Thread
Results 1 to 12 of 12

Userform Image Control - Show specific region of Image

  1. #1
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    237

    Userform Image Control - Show specific region of Image

    Hi all,

    I have a 2D platform game I have been working on in VBA. So far everything has been going to plan, and I'm currently animating everything using individual sprites.

    In a bid to reduce the file size and clutter, I would like to reference a single spritesheet image that contains all the sprites I require, and call specific regions of the image to be shown in the image control.

    For example, My spritesheet has 100 sprites, 10 x 10, measuring 640px by 640px, making each sprite 64px by 64px, so the first sprite location should be 0x0x64x64, the second would be at 0,64,64,128, and so on.

    I've seen this achieved with regular VB with great success, but can it be done in with VBA?

    Many thanks!
    Last edited by PrizeGotti; 11-09-2021 at 11:03 AM.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: Userform Image Control - Show specific region of Image

    You're probably great at explaining and know what you're saying and understand it.
    How about a sample and a what you have and what you want to to have as a result?
    Almost everything is possible with VBA but you do have to tell it what to do, and to tell it ... well, you have to know what to tell it and I don't know what you want done.
    Maybe I'm slow but try again and I'm sure we can work it our and explain it and you'll see there's nothing to it
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    237

    Re: Userform Image Control - Show specific region of Image

    Hi Keeballah,

    I'm not sure how else you would explain it.

    Here's an example image;

    spritesheet.png

    This image is 224px by 32px, there are 8 sprites measuring 28px by 32px.

    I don't want all 8 sprites to show, I only want one sprite at a time, so I would need the Image control to focus on a set region in the image. For example I want to display the 2nd sprite, so the image box would need to
    focus on the region of 0px,28px,32px,56px.

    I hope this makes more sense?

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: Userform Image Control - Show specific region of Image

    Okay, so what it is it's one image with these 8 sprites in it.
    You said you've seen this done with VB then you can use the same code with VBA maybe a minor tweak but I assume it can be done.
    Do you have the VB code script somewhere?

  5. #5
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,158

    Re: Userform Image Control - Show specific region of Image

    I don't think this will solve your problem, but maybe it will inspire you.
    Image2 is only for visualizing what is happening with Image1.

    Artik
    Attached Files Attached Files

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: Userform Image Control - Show specific region of Image

    I think you should just add 8 separate images and select the one you want

  7. #7
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    237

    Re: Userform Image Control - Show specific region of Image

    Quote Originally Posted by Keebellah View Post
    I think you should just add 8 separate images and select the one you want
    Hi Keebellah,

    The problem is, I was just giving 8 as an example. Most spritesheets will have probably at least 100 sprites on them. It's not really feasible to crop them all to perfect alignment, this also increases the file size exponentially, going from 1 image, to hundreds.

    That being said. I was able to solve this problem over breakfast;

    Frames!

    I can place the full sized image control inside a frame that is sized to the sprite, then using the .Top and .Left functions on the image control to position it inside the frame.

    If anyone wants to give this a try, I will provide a sample 4 x 4 sprite sheet;

    sprites.gif

    - Save above picture as "sprites.gif"
    - Create a UserForm.
    - Place a Frame control on the UserForm (No Caption, Disable Borders, Set TabStop to False) measuring 48pts by 48pts (48pts = 64px).
    - Place an Image control INSIDE the Frame (Disable Borders, Set AutoSize to True)

    In the UserForm1 code, paste the following;
    Please Login or Register  to view this content.
    You can control the characters movement using the Arrow keys.
    Last edited by PrizeGotti; 11-09-2021 at 11:37 AM.

  8. #8
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: Userform Image Control - Show specific region of Image

    And what do we have to do?

  9. #9
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    237

    Re: Userform Image Control - Show specific region of Image

    Sorry I'm a bit confused? The instructions are in my post with the code.

  10. #10
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: Userform Image Control - Show specific region of Image

    Then I think I'm the one that doesn't understand what you really want/need, sorry.
    I'm sure others will (probably)

  11. #11
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    237

    Re: Userform Image Control - Show specific region of Image

    Hi Keebellah.

    I'm really note sure where the confusion has come from. I'm sure I've been clear that I am trying to animate a video game sprite using a single spritesheet. (If it's "spritesheet" that has caused the confusion, please see https://en.wikipedia.org/wiki/Texture_atlas)

    Which as I mentioned, I managed to solve myself, and provided a working example of my code for others to play with.

  12. #12
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: Userform Image Control - Show specific region of Image

    Okay, clear, now I also understand the fact that it's solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Userform with image control.
    By Trond64 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 04-18-2021, 06:00 AM
  2. Insert and scale image using Image Control from Active X
    By olga6542 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2020, 06:03 PM
  3. Get Image from worksheet to UserForm Image Control
    By sijostephen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-17-2020, 06:54 AM
  4. [SOLVED] VBA to transfer image FROM userform image control TO a worksheet cell
    By Zoediak in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2014, 02:51 PM
  5. [SOLVED] show jpeg picture inside a userform image control box
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 31
    Last Post: 07-29-2013, 03:44 PM
  6. Displaying and Updating Image Dynamically (ActiveX Image Control?)
    By VTHokie11 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2011, 10:57 AM
  7. Show or hide a control (image)
    By tracktor in forum Excel General
    Replies: 2
    Last Post: 09-17-2009, 10:07 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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1