A game file is not required for this session!
AccelloSoccer
.Soccer Pitch
, leaving all other scene settings at their default configurations.Stencyl Book Soccer Ball
from StencylForge.Ball Movement
, and attach it to the Stencyl Book Soccer Ball actor.Move Ball
.We have created the rudiments of an accelerometer-controlled game in only 10 steps!
We should by now be familiar with creating blank games, scenes, and adding behaviors. So, we only need to look in detail at the Ball Movement
behavior that we have attached to the soccer ball actor.
The Move Ball
event always checks the values of the x and y feedback from the device's accelerometer and it sets the scene's x and y gravity based on those values. As we learned in our earlier experiments, the accelerometer returns values between -1 and +1; however, these values are far too small to have any effect on the scene's gravity. To increase the feedback returned by the accelerometer to values that will be useful to our game, we have simply multiplied them by a factor of -100 for the x axis, and +100 for the y axis.
While these multipliers are a good starting point, experimentation is often required to achieve accelerometer controls to which the player can easily assimilate; so, do experiment with the multiplier numbers to attain a better understanding of how they will affect gameplay.
It's important to be aware that, typically, the accelerometer should not be used with the autorotate feature on iOS devices (at the time of writing, Stencyl does not support autorotate on Android). This is configured in the game settings, and can be found in the main Stencyl menu under Settings | Mobile | User Input.
By default, autorotate is disabled in Stencyl, because most games do not use this feature. However, it can sometimes be useful — imagine a game in which the normal gameplay display mode was portrait, but when turning the device to landscape, an in-game information screen was displayed. This could offer some interesting design possibilities if implemented appropriately, but if a game, such as our sample soccer game had autorotate enabled, this would cause havoc for the player, as the accelerometer feedback would appear to be reversed each time the device was rotated. iOS developers can try enabling autorotate in the soccer game's settings (select Settings | Mobile | User Input), and test the game on their mobile device to experience the problem firsthand.
3.22.61.218