dieterweireldt
Posts: 1
Joined: Tue Feb 10, 2026 3:05 pm

Dynamic Artwork/Skin swapping via Lua

Hi everyone,

I am working on a project in MAME 0.285 and I've hit a wall regarding dynamic layouts and Lua.

1. The Project
I want to display character artwork (movelists) on the left (P1) and right (P2) of the game screen. I want to cycle through different characters for both players independently using LSHIFT (P1) and RSHIFT (P2). (f.e. 7 characters in Mortal Kombat, each with their own artwork containing their movelist)

2. What works right now
Currently, I have it working by swapping the entire view. When I press a key, Lua changes the target.view_index. This works, but it means P1 and P2 are not independent. To make them independent, I would need to pre-define 49 separate views ($7 \times 7$ combinations) in my .lay file.

Code: Select all

if p1_pressed and not last_p1 then
    current_idx = (current_idx % 7) + 1
    target.view_index = current_idx -- This refreshes the art, but swaps the whole layout
end
3. What I would like to achieve
I want to use one single view and update the state of the P1 and P2 elements independently. However, when I try to change the state via Lua, the console shows the value has changed, but the images on screen do not update

The goal is to use something like this (which currently doesn't refresh the screen):

The .lay setup:

Code: Select all

<element name="skins">
    <image state="0" file="subzero.png" />
    <image state="1" file="scorpion.png" />
    .......
    </element>

<view name="Main">
    <screen index="0"><bounds x="240" y="0" width="1440" height="1080"/></screen>
    <element ref="skins" name="p1_skin"><bounds x="40" y="60" width="181" height="960"/></element>
    <element ref="skins" name="p2_skin"><bounds x="1690" y="60" width="181" height="960"/></element>
</view>
The Lua I want to use:

Code: Select all

-- This changes the internal state, but the renderer doesn't 'see' it
local p1_item = target.current_view.items:at(2) 
p1_item:set_state(new_skin_index)
My Question:
Is there a way to force a refresh of the current view/elements in MAME 0.285 so that set_state actually updates the images on screen without having to switch view_index? Or is defining dozens of views the only way to get independent P1/P2 artwork?
User avatar
retrorom
Posts: 3
Joined: Thu Apr 02, 2026 8:37 am

Re: Dynamic Artwork/Skin swapping via Lua

try to force refresh as it may work like :

Code: Select all

local p1_idx = 0
local p2_idx = 0

if p1_pressed then
    p1_idx = (p1_idx + 1) % 7
    local p1_item = target.current_view:find_item_by_name("p1_skin")
    if p1_item then
        p1_item:set_state(p1_idx)
    end
    target.view_index = target.view_index 
end

if p2_pressed then
    p2_idx = (p2_idx + 1) % 7
    local p2_item = target.current_view:find_item_by_name("p2_skin")
    if p2_item then
        p2_item:set_state(p2_idx)
    end
    target.view_index = target.view_index 
end

Return to “Work In Progress (WIP)”