User Tools

Site Tools


Part 14 – FX

Every game needs an objective. In our game, the hero needs to the top of the platforms to reach the flashing star.

We don't have a star asset, so I've provided one below:

Right and click this image and save it as “star.png” in the data/texture folder in our project.

Create a object section for this star and position it at the top right hand platform:

Texture = star.png
Graphic  = StarGraphic
Position = (290, -260, 0)

Add the star to the Scene section's child list so that it is created when the platforms are:

ChildList = PlatformObject # MiddlePlatformObject #
TopLeftPlatformObject # TopPlatformObject # TopRightPlatformObject #

Run the game and you will have a star in the top right hand corner:

It will be nice if the star pulses colour and slowly turns. We can use two FXSlot sections for this:

Type		= color
Curve		= sine
StartTime	= 0
EndTime		= 1
Absolute	= true
StartValue	= (255,0,0)
EndValue	= (255,255,0)
Type       = rotation
Curve      = linear
StartTime  = 0
EndTime    = 2
StartValue = 0
EndValue   = 359

Now group the two slots under one FX section:

SlotList    = StarFlashSlotFX # StarRotateSlotFX
KeepInCache = true
Loop        = true

The FX section will be in charge of ensuring they stay in memory and that they both loop.

Add the FX to the StarObject:

Graphic  = StarGraphic
Position = (290, -260, 0)
FXList   = StarFX

Cool. Run that and the star should turn and flash.

The only problem is that the turning pivot for the star is a little off. Fix that on the StarGraphic:

Texture = star.png
Pivot   = center

Run that. And it will turn nicely.

One more tweak, a minor detail: As the sprite is turning, there are some jaggies. Smooth them out my applying Smoothing to the StarObject:

Graphic   = StarGraphic
Position  = (290, -260, 0)
FXList    = StarFX
Smoothing = true

Run that and you should get:

Great! Next, is to make the hero collide with the star in order to win the game.

The star object will need a static body, with a solid body part:

Dynamic   = false
PartList = StarBodyPart
Type        = box
Solid       = true
SelfFlags   = star
CheckMask   = hero

And add the body to the StarObject:

Graphic   = StarGraphic
Position  = (290, -260, 0)
FXList    = StarFX
Smoothing = true
Body      = StarBody

We've also declared flags to make sure that we only care if the star collides with the hero and nothing else.

We will set that collision up in a moment.

Next: Part 15 – Collision Events.

en/guides/beginners/fx.txt · Last modified: 2018/06/28 12:26 (3 weeks ago) by sausage