I want to create a move function, Wehre you Must Five your Sprite. It works, but how can i drawidisch the Sprite now?
Heres a Little Code:
Player = sprite(“Sprite…”,50,100)
At the draw-function:
Player
–
But what is Wong?
Pls. Help!!!
I want to create a move function, Wehre you Must Five your Sprite. It works, but how can i drawidisch the Sprite now?
Heres a Little Code:
Player = sprite(“Sprite…”,50,100)
At the draw-function:
Player
–
But what is Wong?
Pls. Help!!!
Sprite is a method that draws the sprite, I don’t think you can take the result of calling it and store it in a variable - you have to call sprite() in your draw routine each time and if you want it to move, you will have to change the x,y values.
playerx = 50
playery = 100
in draw:
sprite("Sprite...", playerx, playery)
Ok, i Show you what i have done now:
mainclass:
-- Use this function to perform your initial setup
function setup()
print("Test-Spiel")
displayMode(FULLSCREEN)
colorbg = color(79, 88, 144, 255)
colorout = color(0, 0, 0, 255)
colortxt = color(255, 255, 255, 255)
button=Button("status1",colorbg,colorout,colortxt)
button.action = function () buttonchange() end
end
function buttonchange()
if button.displayName == "status1" then
status2(50,200,100,400,"Planet Cute:Character Horn Girl")
button.displayName = "status2"
elseif button.displayName == "status2" then
button.displayName = "status1"
end
end
--This function prepare your Button
function drawButton()
button.pos = vec2(60,730)
button:draw()
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(167, 167, 167, 255)
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
drawButton()
end
--This function is for touch
function touched(touch)
button:touched(touch)
end
Status2-class
status2 = class()
function status2:init(posx,posy,x,y,figure)
self.figure = figure
self.position.x = posx
self.position.y = posy
self.x = x
self.y = y
if self.position.x < self.x then
self.position.x = self.position.x + 1
elseif self.position.x > self.x then
self.position.x = self.position.x - 1
elseif self.position.x == self.x then
if self.position.y < self.y then
self.position.y = self.position.y + 1
elseif self.position.y > self.y then
self.position.y = self.position.y - 1
elseif self.position.y == self.y then
end
end
end
function status2:draw()
pushStyle()
sprite(self.figure,self.position.x,self.position.y)
popStyle()
end
--
Ignore the Button-class.
Now please help.
Thx.
When you call “status2()” - it returns a “status2” object as the result. You need to save that to a variable so you can call it’s methods later.
So - you’d say something like “player=status2(50,200,100,400,“Planet Cute:Character Horn Girl”)”
Then, in your main draw(), you’d add “player:draw()” after the “-- Do your drawing here” line. draw() doesn’t call the draw methods of classes - you have to do it yourself.
And how can do ist so that it is Possible to See the movement?
I mean the “posx = posx + 1” ???
Yes. Somewhere in the draw loop, you do your movement - if you had “player.position.x = player.position.x + 1”, then the sprite will draw each frame one to the right, and appear to move.
Try putting “player.position.x = CurrentTouch.x” and “player.position.y = CurrentTouch.y”, and the sprite will follow your finger.
Thank you
You’re very Good!
Sry, but i have a Second Question: you know if x = y And z = a then …
It Works with And And or in the mid, right?
And what Must i Write if i want And And or?
I don’t understand the question.