Sliding Text

Category: PyAngelo

Last updated 10 months ago

Thisum Wijendra

Thisum Wijendra Asked 10 months ago

How do you make the text slide across the screen on a canvas then suddenly stop in the middle? With cycling rbg colours for the text if possible?

NOTE: This is for the top down car race video game.

Jeff Plumb

Jeff Plumb Answered 10 months ago

Hi Thisum,

Here's one way you could achieve that effect:

from sprite import *
setCanvasSize(640, 360)
title = TextSprite("Racing Game", -100, 160)
red = 0
title.setColour(red, 100, 200)

while title.x < 260:
    background(220, 220, 220)
    title.moveBy(1, 0)
    red = (red + 1) % 256
    title.setColour(red, 100, 200)

We create an object called "title" from the TextSprite class. This means that wth the "title" object we can use many methods including draw(), moveBy(), and setColour(). To change the colour we are simply changing the red value by 1 each time through the loop and using the modulus operator to set it back to zero if it passes 256. Let me know if that helps.

Notify me of updates
Add to Favourites
Back to Questions

No comments yet!

Become a free member to post a comment about this question.