Both sides had a lot of allies.
In the first war the fighting was almost entirely limited to Sicily and the competition for alliances was thus mostly centered around that island. But the second war was a lot bigger in scope. And much more interesting, politically speaking.
Much of Italy was officially "allied" to Rome and not subjugated to Rome during the period. During the 2nd Punic war Hannibal's policy was to try and peel off these allies from Rome and "free Italy from Rome." His biggest success was when Capua joined the Carthaginian Italian alliance. Hannibal also always had a contingent of Gaulic allies from Cisalpine Gaul who were eager to get some nice Italian plunder.
In Sicily Syracuse was a major power. And they changed alliances in both the 1st and 2nd Punic wars. Famously they started the 2nd war allied to Rome. Then they joined Carthage after Cannae. Rome eventually sacked the city after an incredible siege where Archimedes was building some incredible war machines. But that ended Syracuse as an independent state.
In Greece the Romans had gained some small territories on the Illyrian coast. So after Cannae Phillip V of Macedon signed an alliance with Hannibal and went on the offensive to gain control over the Roman cities. The Romans responded by allying with Macedon's traditional enemy, the Aetolian League. This eventually drew in most of the other Greek states. The Greek alliances didn't do either the Romans or the Carthaginians any good or harm, as they balanced each other out and never really affected the 2nd Punic war in a significant way.
In Africa there was open competition to gain the allegiance of the various Numidian kings. Syphax basically held an auction for his allegiance and got a Carthaginian bride out of it. Massinissa allied with the Romans, and for his trouble got the better part of Syphax's kingdom when Syphax was captured. And this proved to be critical. The Numidians fielded some incredible cavalry. And the side that had the most Numidians in any battle tended to win. So that alliance with Massinissa gave Scipio the cavalry he needed to beat Hannibal.
In Spain it was a similar story. Much of the territory was controlled by Spanish allies. And one of the key battles there was when the Romans captured the town where the families of most of the Spanish allies leaders were. And the Spanish allies quit the war.
Pretty much the entire second Punic war in every theatre could be defined in terms of a struggle over control over the various allied states. And as important as winning a big battle could be, getting a significant allied city to switch sides could be equally important. That is one of the reasons Cannae was so dangerous to the Romans. Not only did they lose a massive army in the field. They also lost the biggest city in Sicily and the second biggest in Italy (after Rome) who decided to back Hannibal after such an impressive showing. And they gained an enemy in Macedon which was the most powerful state in Greece.
In the Third Punic war there were no significant alliances. Carthage was isolated. And Rome didn't feel the need for any, beyond those that already existed.