How to update circle radius and properties lacking listeners?

How does the system want me to update the properties of stage objects if there is no way to change the properties after initial creation? Like with a circle…I can update the x and y properties of the shape object cause it gives me those properties for update. What about radius? Doesn’t give me the property. Here they say to scale it instead…Access Circle radius property?. That can work sort of with some work, but what about a line? Doesn’t give u even the pairs of x/y properties. I’m going to consider the x,y properties of display.newCircle() as ‘event listeners’ or ‘listeners’ to distinguish them from the radius and other default properties lacking such update functionality…you can correct me on the proper name.

Now, I can delete and redraw the entire object with the same name. But if I have a image like a sprite with all these crazy properties including physics bodies on them…i gotta remake all of that don’t I? Like I am trying to change the crosshair of my mouse image on keypress…and it should be a simple case of changing the number in the frame property, but there’s no way to update that property without remaking the entire object and physics bodies I assigned to it.

I had tested out the act of using a standard init/update/draw+cls() loop like u would in pico8 and love2d but it proved only at best 1/3 as efficient as updating just the 1-2 necessary properties of stage objects…so I thought to embrace the solar2d system. But I am getting frustrated cause I made a system that did both to fit these listener exceptions, but now it’s getting ridiculous if I need to now make sub-functions like remake_entire_sprite_with_physics(crosshair=3). And Solar2d does not seem to want u to just giveup and adopt a cls() method like u would in those other lua engines, the stage objects are just really sticky and require extra work to overwrite and delete.

So going back to the example where you have a mouse cursor that moves objects via the physics system and u want to change its crosshair-image all of a sudden, how would you make that work? Should my physics objects be blank objects underneath everything, and kept separate from all the image files, then the image files can be the ones that get deleted and remade when I need a new crosshair? If anyone has examples of systems that achieve such feats, or information I am missing that would be great. I need to rethink my outline once more.

To change the image in Solar2D you can use Bitmap Paint.

local paint = {
    type = "image",
    filename = "texture_cursor.png"
}

cursor.fill = paint
-- If the image has a different size you need to resize the display object.
cursor.width = newWidth
cursor.height = newHeight

One way I use more often is to use SpriteSheet.

1 Like

Some objects have a path property, in this case, a CirclePath:

local circle = display.newCircle( 160, 240, 10 )
circle.path.radius = 50
 
transition.to( circle.path, { time=2000, radius=10 } )

Reference: Solar2D Documentation — Developer Guides | Graphics/Audio/Animation

1 Like